Commit 3fd837c82fc36a1c9d67b643bc967fcc8172d5c5

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.
  
1717siteContent = db['content']
1818siteMenu = db['menu']
1919if siteMenu.find_one() == None:
20 siteMenu.insert({'customMenu': False})
20 siteMenu.insert({'customMenu': False, 'menuOrder': []})
2121
22
2223# handy reference to otherwise long name
2324bson.ObjId = bson.objectid.ObjectId
2425
5050@app.route('/edit', methods=['GET'])
5151def edit():
5252 return flask.render_template('editor.html', content=getContent(),
53 title=conf)
53 title=conf.SITE_TITLE)
5454
5555
5656@app.route('/page', methods=['POST'])
115115 # print _id
116116 # res = siteMenu.remove({'_id': bson.ObjId(_id)})
117117 # return flask.jsonify(status='deleted')
118
118119
119120
120121if __name__ == "__main__":
  
99 'click .pagename .disp': 'showPage',
1010 'click #addPage': 'addPage',
1111 'click .pagename .remove': 'removePage',
12 'click #menu-config': 'showMenu'//,
13 //'click #footer-config': 'footerConfig'
12 'click #menu-config': 'showMenu',
1413 },
1514 initialize: function() {
1615 _.bindAll(this);
2424 //console.log(menu);
2525 this.menuconfig = new M.types.model.menu(menu);
2626 this.menuconfigview = new MenuConfigView({model: this.menuconfig});
27 //this.footerconfigview = new FooterConfigView();
2827 },
2928 render: function() {
3029 // append the page list
6767 },
6868 showMenu: function(event) {
6969 this.menuconfigview.render();
70 },
71 footerConfig: function(event) {
72 //this.footerconfigview.render();
7370 }
7471 });
7572
238238 },
239239 render: function() {
240240 this.$el.html('');
241 console.log(this.model);
242241 var type = this.model.get('type');
243242 this.$el.append(this.template({
244243 type: this.model.get('type'),
246246 }));
247247
248248 this.$select = $('.contentview select');
249 //this.$select.bind('change', this.typeChanged);
250249 this.$select.val(type);
251250
252251 if(type === 'text') {
258258 }
259259 else if(type === 'image' || type === 'video' ||
260260 type === 'audio' || type === 'plugin') {
261 var template = _.template($('#media-template').html());
262261
262 var template = _.template($('#media-template').html());
263263 $('#specific-content').html(template({
264264 src: this.model.get('src')
265265 }));
266266
267 //provide the users a preview
267 //TODO: provide the users a preview
268268 /*var view = new M.types.view[type]({model: this.model});
269269 //$('#specific-content.preview').html();
270270 view.render('.preview');*/
309309 }
310310 });
311311
312 /* view to configure footer */
313 var FooterConfigView = Backbone.View.extend({
314 tagName: 'div',
315 id: 'page',
316 events: {
317 'click #saveFooter': 'saveFooter'
318 },
319 initialize: function() {
320 _.bindAll(this);
321 this.template = _.template($('#footer-config-template').html());
322 },
323 render: function() {
324 $('#page').remove();
325 $('#content-container').append(this.$el);
326 this.$el.html(this.template());
327 M.editor.wysiwig('#footer-input');
328 },
329 saveFooter: function() {
330 tinymce.triggerSave(false, true);
331 var data = $('#footer-input').html();
332 console.log(data);
333 }
334 });
335
336312 /* view to configure custom navigation menu */
337313 var MenuConfigView = Backbone.View.extend({
338314 tagName: 'div',
326326 $('#content-container').append(this.$el);
327327 console.log('rendering..', this.$el);
328328 this.$el.html(this.template({
329 menu_order: this.model.get('menuOrder'),
329330 pos: this.model.get('pos'),
330331 menu: this.model.get('html')
331332 }));
332333 this.$menuOptions = $('.menu-options');
334 this.$menuOrder = $('#menu-order-wrap');
333335
334336 if(this.model.get('customMenu') === true) {
335337 $('#custom-menu').attr('checked', true);
336338 this.$menuOptions.show({complete: function() {
337 M.editor.wysiwig('#menu');
339 //M.editor.wysiwig('#menu');
338340 }});
339341 }
340342 },
341343 showMenuOptions: function(bool) {
342344 if(bool === true) {
345 this.$menuOrder.hide();
343346 this.$menuOptions.show({complete: function() {
344347 //M.editor.wysiwig('#menu');
345348 }});
346349 }
347350 else {
351 this.$menuOrder.show();
348352 this.$menuOptions.hide();
349353 }
350354 },
364364 },
365365 saveMenu: function() {
366366 console.log('saving menu..');
367 // var menuHTML = $('#menu').val().trim();
368 //this.model.set({'html': menuHTML});
369 //console.log(this.model.toJSON());
370 //alert('saveMenu called');
371 var bool;
372 if($("custom-menu").is(":checked")) {
367 var bool, html = '', menuOrder = [];
368 if($('#custom-menu').is(":checked")) {
373369 bool = true;
370 html = $('#menu').val().trim();
374371 }
375372 else {
376373 bool = false;
374 menuOrder = $('#menu-order').val().split(',');
377375 }
378 this.model.save({customMenu: bool}, {
376 this.model.set({'customMenu': bool, 'html': html, 'menuOrder': menuOrder});
377 console.log(this.model.toJSON());
378 this.model.save({}, {
379379 success: function(model, response) {
380380 console.log(model, response);
381381 },
  
137137 'Pages': Pages
138138 };
139139
140 //content types to render in content menu
141 M.contentTypes = ['text', 'image', 'video', 'table', 'plugin'];
142
140143})(M);
  
6464 },
6565 populate: function() {
6666 var item_template = _.template($('#nav-item-template').html());
67 _.each(M.pages.models, function(page) {
68 //console.log('no children?', _.isEmpty(page.get('children')));
67 _.each(this.model.get('menuOrder'), function(page) {
6968 this.$ul.append(item_template({
69 cls: '',
70 page: page
71 }));
72 //console.log('no children?', _.isEmpty(page.get('children')));
73 /*this.$ul.append(item_template({
7074 cls: (_.isEmpty(page.get('children'))) ? '' : 'dropdown',
7175 page: page.get('name')
72 }));
76 }));*/
7377 }, this);
7478 },
7579 navClicked: function(event) {
7680 this.$links.removeClass('active');
7781 if(!event) {
7882 var fragment = location.hash.split('/')[1];
79 var pos = _.indexOf(M.pages.models, M.pages.where({'name': fragment})[0]);
83 //var pos = _.indexOf(M.pages.models, M.pages.where({'name': fragment})[0]);
84 var pos = _.indexOf(this.model.get('menuOrder'), fragment);
8085 if(!fragment) {
8186 pos = 0;
8287 }
  
5454 <div class="page">
5555 <div class="menu-config">
5656 <h4> Menu Config </h4>
57 <!-- <form class="form-horizontal"> -->
57 <div class="control-group">
58 <input id="custom-menu" type="checkbox">
59 <span class=""><strong> Custom Menu </strong></span>
60 </div>
61 <div class="control-group" id="menu-order-wrap">
62 <% if(!$('#custom-menu').is(':checked')) { %>
63 <div class="input-prepend">
64 <span class="add-on"> <strong> Menu Order</strong></span>
65 <input id="menu-order" type="text"
66 placeholder="list,page,names,for,menu,order" value="<%= menu_order %>">
67 </div>
68 <% } %>
69 </div>
70 <div class="menu-options" style="display: none;">
5871 <div class="control-group">
59 <input id="custom-menu" type="checkbox">
60 <span class=""><strong> Custom Menu </strong></span>
61 </div>
62 <button id="updateMenu" class="btn btn-primary pull-right"> Update </button>
63 <div class="clearfix"></div>
64 <div class="menu-options" style="display: none;">
65 <div class="control-group">
66 <div class="input-prepend">
67 <span class="add-on"> <strong> Position </strong></span>
68 <input id="pos" type="text" placeholder="[left, top]"
69 value="<%= pos %>">
70 </div>
72 <div class="input-prepend">
73 <span class="add-on"> <strong> Position </strong></span>
74 <input id="pos" type="text" placeholder="[left, top]"
75 value="<%= pos %>">
7176 </div>
72 <label><strong> HTML </strong></label>
73 <div id="menu">
74 <%= menu %>
75 </div>
7677 </div>
77 <!-- </form> -->
78 <label><strong> HTML for menu: </strong></label>
79 <textarea cols="25" rows="8" id="menu"><%= menu %></textarea>
80 </div>
7881 </div>
82 <button id="updateMenu" class="btn btn-primary pull-right"> Update </button>
83 <div class="clearfix"></div>
7984 </div>
8085 </script>
8186
169169 <div class="">
170170 <label><b>Type</b></label>
171171 <select>
172 <% _.each(_.keys(M.types.model), function(type) { %>
172 <% _.each(M.contentTypes, function(type) { %>
173173 <option><%= type %></option>
174174 <% }); %>
175175 </select>