Author: mfranklin
Date: Wed May 29 14:51:50 2013
New Revision: 1487506

URL: http://svn.apache.org/r1487506
Log:
Fixed RAVE-972

Modified:
    
rave/trunk/rave-portal-resources/src/main/webapp/static/script/portal/rave_ui.js

Modified: 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/portal/rave_ui.js
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/static/script/portal/rave_ui.js?rev=1487506&r1=1487505&r2=1487506&view=diff
==============================================================================
--- 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/portal/rave_ui.js
 (original)
+++ 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/portal/rave_ui.js
 Wed May 29 14:51:50 2013
@@ -20,7 +20,7 @@
 rave = rave || {};
 rave.ui = rave.ui || {}
 _.extend(rave.ui, (function () {
-    var exports = {};
+    var exports = {}, templates=null;
 
 
     /*
@@ -31,173 +31,178 @@ _.extend(rave.ui, (function () {
         return rave.getClientMessage(key);
     })
 
-    /*
-     Register templates
-     */
-    var templates = exports.templates = {};
-    $('[data-template-for]').each(function () {
-        var key = $(this).data('template-for');
-        var source = $(this).html();
-
-        templates[key] = Handlebars.compile(source);
-    });
 
     /*
      Build rave client side views
      */
     var views = exports.views = {};
 
-    /*
-     View for managing sharing / cloning of pages
-     */
-    var PageSharingModalView = rave.View.extend({
-        template: templates['user-search-view'],
-        //the bootstrap modal div
-        modalDiv: $('#sharePageDialog'),
-        //attach point for this view
-        container: $('#sharePageDialogContent'),
 
+    //TODO: root app view, will be expanded significantly
+    var App = rave.View.extend({
         models: {
-            page: rave.models.currentPage,
-            users: rave.models.users
+            page: rave.models.currentPage
         },
 
         initialize: function () {
-            var page = this.models.page;
-            var users = this.models.users;
-
-            this.constructor.__super__.initialize.apply(this);
-
-            page.on('share', this.flash, this);
-            page.on('error', this.handleError, this);
-
-            //whenever the modal is displayed reset the view
-            this.modalDiv.on('show', function () {
-                users.fetchPage(1);
+            this.models.page.on('acceptShare', rave.viewPage);
+            this.models.page.on('declineShare', function () {
+                document.location.href = rave.getContext();
             });
+        }
+    });
 
-            //extend users toViewModel function to include share properties
-            this.models.users.toViewModel = 
_.wrap(this.models.users.toViewModel, function (toViewModel) {
-                var model = toViewModel.apply(this);
-
-                _.each(model.users, function (user) {
-                    user.isOwner = page.isUserOwner(user.id);
-                    user.hasShare = page.isUserMember(user.id);
-                    user.hasEdit = page.isUserEditor(user.id);
-                });
+    views.app = new App();
+    /*
+     Register templates
+     */
+    function initializeTemplates() {
 
-                return model;
-            });
+        templates = exports.templates = {};
+        $('[data-template-for]').each(function () {
+            var key = $(this).data('template-for');
+            var source = $(this).html();
 
-            this.container.html(this.$el);
-        },
+            templates[key] = Handlebars.compile(source);
+        });
+    }
 
-        events: {
-            'click #shareSearchButton': 'search',
-            'keypress #searchTerm': 'search',
-            'click #clearSearchButton': 'clearSearch',
-            'click #pagingul a': 'page',
-            'click .searchResultRecord a': 'shareAction'
-        },
+    function initializePageSharing() {
+        /*
+         View for managing sharing / cloning of pages
+         */
+        var PageSharingModalView = rave.View.extend({
+            template: templates['user-search-view'],
+            //the bootstrap modal div
+            modalDiv: $('#sharePageDialog'),
+            //attach point for this view
+            container: $('#sharePageDialogContent'),
+
+            models: {
+                page: rave.models.currentPage,
+                users: rave.models.users
+            },
 
-        search: function (e) {
-            //allow search function to trigger from enter keypress or button 
click
-            if (e.which == 13 || _.isUndefined(e.which)) {
-                var term = $('#searchTerm', this.$el).val();
+            initialize: function () {
+                var page = this.models.page;
+                var users = this.models.users;
+
+                this.constructor.__super__.initialize.apply(this);
+
+                page.on('share', this.flash, this);
+                page.on('error', this.handleError, this);
+
+                //whenever the modal is displayed reset the view
+                this.modalDiv.on('show', function () {
+                    users.fetchPage(1);
+                });
 
-                this.models.users.filter(term);
-            }
-        },
+                //extend users toViewModel function to include share properties
+                this.models.users.toViewModel = 
_.wrap(this.models.users.toViewModel, function (toViewModel) {
+                    var model = toViewModel.apply(this);
+
+                    _.each(model.users, function (user) {
+                        user.isOwner = page.isUserOwner(user.id);
+                        user.hasShare = page.isUserMember(user.id);
+                        user.hasEdit = page.isUserEditor(user.id);
+                    });
 
-        clearSearch: function (e) {
-            this.models.users.filter(null);
-        },
+                    return model;
+                });
 
-        page: function (e) {
-            var page = $(e.target).data('pagenumber');
+                this.container.html(this.$el);
+            },
 
-            this.models.users.fetchPage(page);
-        },
+            events: {
+                'click #shareSearchButton': 'search',
+                'keypress #searchTerm': 'search',
+                'click #clearSearchButton': 'clearSearch',
+                'click #pagingul a': 'page',
+                'click .searchResultRecord a': 'shareAction'
+            },
 
-        //manages any add / remove share, editor or clone actions
-        shareAction: function (e) {
-            var userId = $(e.target).data('userid');
-            var action = $(e.target).data('action');
+            search: function (e) {
+                //allow search function to trigger from enter keypress or 
button click
+                if (e.which == 13 || _.isUndefined(e.which)) {
+                    var term = $('#searchTerm', this.$el).val();
 
-            this.models.page[action](userId);
-        },
+                    this.models.users.filter(term);
+                }
+            },
 
-        //flash success messages
-        flash: function (event, userId) {
-            var eventsToMessages = {
-                'member:add': 'create.share',
-                'member:remove': 'revoke.share',
-                'editor:add': '',
-                'editor:remove': '',
-                'clone': 'success.clone.page'
-            }
-
-            var msg = eventsToMessages[event];
-
-            if (msg) {
-                var message = rave.getClientMessage(msg);
-                var user = this.models.users.get(userId);
-                rave.showInfoMessage('(' + user.get('username') + ') ' + 
message);
-            }
-        },
+            clearSearch: function (e) {
+                this.models.users.filter(null);
+            },
 
-        //TODO: deal with errors better. Until we have a better api or there 
is another view for this modal,
-        //manually manage the form
-        handleError: function (errorCode, userId) {
-            var self = this;
+            page: function (e) {
+                var page = $(e.target).data('pagenumber');
 
-            if (errorCode == 'DUPLICATE_ITEM') {
-                this.modalDiv.modal('hide');
-                
$("#pageMenuDialogHeader").html(rave.getClientMessage("page.update"));
-                
$("#pageFormErrors").html(rave.getClientMessage("page.duplicate_name"));
-                $("#pageLayoutGroup").hide();
-                var $pageMenuUpdateButton = $("#pageMenuUpdateButton");
-                
$pageMenuUpdateButton.html(rave.getClientMessage("common.save"));
-                // unbind the previous click event since we are sharing the
-                // dialog between separate add/edit page actions
-                $pageMenuUpdateButton.unbind('click');
-                $pageMenuUpdateButton.click(function () {
-                    var $pageForm = $("#pageForm");
-                    var $tab_title_input = $("#tab_title");
-                    if ($pageForm.valid()) {
-                        self.models.page.cloneForUser(userId, 
$tab_title_input.val());
-                        $("#pageMenuDialog").modal('hide');
-                    }
-                });
-                $('#pageMenuDialog').on('shown', function () {
-                    $("#tab_title").first().focus();
-                });
-                //
-                $("#pageMenuDialog").modal('show');
-            } else {
-                $("#pageMenuDialog").modal('hide');
-                alert(rave.getClientMessage("api.rpc.error.internal"));
-            }
-        }
-    });
+                this.models.users.fetchPage(page);
+            },
 
-    views.pageSharingModal = new PageSharingModalView();
+            //manages any add / remove share, editor or clone actions
+            shareAction: function (e) {
+                var userId = $(e.target).data('userid');
+                var action = $(e.target).data('action');
 
-    //TODO: root app view, will be expanded significantly
-    var App = rave.View.extend({
-        models: {
-            page: rave.models.currentPage
-        },
+                this.models.page[action](userId);
+            },
 
-        initialize: function () {
-            this.models.page.on('acceptShare', rave.viewPage);
-            this.models.page.on('declineShare', function () {
-                document.location.href = rave.getContext();
-            });
-        }
-    });
+            //flash success messages
+            flash: function (event, userId) {
+                var eventsToMessages = {
+                    'member:add': 'create.share',
+                    'member:remove': 'revoke.share',
+                    'editor:add': '',
+                    'editor:remove': '',
+                    'clone': 'success.clone.page'
+                }
+
+                var msg = eventsToMessages[event];
+
+                if (msg) {
+                    var message = rave.getClientMessage(msg);
+                    var user = this.models.users.get(userId);
+                    rave.showInfoMessage('(' + user.get('username') + ') ' + 
message);
+                }
+            },
 
-    views.app = new App();
+            //TODO: deal with errors better. Until we have a better api or 
there is another view for this modal,
+            //manually manage the form
+            handleError: function (errorCode, userId) {
+                var self = this;
+
+                if (errorCode == 'DUPLICATE_ITEM') {
+                    this.modalDiv.modal('hide');
+                    
$("#pageMenuDialogHeader").html(rave.getClientMessage("page.update"));
+                    
$("#pageFormErrors").html(rave.getClientMessage("page.duplicate_name"));
+                    $("#pageLayoutGroup").hide();
+                    var $pageMenuUpdateButton = $("#pageMenuUpdateButton");
+                    
$pageMenuUpdateButton.html(rave.getClientMessage("common.save"));
+                    // unbind the previous click event since we are sharing the
+                    // dialog between separate add/edit page actions
+                    $pageMenuUpdateButton.unbind('click');
+                    $pageMenuUpdateButton.click(function () {
+                        var $pageForm = $("#pageForm");
+                        var $tab_title_input = $("#tab_title");
+                        if ($pageForm.valid()) {
+                            self.models.page.cloneForUser(userId, 
$tab_title_input.val());
+                            $("#pageMenuDialog").modal('hide');
+                        }
+                    });
+                    $('#pageMenuDialog').on('shown', function () {
+                        $("#tab_title").first().focus();
+                    });
+                    //
+                    $("#pageMenuDialog").modal('show');
+                } else {
+                    $("#pageMenuDialog").modal('hide');
+                    alert(rave.getClientMessage("api.rpc.error.internal"));
+                }
+            }
+        });
+        views.pageSharingModal = new PageSharingModalView();
+    }
 
     //TODO: this is all wrong - should be bootstrapped data
     function getCurrentPageId() {
@@ -906,6 +911,8 @@ _.extend(rave.ui, (function () {
     }
 
     function init() {
+        initializeTemplates();
+        initializePageSharing();
         registerHomeView();
         registerCanvasView();
         registerPopups();


Reply via email to