Commit ade21b2f3b22bc064bd35421fd6b66fc0d082457

Fix: JS/CSS plugin getting executed when loading up for editing

  - Currently implemented is a hacky workaround around this problem. See
    models.js > Plugin Model > getCode function.
  - Small fix in editor to not take empty strings as valid tags.
  
113113def edit():
114114 if "logged_in" in flask.session:
115115 flask.session['key'] = conf.SECRET_KEY
116 #print getContent()
117116 return flask.render_template('editor.html', content=getContent(),
118117 title=conf.SITE_TITLE)
119118 else:
140140 content = getContent()['content']
141141 return flask.make_response(json.dumps(content), '200 OK',
142142 {'Content-Type': 'application/json'})
143
143144
144145@app.route('/pages/<_id>', methods=['GET'])
145146def listPage(_id):
  
204204 split('-')[1];
205205 var content = this.model.get('content')[idx];
206206 content = new M.types.model[content.type](content);
207 console.log('model inited ', content);
207 //console.log('model inited ', content);
208208 this.editing = true;
209209 this.edit_idx = idx;
210210 var contentview = new ContentView({model: content});
256256 this.render();
257257 return false;
258258 },
259 updatePage: function() {
259 updatePage: function(event) {
260 event.preventDefault();
260261 var name = $('#name').val();
261262 var title = $('#title').val();
262 var children = $('#children').val();
263 children = (children === '') ? [] : children.split(',');
263 var children = [];
264 //var children = $('#children').val();
265 //children = (children === '') ? [] : children.split(',');
264266 this.model.set({'name': name, 'title': title, 'children': children});
265267
266268 if($('#showNav').is(':checked')) {
376376 if(this.model.get('src')) {
377377 var plugin_type = this.model.get('plugin_type');
378378 plugin_type = (plugin_type === 'js') ? 'javascript' : 'css';
379 //console.log('getting code..');
379380 this.model.getCode(function(data) {
381 //console.log('got code..');
380382 $('#plugin-edit').html(escapeHtml(data));
381383 M.editor.code.init('plugin-edit', plugin_type);
382384 });
421421 $('#contentview [m-data-target]').each(function(idx, elem) {
422422 prop = $(elem).attr('m-data-target');
423423 if(prop === 'tags') {
424 val = $(elem).val().split(',');
424 val = ($(elem).val()) ? $(elem).val().split(',') : [];
425425 }
426426 else {
427427 val = $(elem).val();
442442 else if(this.$select.val() === 'plugin') {
443443 var data = M.editor.code.save('plugin-edit');
444444 this.model.saveCode(data, function(resp) {
445 console.log('plugin saved..');
445 //console.log('plugin saved..');
446446 });
447447 }
448448 this.model.set(new_attrs);
449 //console.log('content updated');
449450 M.editor.pageview.updateContent(this.model.toJSON());
450451 },
451452 cleanUp: function() {
467467 var self = this;
468468 M.editor.showOverlay();
469469 var $form = $('#plugin-upload-form')[0];
470 console.log($form);
470 //console.log($form);
471471 var formdata = new FormData($form);
472 console.log(formdata);
472 //console.log(formdata);
473473 $.ajax({
474474 type: 'POST',
475475 url: M.PluginUploadURL(),
480480 self.model.set({'src': response.path})
481481 self.render();
482482 M.editor.hideOverlay();
483 console.log(self.model.toJSON());
483 //console.log(self.model.toJSON());
484484 }
485485 });
486486 }
  
115115 // get the source code of the plugin from the src path
116116 getCode: function(cb) {
117117 var self = this;
118 //NOTE: jQuery executes the code(css or js) as soon as it is returned by
119 //the server. Apparently, there is no way to tell jQuery not to execute
120 //the piece of code retrieved.
121 //Hecnce, right now its a HACK to workaround this problem.
122 // We use dataFilter which is called by jQuery to process the raw xhr
123 // response sent, and jQuery expects back a filtered/sanitized data so
124 // that it can call the success callback with that data. We use
125 // dataFilter to do our processing there, and return an empty string;
126 // this apparently prevents jQuery from executing the code.
127 // TODO: find a better way to workaround this.
128 // TODO: find out how cloud-based IDEs load up code files for editing.
118129 $.ajax({
119130 type: 'GET',
120131 url: self.get('src'),
132 dataFilter: function(data, type) {
133 cb(data);
134 return '';
135 },
121136 cache: false,
122137 success: function(data) {
123 cb(data);
138 //cb(data);
124139 }
125140 });
126141 },