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.
  
7171 del(newpage['_id'])
7272 print newpage
7373 # 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
7778@app.route('/page/<_id>', methods=['PUT', 'DELETE'])
8686 print res
8787 if res['err'] == None:
8888 print changedPage
89 return flask.jsonify(status='ok', page=changedPage)
89 #return flask.jsonify(status='ok', page=changedPage)
90 return flask.jsonify(changedPage)
9091
9192 elif flask.request.method == 'DELETE':
9293 delPage = flask.request.url
119119 print changedMenu
120120 res = siteMenu.update({'_id': bson.ObjId(_id)}, changedMenu)
121121 print res
122 return flask.jsonify(status='ok', menu=changedMenu)
122 #return flask.jsonify(status='ok', menu=changedMenu)
123 return flask.jsonify(changedMenu)
123124
124125 #elif flask.request.method == 'DELETE':
125126 # delMenu = flask.request.url
  
3030 this.$pagelist.html('');
3131 _.each(M.pages.models, function(page) {
3232 this.$pagelist.append(this.listTemplate({
33 name: page.get('name') || 'newpage',
33 name: page.get('name'),
3434 id: page.id
3535 }));
3636 }, this);
4242 M.editor.pageview = pageview;
4343 },
4444 addPage: function() {
45 var newpage = new M.types.model.Page();
45 var newpage = new M.types.model.Page({name: 'newpage'});
4646 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 }});
5056 },
5157 removePage: function(event) {
5258 var option = confirm("Are you sure, you want to delete this page?");
214214
215215 this.editing = false;
216216 this.edit_idx = -1;
217 //console.log('setting content in page: ', content);
218217 this.model.set({'content': content});
219218 this.render();
220219 },
246246 this.model.set({'showNav': false});
247247 }
248248
249 //console.log('mode before save', this.model.toJSON());
250
249251 this.model.save({}, {
250252 success: function(model, response) {
251253 //console.log('saved', model, response);
252254 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);
255258 M.pagelistview.render();
256259 $('#notifications').html(success_template({
257260 title: 'Saved',
503503 M.pages = new Pages(M.site_content.content);
504504 var pagelistview = new PageListView();
505505 pagelistview.render();
506 M.pages.on('add', function(page) {
506 /*M.pages.on('add', function(page) {
507507 pagelistview.render();
508 });
508 });*/
509509 M.pagelistview = pagelistview;
510510 },
511511 wysiwyg: {