From 063b6602dc8e49a0e2e05826dd1e2c0a5c09b92e Mon Sep 17 00:00:00 2001 From: Anon Ray Date: Mon, 7 Oct 2013 16:02:02 +0530 Subject: [PATCH] Fix map plugin save throwing error Map plugin was throwing error while saving, this was because it was assumed that all types would have atleast an attribute called data. Fix that. --- mouchak/static/js/editor.js | 28 +++++++++++++++++++--------- mouchak/static/js/models.js | 6 ++++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/mouchak/static/js/editor.js b/mouchak/static/js/editor.js index 4e74771..51ee991 100644 --- a/mouchak/static/js/editor.js +++ b/mouchak/static/js/editor.js @@ -162,12 +162,20 @@ }, listContent: function() { var content = ''; + var base_props = _.keys(new M.types.model.base().defaults); _.each(this.model.get('content'), function(element, idx) { + //prepare the more field + var moar = ''; + _.each(element, function(v, k) { + //check if not one of the base properties..add it to more.. + if(_.indexOf(base_props, k) < 0) { + moar += (v) ? v + ', ' : ''; + } + }); content += this.contentListTemplate({ no: idx, type: element.type, - more: element.src || - escapeHtml(element.data.substring(0, 30) + '..'), + more: escapeHtml(moar.substring(0, 30) + '..'), title: (element.title) ? element.title + ',' : '' }); }, this); @@ -386,13 +394,15 @@ new_attrs[prop] = val; }); new_attrs['type'] = this.$select.val(); - if(this.wysiwyg) { - var data = M.editor.wysiwyg.save('#edit'); - new_attrs['data'] = data; - } - else { - var data = M.editor.code.save('code-edit'); - new_attrs['data'] = data; + if(this.$select.val() === 'text') { + if(this.wysiwyg) { + var data = M.editor.wysiwyg.save('#edit'); + new_attrs['data'] = data; + } + else { + var data = M.editor.code.save('code-edit'); + new_attrs['data'] = data; + } } this.model.set(new_attrs); M.editor.pageview.updateContent(this.model.toJSON()); diff --git a/mouchak/static/js/models.js b/mouchak/static/js/models.js index 36dae73..c277bc0 100644 --- a/mouchak/static/js/models.js +++ b/mouchak/static/js/models.js @@ -4,7 +4,8 @@ defaults: { tags: [], title: "", - attr: {} + attr: {}, + type: '' }, initialize: function() { } @@ -61,7 +62,7 @@ // Map model var Map = BaseType.extend({ defaults: _.extend({ - tileLayer:"", + tileLayer: "", shp: "" }, BaseType.prototype.defaults), initialize: function(){ @@ -138,6 +139,7 @@ //export types to the typemap M.types = M.types || {}; M.types.model = { + 'base': BaseType, 'text': Text, 'image': Image, 'video': Video, -- 1.7.10.4