Commit 66e3c71ebb4c3875c964dbc631e3486b10fa1ec1

Fix: adding to existing content was not saving

  When more content was added to exisiting content, it was not saving the new
content. This because of a one-line bug in editor.js. Fix that.
  • Diff rendering mode:
  • inline
  • side by side

mouchak/static/js/editor.js

165 showContent: function(event) {165 showContent: function(event) {
166 var idx = $(event.target).closest('.content-item').attr('id').166 var idx = $(event.target).closest('.content-item').attr('id').
167 split('-')[1];167 split('-')[1];
168 this.edit = {on: true, idx: idx};
169 var content = this.model.get('content')[idx];168 var content = this.model.get('content')[idx];
170 content = new M.types.model[content.type](content);169 content = new M.types.model[content.type](content);
170 this.editing = true;
171 var contentview = new ContentView({model: content});171 var contentview = new ContentView({model: content});
172 contentview.render();172 contentview.render();
173 M.editor.contentview = contentview;173 M.editor.contentview = contentview;
365 this.$menuOrder = $('#menu-order-wrap');365 this.$menuOrder = $('#menu-order-wrap');
366366
367 if(this.model.get('customMenu') === true) {367 if(this.model.get('customMenu') === true) {
368 this.$menuOrder.hide();
368 $('#custom-menu').attr('checked', true);369 $('#custom-menu').attr('checked', true);
369 this.$menuOptions.show({complete: function() {370 this.$menuOptions.show({complete: function() {
370 //M.editor.wysiwig('#menu');371 //M.editor.wysiwig('#menu');
399 var success_template = _.template($('#success-notif').html());399 var success_template = _.template($('#success-notif').html());
400 var fail_template = _.template($('#fail-notif').html());400 var fail_template = _.template($('#fail-notif').html());
401401
402 var bool, html = '', menuOrder = [];
403 if($('#custom-menu').is(":checked")) {
404 bool = true;
405 html = $('#menu').val().trim();
402 if($('#custom-menu').is(':checked')) {
403 var html = $('#menu').val().trim() || '';
404 this.model.set({'customMenu': true, 'html': html});
406 }405 }
407 else {406 else {
408 bool = false;
409 menuOrder = $('#menu-order').val().split(',');
407 var menuOrder = $('#menu-order').val().split(',') || [];
408 this.model.set({'customMenu': false, 'menuOrder': menuOrder});
410 }409 }
411 this.model.set({'customMenu': bool, 'html': html, 'menuOrder': menuOrder});
412 //console.log(this.model.toJSON());
410 //console.log('menu model: ', this.model.toJSON());
413 this.model.save({}, {411 this.model.save({}, {
414 success: function(model, response) {412 success: function(model, response) {
415 //console.log(model, response);413 //console.log(model, response);

mouchak/templates/editor.html

54 <div class="page">54 <div class="page">
55 <div class="menu-config">55 <div class="menu-config">
56 <h4> Menu Config </h4>56 <h4> Menu Config </h4>
57
58 <div class="control-group" id="menu-order-wrap">
59 <div class="input-prepend">
60 <span class="add-on"> <strong> Menu Order</strong></span>
61 <input id="menu-order" type="text" class="span4"
62 placeholder="list,page,names,for,menu,order" value="<%= menu_order %>">
63 </div>
64 </div>
65
57 <div class="control-group">66 <div class="control-group">
58 <input id="custom-menu" type="checkbox">67 <input id="custom-menu" type="checkbox">
59 <span class=""><strong> Custom Menu </strong></span>68 <span class=""><strong> Custom Menu </strong></span>
60 </div>69 </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" class="span4"
66 placeholder="list,page,names,for,menu,order" value="<%= menu_order %>">
67 </div>
68 <% } %>
69 </div>
70
70 <div class="menu-options" style="display: none;">71 <div class="menu-options" style="display: none;">
71 <div class="control-group">72 <div class="control-group">
72 <div class="input-prepend">73 <div class="input-prepend">
79 <label><strong> HTML for menu: </strong></label>79 <label><strong> HTML for menu: </strong></label>
80 <textarea cols="25" rows="8" id="menu"><%= menu %></textarea>80 <textarea cols="25" rows="8" id="menu"><%= menu %></textarea>
81 </div>81 </div>
82
82 </div>83 </div>
83 <button id="updateMenu" class="btn btn-primary pull-right"> Update </button>84 <button id="updateMenu" class="btn btn-primary pull-right"> Update </button>
84 <div class="clearfix"></div>85 <div class="clearfix"></div>