Commit 878048ff08a7c11d81de0ca9ddab7253075da41c
- Diff rendering mode:
- inline
- side by side
mouchak/static/js/editor.js
(39 / 19)
  | |||
49 | 49 | M.editor.pageview = newpageview; | |
50 | 50 | }, | |
51 | 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 | 56 | 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); | ||
54 | 60 | M.pages.get(id).destroy({ | |
55 | 61 | success: function(model, response) { | |
56 | console.log('deleted', model, response); | ||
62 | //console.log('deleted', model, response); | ||
57 | 63 | M.pages.remove(id); | |
58 | 64 | M.pagelistview.render(); | |
59 | 65 | if(M.editor.pageview) { | |
60 | 66 | M.editor.pageview.remove(); | |
61 | 67 | } | |
68 | $('#notifications').html(success_template({ | ||
69 | title: 'Deleted', | ||
70 | msg: '' | ||
71 | })); | ||
62 | 72 | }, | |
63 | 73 | error: function(model, xhr) { | |
64 | 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 | 82 | showMenu: function(event) { | |
69 | 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 | 108 | initialize: function() { | |
109 | 109 | _.bindAll(this); | |
110 | 110 | _.bind(this.render, this); | |
111 | this.editing = false; | ||
111 | 112 | $('#page').remove(); | |
112 | 113 | $('#content-container').append(this.$el); | |
113 | 114 | this.template = _.template($('#page-template').html()); | |
… | … | ||
119 | 119 | this.model.bind('change:name', this.nameChanged); | |
120 | 120 | }, | |
121 | 121 | modelChanged: function(page) { | |
122 | console.log('model changed ', page.id, ' re-rendering...'); | ||
122 | //console.log('model changed ', page.id, ' re-rendering...'); | ||
123 | 123 | this.render(); | |
124 | 124 | }, | |
125 | 125 | contentChanged: function(page) { | |
126 | console.log('content changed', page); | ||
126 | //console.log('content changed', page); | ||
127 | 127 | this.render(); | |
128 | 128 | }, | |
129 | 129 | nameChanged: function(page) { | |
130 | 130 | //M.pagelistview.render(); | |
131 | console.log('name changed', page); | ||
131 | //console.log('name changed', page); | ||
132 | 132 | }, | |
133 | 133 | render: function() { | |
134 | 134 | $('#page').html(''); | |
… | … | ||
174 | 174 | return false; | |
175 | 175 | }, | |
176 | 176 | addContent: function() { | |
177 | console.log('addContent'); | ||
177 | //console.log('addContent'); | ||
178 | 178 | var content = new M.types.model.text({ | |
179 | 179 | type: 'text', | |
180 | 180 | title: '', | |
181 | 181 | data: '' | |
182 | 182 | }); | |
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; | ||
186 | 184 | var contentview = new ContentView({model: content}); | |
187 | 185 | contentview.render(); | |
188 | 186 | M.editor.contentview = contentview; | |
189 | 187 | return false; | |
190 | 188 | }, | |
191 | 189 | updateContent: function(json) { | |
192 | if(!this.edit.on && this.edit.idx < 0) { | ||
190 | if(!this.editing) { | ||
193 | 191 | return; | |
194 | 192 | } | |
193 | //console.log('updateContent in Pageview'); | ||
195 | 194 | 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); | ||
198 | 198 | this.model.set({'content': content}); | |
199 | 199 | this.render(); | |
200 | 200 | }, | |
201 | 201 | removeContent: function(event) { | |
202 | console.log('recvd remove event..about to process..'); | ||
202 | //console.log('recvd remove event..about to process..'); | ||
203 | 203 | var content = this.model.get('content'); | |
204 | 204 | var idx = $(event.target).parent().attr('for'); | |
205 | 205 | 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]); | ||
207 | 207 | content.splice(idx, 1); | |
208 | 208 | this.model.set({'content': content}); | |
209 | console.log('after removing: ', this.model.get('content')); | ||
209 | //console.log('after removing: ', this.model.get('content')); | ||
210 | 210 | this.render(); | |
211 | 211 | return false; | |
212 | 212 | }, | |
… | … | ||
229 | 229 | ||
230 | 230 | this.model.save({}, { | |
231 | 231 | success: function(model, response) { | |
232 | console.log('saved', model, response); | ||
232 | //console.log('saved', model, response); | ||
233 | 233 | model.set(response.page); | |
234 | 234 | model.id = response.page.id; | |
235 | 235 | M.pagelistview.render(); | |
… | … | ||
355 | 355 | render: function() { | |
356 | 356 | $('#page').remove(); | |
357 | 357 | $('#content-container').append(this.$el); | |
358 | console.log('rendering..', this.$el); | ||
358 | //console.log('rendering..', this.$el); | ||
359 | 359 | this.$el.html(this.template({ | |
360 | 360 | menu_order: this.model.get('menuOrder'), | |
361 | 361 | pos: this.model.get('pos'), | |
… | … | ||
408 | 408 | menuOrder = $('#menu-order').val().split(','); | |
409 | 409 | } | |
410 | 410 | this.model.set({'customMenu': bool, 'html': html, 'menuOrder': menuOrder}); | |
411 | console.log(this.model.toJSON()); | ||
411 | //console.log(this.model.toJSON()); | ||
412 | 412 | this.model.save({}, { | |
413 | 413 | success: function(model, response) { | |
414 | console.log(model, response); | ||
414 | //console.log(model, response); | ||
415 | 415 | $('#notifications').html(success_template({ | |
416 | 416 | title: 'Saved', | |
417 | 417 | msg: '' |