From 3fd837c82fc36a1c9d67b643bc967fcc8172d5c5 Mon Sep 17 00:00:00 2001 From: Anon Ray Date: Fri, 23 Aug 2013 17:54:08 +0530 Subject: [PATCH] Add support for menu order in default menu - Now with default menu, can specify the order of pages. - Fix custom menu not getting saved. - Fix irrelevant types in content editor. --- mouchak/server.py | 6 +++-- mouchak/static/js/editor.js | 57 +++++++++++------------------------------ mouchak/static/js/models.js | 3 +++ mouchak/static/js/mouchak.js | 13 +++++++--- mouchak/templates/editor.html | 43 +++++++++++++++++-------------- 5 files changed, 55 insertions(+), 67 deletions(-) diff --git a/mouchak/server.py b/mouchak/server.py index 3c549cd..65ad609 100644 --- a/mouchak/server.py +++ b/mouchak/server.py @@ -17,7 +17,8 @@ db = dbClient[conf.DB] siteContent = db['content'] siteMenu = db['menu'] if siteMenu.find_one() == None: - siteMenu.insert({'customMenu': False}) + siteMenu.insert({'customMenu': False, 'menuOrder': []}) + # handy reference to otherwise long name bson.ObjId = bson.objectid.ObjectId @@ -49,7 +50,7 @@ def index(): @app.route('/edit', methods=['GET']) def edit(): return flask.render_template('editor.html', content=getContent(), - title=conf) + title=conf.SITE_TITLE) @app.route('/page', methods=['POST']) @@ -116,6 +117,7 @@ def updateMenu(_id): # return flask.jsonify(status='deleted') + if __name__ == "__main__": app.run(debug=True, host=conf.HOST, port=conf.PORT) diff --git a/mouchak/static/js/editor.js b/mouchak/static/js/editor.js index 718f347..177ed12 100644 --- a/mouchak/static/js/editor.js +++ b/mouchak/static/js/editor.js @@ -9,8 +9,7 @@ 'click .pagename .disp': 'showPage', 'click #addPage': 'addPage', 'click .pagename .remove': 'removePage', - 'click #menu-config': 'showMenu'//, - //'click #footer-config': 'footerConfig' + 'click #menu-config': 'showMenu', }, initialize: function() { _.bindAll(this); @@ -25,7 +24,6 @@ //console.log(menu); this.menuconfig = new M.types.model.menu(menu); this.menuconfigview = new MenuConfigView({model: this.menuconfig}); - //this.footerconfigview = new FooterConfigView(); }, render: function() { // append the page list @@ -69,9 +67,6 @@ }, showMenu: function(event) { this.menuconfigview.render(); - }, - footerConfig: function(event) { - //this.footerconfigview.render(); } }); @@ -243,7 +238,6 @@ }, render: function() { this.$el.html(''); - console.log(this.model); var type = this.model.get('type'); this.$el.append(this.template({ type: this.model.get('type'), @@ -252,7 +246,6 @@ })); this.$select = $('.contentview select'); - //this.$select.bind('change', this.typeChanged); this.$select.val(type); if(type === 'text') { @@ -265,13 +258,13 @@ } else if(type === 'image' || type === 'video' || type === 'audio' || type === 'plugin') { - var template = _.template($('#media-template').html()); + var template = _.template($('#media-template').html()); $('#specific-content').html(template({ src: this.model.get('src') })); - //provide the users a preview + //TODO: provide the users a preview /*var view = new M.types.view[type]({model: this.model}); //$('#specific-content.preview').html(); view.render('.preview');*/ @@ -316,30 +309,6 @@ } }); - /* view to configure footer */ - var FooterConfigView = Backbone.View.extend({ - tagName: 'div', - id: 'page', - events: { - 'click #saveFooter': 'saveFooter' - }, - initialize: function() { - _.bindAll(this); - this.template = _.template($('#footer-config-template').html()); - }, - render: function() { - $('#page').remove(); - $('#content-container').append(this.$el); - this.$el.html(this.template()); - M.editor.wysiwig('#footer-input'); - }, - saveFooter: function() { - tinymce.triggerSave(false, true); - var data = $('#footer-input').html(); - console.log(data); - } - }); - /* view to configure custom navigation menu */ var MenuConfigView = Backbone.View.extend({ tagName: 'div', @@ -357,25 +326,29 @@ $('#content-container').append(this.$el); console.log('rendering..', this.$el); this.$el.html(this.template({ + menu_order: this.model.get('menuOrder'), pos: this.model.get('pos'), menu: this.model.get('html') })); this.$menuOptions = $('.menu-options'); + this.$menuOrder = $('#menu-order-wrap'); if(this.model.get('customMenu') === true) { $('#custom-menu').attr('checked', true); this.$menuOptions.show({complete: function() { - M.editor.wysiwig('#menu'); + //M.editor.wysiwig('#menu'); }}); } }, showMenuOptions: function(bool) { if(bool === true) { + this.$menuOrder.hide(); this.$menuOptions.show({complete: function() { //M.editor.wysiwig('#menu'); }}); } else { + this.$menuOrder.show(); this.$menuOptions.hide(); } }, @@ -391,18 +364,18 @@ }, saveMenu: function() { console.log('saving menu..'); - // var menuHTML = $('#menu').val().trim(); - //this.model.set({'html': menuHTML}); - //console.log(this.model.toJSON()); - //alert('saveMenu called'); - var bool; - if($("custom-menu").is(":checked")) { + var bool, html = '', menuOrder = []; + if($('#custom-menu').is(":checked")) { bool = true; + html = $('#menu').val().trim(); } else { bool = false; + menuOrder = $('#menu-order').val().split(','); } - this.model.save({customMenu: bool}, { + this.model.set({'customMenu': bool, 'html': html, 'menuOrder': menuOrder}); + console.log(this.model.toJSON()); + this.model.save({}, { success: function(model, response) { console.log(model, response); }, diff --git a/mouchak/static/js/models.js b/mouchak/static/js/models.js index eb62443..99bd7b8 100644 --- a/mouchak/static/js/models.js +++ b/mouchak/static/js/models.js @@ -137,4 +137,7 @@ 'Pages': Pages }; + //content types to render in content menu + M.contentTypes = ['text', 'image', 'video', 'table', 'plugin']; + })(M); diff --git a/mouchak/static/js/mouchak.js b/mouchak/static/js/mouchak.js index 697975e..1946497 100644 --- a/mouchak/static/js/mouchak.js +++ b/mouchak/static/js/mouchak.js @@ -64,19 +64,24 @@ var NavigationView = Backbone.View.extend({ }, populate: function() { var item_template = _.template($('#nav-item-template').html()); - _.each(M.pages.models, function(page) { - //console.log('no children?', _.isEmpty(page.get('children'))); + _.each(this.model.get('menuOrder'), function(page) { this.$ul.append(item_template({ + cls: '', + page: page + })); + //console.log('no children?', _.isEmpty(page.get('children'))); + /*this.$ul.append(item_template({ cls: (_.isEmpty(page.get('children'))) ? '' : 'dropdown', page: page.get('name') - })); + }));*/ }, this); }, navClicked: function(event) { this.$links.removeClass('active'); if(!event) { var fragment = location.hash.split('/')[1]; - var pos = _.indexOf(M.pages.models, M.pages.where({'name': fragment})[0]); + //var pos = _.indexOf(M.pages.models, M.pages.where({'name': fragment})[0]); + var pos = _.indexOf(this.model.get('menuOrder'), fragment); if(!fragment) { pos = 0; } diff --git a/mouchak/templates/editor.html b/mouchak/templates/editor.html index d71ca58..66b1beb 100644 --- a/mouchak/templates/editor.html +++ b/mouchak/templates/editor.html @@ -54,28 +54,33 @@