Commit 24cd97ed92bbb6fc321663ad68a08ded9a88f082

Fix nested content and dangling view bug

  -  When saving content or menu was always getting nested in the backend. Fix
     that.
  - When a new page was created and then navigated to another page, view of the
    new page remained dangled and could not be reached - because we were not
    creating any ID for it; now saving it to server to get an ID and then
    updating the view.
  • Diff rendering mode:
  • inline
  • side by side

mouchak/server.py

71 del(newpage['_id'])71 del(newpage['_id'])
72 print newpage72 print newpage
73 # FIXME: handle errors73 # FIXME: handle errors
74 return flask.jsonify(status='ok', page=newpage)
74 #return flask.jsonify(status='ok', page=newpage)
75 return flask.jsonify(newpage)
7576
7677
77@app.route('/page/<_id>', methods=['PUT', 'DELETE'])78@app.route('/page/<_id>', methods=['PUT', 'DELETE'])
86 print res86 print res
87 if res['err'] == None:87 if res['err'] == None:
88 print changedPage88 print changedPage
89 return flask.jsonify(status='ok', page=changedPage)
89 #return flask.jsonify(status='ok', page=changedPage)
90 return flask.jsonify(changedPage)
9091
91 elif flask.request.method == 'DELETE':92 elif flask.request.method == 'DELETE':
92 delPage = flask.request.url93 delPage = flask.request.url
119 print changedMenu119 print changedMenu
120 res = siteMenu.update({'_id': bson.ObjId(_id)}, changedMenu)120 res = siteMenu.update({'_id': bson.ObjId(_id)}, changedMenu)
121 print res121 print res
122 return flask.jsonify(status='ok', menu=changedMenu)
122 #return flask.jsonify(status='ok', menu=changedMenu)
123 return flask.jsonify(changedMenu)
123124
124 #elif flask.request.method == 'DELETE':125 #elif flask.request.method == 'DELETE':
125 # delMenu = flask.request.url126 # delMenu = flask.request.url

mouchak/static/js/editor.js

30 this.$pagelist.html('');30 this.$pagelist.html('');
31 _.each(M.pages.models, function(page) {31 _.each(M.pages.models, function(page) {
32 this.$pagelist.append(this.listTemplate({32 this.$pagelist.append(this.listTemplate({
33 name: page.get('name') || 'newpage',
33 name: page.get('name'),
34 id: page.id34 id: page.id
35 }));35 }));
36 }, this);36 }, this);
42 M.editor.pageview = pageview;42 M.editor.pageview = pageview;
43 },43 },
44 addPage: function() {44 addPage: function() {
45 var newpage = new M.types.model.Page();
45 var newpage = new M.types.model.Page({name: 'newpage'});
46 M.pages.add(newpage);46 M.pages.add(newpage);
47 var newpageview = new PageView({model: newpage});
48 newpageview.render();
49 M.editor.pageview = newpageview;
47 var self = this;
48 M.editor.showOverlay();
49 newpage.save({}, {success: function(model, response) {
50 M.editor.hideOverlay();
51 self.render();
52 var newpageview = new PageView({model: newpage});
53 newpageview.render();
54 M.editor.pageview = newpageview;
55 }});
50 },56 },
51 removePage: function(event) {57 removePage: function(event) {
52 var option = confirm("Are you sure, you want to delete this page?");58 var option = confirm("Are you sure, you want to delete this page?");
214214
215 this.editing = false;215 this.editing = false;
216 this.edit_idx = -1;216 this.edit_idx = -1;
217 //console.log('setting content in page: ', content);
218 this.model.set({'content': content});217 this.model.set({'content': content});
219 this.render();218 this.render();
220 },219 },
246 this.model.set({'showNav': false});246 this.model.set({'showNav': false});
247 }247 }
248248
249 //console.log('mode before save', this.model.toJSON());
250
249 this.model.save({}, {251 this.model.save({}, {
250 success: function(model, response) {252 success: function(model, response) {
251 //console.log('saved', model, response);253 //console.log('saved', model, response);
252 M.editor.hideOverlay();254 M.editor.hideOverlay();
253 model.set(response.page);
254 model.id = response.page.id;
255 //model.set(response.page);
256 //model.id = response.page.id;
257 //console.log(model);
255 M.pagelistview.render();258 M.pagelistview.render();
256 $('#notifications').html(success_template({259 $('#notifications').html(success_template({
257 title: 'Saved',260 title: 'Saved',
503 M.pages = new Pages(M.site_content.content);503 M.pages = new Pages(M.site_content.content);
504 var pagelistview = new PageListView();504 var pagelistview = new PageListView();
505 pagelistview.render();505 pagelistview.render();
506 M.pages.on('add', function(page) {
506 /*M.pages.on('add', function(page) {
507 pagelistview.render();507 pagelistview.render();
508 });
508 });*/
509 M.pagelistview = pagelistview;509 M.pagelistview = pagelistview;
510 },510 },
511 wysiwyg: {511 wysiwyg: {