From 24cd97ed92bbb6fc321663ad68a08ded9a88f082 Mon Sep 17 00:00:00 2001 From: Anon Ray Date: Sun, 6 Oct 2013 18:21:07 +0530 Subject: [PATCH] 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. --- mouchak/server.py | 9 ++++++--- mouchak/static/js/editor.js | 28 ++++++++++++++++++---------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/mouchak/server.py b/mouchak/server.py index 5c2bc7a..dc19d1f 100644 --- a/mouchak/server.py +++ b/mouchak/server.py @@ -71,7 +71,8 @@ def insertPage(): del(newpage['_id']) print newpage # FIXME: handle errors - return flask.jsonify(status='ok', page=newpage) + #return flask.jsonify(status='ok', page=newpage) + return flask.jsonify(newpage) @app.route('/page/<_id>', methods=['PUT', 'DELETE']) @@ -85,7 +86,8 @@ def updatePage(_id): print res if res['err'] == None: print changedPage - return flask.jsonify(status='ok', page=changedPage) + #return flask.jsonify(status='ok', page=changedPage) + return flask.jsonify(changedPage) elif flask.request.method == 'DELETE': delPage = flask.request.url @@ -117,7 +119,8 @@ def updateMenu(_id): print changedMenu res = siteMenu.update({'_id': bson.ObjId(_id)}, changedMenu) print res - return flask.jsonify(status='ok', menu=changedMenu) + #return flask.jsonify(status='ok', menu=changedMenu) + return flask.jsonify(changedMenu) #elif flask.request.method == 'DELETE': # delMenu = flask.request.url diff --git a/mouchak/static/js/editor.js b/mouchak/static/js/editor.js index f380694..030da12 100644 --- a/mouchak/static/js/editor.js +++ b/mouchak/static/js/editor.js @@ -30,7 +30,7 @@ this.$pagelist.html(''); _.each(M.pages.models, function(page) { this.$pagelist.append(this.listTemplate({ - name: page.get('name') || 'newpage', + name: page.get('name'), id: page.id })); }, this); @@ -42,11 +42,17 @@ M.editor.pageview = pageview; }, addPage: function() { - var newpage = new M.types.model.Page(); + var newpage = new M.types.model.Page({name: 'newpage'}); M.pages.add(newpage); - var newpageview = new PageView({model: newpage}); - newpageview.render(); - M.editor.pageview = newpageview; + var self = this; + M.editor.showOverlay(); + newpage.save({}, {success: function(model, response) { + M.editor.hideOverlay(); + self.render(); + var newpageview = new PageView({model: newpage}); + newpageview.render(); + M.editor.pageview = newpageview; + }}); }, removePage: function(event) { var option = confirm("Are you sure, you want to delete this page?"); @@ -208,7 +214,6 @@ this.editing = false; this.edit_idx = -1; - //console.log('setting content in page: ', content); this.model.set({'content': content}); this.render(); }, @@ -241,12 +246,15 @@ this.model.set({'showNav': false}); } + //console.log('mode before save', this.model.toJSON()); + this.model.save({}, { success: function(model, response) { //console.log('saved', model, response); M.editor.hideOverlay(); - model.set(response.page); - model.id = response.page.id; + //model.set(response.page); + //model.id = response.page.id; + //console.log(model); M.pagelistview.render(); $('#notifications').html(success_template({ title: 'Saved', @@ -495,9 +503,9 @@ M.pages = new Pages(M.site_content.content); var pagelistview = new PageListView(); pagelistview.render(); - M.pages.on('add', function(page) { + /*M.pages.on('add', function(page) { pagelistview.render(); - }); + });*/ M.pagelistview = pagelistview; }, wysiwyg: { -- 1.7.10.4