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
| | | | 49 | M.editor.pageview = newpageview; | 49 | M.editor.pageview = newpageview; |
---|
50 | }, | 50 | }, |
---|
51 | removePage: function(event) { | 51 | removePage: function(event) { |
---|
| | 52 | var option = confirm("Are you sure, you want to delete this page?"); |
---|
| | 53 | if(!option) { |
---|
| | 54 | return false; |
---|
| | 55 | } |
---|
52 | var id = $(event.target).parent('.remove').attr('for'); | 56 | var id = $(event.target).parent('.remove').attr('for'); |
---|
53 | console.log('remove', id); | | 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); |
---|
54 | M.pages.get(id).destroy({ | 60 | M.pages.get(id).destroy({ |
---|
55 | success: function(model, response) { | 61 | success: function(model, response) { |
---|
56 | console.log('deleted', model, response); | | console.log('deleted', model, response); |
---|
| | 62 | //console.log('deleted', model, response); | 57 | M.pages.remove(id); | 63 | M.pages.remove(id); |
---|
58 | M.pagelistview.render(); | 64 | M.pagelistview.render(); |
---|
59 | if(M.editor.pageview) { | 65 | if(M.editor.pageview) { |
---|
60 | M.editor.pageview.remove(); | 66 | M.editor.pageview.remove(); |
---|
61 | } | 67 | } |
---|
| | 68 | $('#notifications').html(success_template({ |
---|
| | 69 | title: 'Deleted', |
---|
| | 70 | msg: '' |
---|
| | 71 | })); |
---|
62 | }, | 72 | }, |
---|
63 | error: function(model, xhr) { | 73 | error: function(model, xhr) { |
---|
64 | console.log('failed', model, xhr); | 74 | console.log('failed', model, xhr); |
---|
| | 75 | $('#notifications').html(fail_template({ |
---|
| | 76 | title: 'Error', |
---|
| | 77 | msg: 'Failed to delete. Please try again.' |
---|
| | 78 | })); |
---|
65 | } | 79 | } |
---|
66 | }); | 80 | }); |
---|
67 | }, | 81 | }, |
---|
68 | showMenu: function(event) { | 82 | showMenu: function(event) { |
---|
69 | this.menuconfigview.render(); | 83 | 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 |
---|
70 | } | 89 | } |
---|
71 | }); | 90 | }); |
---|
72 | | 91 | |
---|
… | | … | |
---|
108 | initialize: function() { | 108 | initialize: function() { |
---|
109 | _.bindAll(this); | 109 | _.bindAll(this); |
---|
110 | _.bind(this.render, this); | 110 | _.bind(this.render, this); |
---|
| | 111 | this.editing = false; |
---|
111 | $('#page').remove(); | 112 | $('#page').remove(); |
---|
112 | $('#content-container').append(this.$el); | 113 | $('#content-container').append(this.$el); |
---|
113 | this.template = _.template($('#page-template').html()); | 114 | this.template = _.template($('#page-template').html()); |
---|
… | | … | |
---|
119 | this.model.bind('change:name', this.nameChanged); | 119 | this.model.bind('change:name', this.nameChanged); |
---|
120 | }, | 120 | }, |
---|
121 | modelChanged: function(page) { | 121 | modelChanged: function(page) { |
---|
122 | console.log('model changed ', page.id, ' re-rendering...'); | | console.log('model changed ', page.id, ' re-rendering...'); |
---|
| | 122 | //console.log('model changed ', page.id, ' re-rendering...'); | 123 | this.render(); | 123 | this.render(); |
---|
124 | }, | 124 | }, |
---|
125 | contentChanged: function(page) { | 125 | contentChanged: function(page) { |
---|
126 | console.log('content changed', page); | | console.log('content changed', page); |
---|
| | 126 | //console.log('content changed', page); | 127 | this.render(); | 127 | this.render(); |
---|
128 | }, | 128 | }, |
---|
129 | nameChanged: function(page) { | 129 | nameChanged: function(page) { |
---|
130 | //M.pagelistview.render(); | 130 | //M.pagelistview.render(); |
---|
131 | console.log('name changed', page); | | console.log('name changed', page); |
---|
| | 131 | //console.log('name changed', page); | 132 | }, | 132 | }, |
---|
133 | render: function() { | 133 | render: function() { |
---|
134 | $('#page').html(''); | 134 | $('#page').html(''); |
---|
… | | … | |
---|
174 | return false; | 174 | return false; |
---|
175 | }, | 175 | }, |
---|
176 | addContent: function() { | 176 | addContent: function() { |
---|
177 | console.log('addContent'); | | console.log('addContent'); |
---|
| | 177 | //console.log('addContent'); | 178 | var content = new M.types.model.text({ | 178 | var content = new M.types.model.text({ |
---|
179 | type: 'text', | 179 | type: 'text', |
---|
180 | title: '', | 180 | title: '', |
---|
181 | data: '' | 181 | data: '' |
---|
182 | }); | 182 | }); |
---|
183 | this.model.get('content').push(content.toJSON()); | | this.model.get('content').push(content.toJSON()); |
---|
184 | var idx = this.model.get('content').length; | | var idx = this.model.get('content').length; |
---|
185 | this.edit = {on: true, idx: idx}; | | this.edit = {on: true, idx: idx}; |
---|
| | 183 | this.editing = true; | 186 | var contentview = new ContentView({model: content}); | 184 | var contentview = new ContentView({model: content}); |
---|
187 | contentview.render(); | 185 | contentview.render(); |
---|
188 | M.editor.contentview = contentview; | 186 | M.editor.contentview = contentview; |
---|
189 | return false; | 187 | return false; |
---|
190 | }, | 188 | }, |
---|
191 | updateContent: function(json) { | 189 | updateContent: function(json) { |
---|
192 | if(!this.edit.on && this.edit.idx < 0) { | | if(!this.edit.on && this.edit.idx < 0) { |
---|
| | 190 | if(!this.editing) { | 193 | return; | 191 | return; |
---|
194 | } | 192 | } |
---|
| | 193 | //console.log('updateContent in Pageview'); |
---|
195 | var content = this.model.get('content'); | 194 | var content = this.model.get('content'); |
---|
196 | content[this.edit.idx] = json; | | content[this.edit.idx] = json; |
---|
197 | this.edit = {on: false, idx: -1}; | | this.edit = {on: false, idx: -1}; |
---|
| | 195 | content.push(json); | | | 196 | this.editing = false; |
---|
| | 197 | //console.log('setting content in page: ', content); |
---|
198 | this.model.set({'content': content}); | 198 | this.model.set({'content': content}); |
---|
199 | this.render(); | 199 | this.render(); |
---|
200 | }, | 200 | }, |
---|
201 | removeContent: function(event) { | 201 | removeContent: function(event) { |
---|
202 | console.log('recvd remove event..about to process..'); | | console.log('recvd remove event..about to process..'); |
---|
| | 202 | //console.log('recvd remove event..about to process..'); | 203 | var content = this.model.get('content'); | 203 | var content = this.model.get('content'); |
---|
204 | var idx = $(event.target).parent().attr('for'); | 204 | var idx = $(event.target).parent().attr('for'); |
---|
205 | idx = Number(idx); //is this a correct way of doing it? | 205 | idx = Number(idx); //is this a correct way of doing it? |
---|
206 | console.log('remove content: ', content[idx]); | | console.log('remove content: ', content[idx]); |
---|
| | 206 | //console.log('remove content: ', content[idx]); | 207 | content.splice(idx, 1); | 207 | content.splice(idx, 1); |
---|
208 | this.model.set({'content': content}); | 208 | this.model.set({'content': content}); |
---|
209 | console.log('after removing: ', this.model.get('content')); | | console.log('after removing: ', this.model.get('content')); |
---|
| | 209 | //console.log('after removing: ', this.model.get('content')); | 210 | this.render(); | 210 | this.render(); |
---|
211 | return false; | 211 | return false; |
---|
212 | }, | 212 | }, |
---|
… | | … | |
---|
229 | | 229 | |
---|
230 | this.model.save({}, { | 230 | this.model.save({}, { |
---|
231 | success: function(model, response) { | 231 | success: function(model, response) { |
---|
232 | console.log('saved', model, response); | | console.log('saved', model, response); |
---|
| | 232 | //console.log('saved', model, response); | 233 | model.set(response.page); | 233 | model.set(response.page); |
---|
234 | model.id = response.page.id; | 234 | model.id = response.page.id; |
---|
235 | M.pagelistview.render(); | 235 | M.pagelistview.render(); |
---|
… | | … | |
---|
355 | render: function() { | 355 | render: function() { |
---|
356 | $('#page').remove(); | 356 | $('#page').remove(); |
---|
357 | $('#content-container').append(this.$el); | 357 | $('#content-container').append(this.$el); |
---|
358 | console.log('rendering..', this.$el); | | console.log('rendering..', this.$el); |
---|
| | 358 | //console.log('rendering..', this.$el); | 359 | this.$el.html(this.template({ | 359 | this.$el.html(this.template({ |
---|
360 | menu_order: this.model.get('menuOrder'), | 360 | menu_order: this.model.get('menuOrder'), |
---|
361 | pos: this.model.get('pos'), | 361 | pos: this.model.get('pos'), |
---|
… | | … | |
---|
408 | menuOrder = $('#menu-order').val().split(','); | 408 | menuOrder = $('#menu-order').val().split(','); |
---|
409 | } | 409 | } |
---|
410 | this.model.set({'customMenu': bool, 'html': html, 'menuOrder': menuOrder}); | 410 | this.model.set({'customMenu': bool, 'html': html, 'menuOrder': menuOrder}); |
---|
411 | console.log(this.model.toJSON()); | | console.log(this.model.toJSON()); |
---|
| | 411 | //console.log(this.model.toJSON()); | 412 | this.model.save({}, { | 412 | this.model.save({}, { |
---|
413 | success: function(model, response) { | 413 | success: function(model, response) { |
---|
414 | console.log(model, response); | | console.log(model, response); |
---|
| | 414 | //console.log(model, response); | 415 | $('#notifications').html(success_template({ | 415 | $('#notifications').html(success_template({ |
---|
416 | title: 'Saved', | 416 | title: 'Saved', |
---|
417 | msg: '' | 417 | msg: '' |
---|