Commit 878048ff08a7c11d81de0ca9ddab7253075da41c

Fix extra item appearing when adding new content

  - When a new content was added, always an empty extra content element was
    getting created. Fix that.
  - Added notification and confirmation for deleting pages.
  - Commented out all console.log lines
  
4949 M.editor.pageview = newpageview;
5050 },
5151 removePage: function(event) {
52 var option = confirm("Are you sure, you want to delete this page?");
53 if(!option) {
54 return false;
55 }
5256 var id = $(event.target).parent('.remove').attr('for');
53 console.log('remove', id);
57 var success_template = _.template($('#success-notif').html());
58 var fail_template = _.template($('#fail-notif').html());
59 //console.log('remove', id);
5460 M.pages.get(id).destroy({
5561 success: function(model, response) {
56 console.log('deleted', model, response);
62 //console.log('deleted', model, response);
5763 M.pages.remove(id);
5864 M.pagelistview.render();
5965 if(M.editor.pageview) {
6066 M.editor.pageview.remove();
6167 }
68 $('#notifications').html(success_template({
69 title: 'Deleted',
70 msg: ''
71 }));
6272 },
6373 error: function(model, xhr) {
6474 console.log('failed', model, xhr);
75 $('#notifications').html(fail_template({
76 title: 'Error',
77 msg: 'Failed to delete. Please try again.'
78 }));
6579 }
6680 });
6781 },
6882 showMenu: function(event) {
6983 this.menuconfigview.render();
84 },
85 // validate the page list with menu order list
86 validate: function() {
87 //TODO: validate if the menu order list matches with the list of pages
88 //and provide relevant notifications
7089 }
7190 });
7291
108108 initialize: function() {
109109 _.bindAll(this);
110110 _.bind(this.render, this);
111 this.editing = false;
111112 $('#page').remove();
112113 $('#content-container').append(this.$el);
113114 this.template = _.template($('#page-template').html());
119119 this.model.bind('change:name', this.nameChanged);
120120 },
121121 modelChanged: function(page) {
122 console.log('model changed ', page.id, ' re-rendering...');
122 //console.log('model changed ', page.id, ' re-rendering...');
123123 this.render();
124124 },
125125 contentChanged: function(page) {
126 console.log('content changed', page);
126 //console.log('content changed', page);
127127 this.render();
128128 },
129129 nameChanged: function(page) {
130130 //M.pagelistview.render();
131 console.log('name changed', page);
131 //console.log('name changed', page);
132132 },
133133 render: function() {
134134 $('#page').html('');
174174 return false;
175175 },
176176 addContent: function() {
177 console.log('addContent');
177 //console.log('addContent');
178178 var content = new M.types.model.text({
179179 type: 'text',
180180 title: '',
181181 data: ''
182182 });
183 this.model.get('content').push(content.toJSON());
184 var idx = this.model.get('content').length;
185 this.edit = {on: true, idx: idx};
183 this.editing = true;
186184 var contentview = new ContentView({model: content});
187185 contentview.render();
188186 M.editor.contentview = contentview;
189187 return false;
190188 },
191189 updateContent: function(json) {
192 if(!this.edit.on && this.edit.idx < 0) {
190 if(!this.editing) {
193191 return;
194192 }
193 //console.log('updateContent in Pageview');
195194 var content = this.model.get('content');
196 content[this.edit.idx] = json;
197 this.edit = {on: false, idx: -1};
195 content.push(json);
196 this.editing = false;
197 //console.log('setting content in page: ', content);
198198 this.model.set({'content': content});
199199 this.render();
200200 },
201201 removeContent: function(event) {
202 console.log('recvd remove event..about to process..');
202 //console.log('recvd remove event..about to process..');
203203 var content = this.model.get('content');
204204 var idx = $(event.target).parent().attr('for');
205205 idx = Number(idx); //is this a correct way of doing it?
206 console.log('remove content: ', content[idx]);
206 //console.log('remove content: ', content[idx]);
207207 content.splice(idx, 1);
208208 this.model.set({'content': content});
209 console.log('after removing: ', this.model.get('content'));
209 //console.log('after removing: ', this.model.get('content'));
210210 this.render();
211211 return false;
212212 },
229229
230230 this.model.save({}, {
231231 success: function(model, response) {
232 console.log('saved', model, response);
232 //console.log('saved', model, response);
233233 model.set(response.page);
234234 model.id = response.page.id;
235235 M.pagelistview.render();
355355 render: function() {
356356 $('#page').remove();
357357 $('#content-container').append(this.$el);
358 console.log('rendering..', this.$el);
358 //console.log('rendering..', this.$el);
359359 this.$el.html(this.template({
360360 menu_order: this.model.get('menuOrder'),
361361 pos: this.model.get('pos'),
408408 menuOrder = $('#menu-order').val().split(',');
409409 }
410410 this.model.set({'customMenu': bool, 'html': html, 'menuOrder': menuOrder});
411 console.log(this.model.toJSON());
411 //console.log(this.model.toJSON());
412412 this.model.save({}, {
413413 success: function(model, response) {
414 console.log(model, response);
414 //console.log(model, response);
415415 $('#notifications').html(success_template({
416416 title: 'Saved',
417417 msg: ''