This commit is contained in:
did 2012-05-24 06:46:48 -07:00
parent 04d9fe17f8
commit d3e219018b
3 changed files with 19 additions and 7 deletions

View File

@ -50,11 +50,13 @@ class Locomotive.Views.ContentEntries.FormView extends Locomotive.Views.Shared.F
settings = _.extend {}, @tinyMCE_settings(),
oninit: ((editor) =>
$.cmd 'S', (() =>
$(textarea).val(editor.getBody().innerHTML).trigger('change')
editor.save()
$(textarea).trigger('changeSilently')
@$('form').trigger('submit')
), [], ignoreCase: true, document: editor.dom.doc),
onchange_callback: (editor) =>
$(textarea).val(editor.getBody().innerHTML).trigger('change')
editor.save()
$(textarea).trigger('changeSilently')
$(textarea).tinymce(settings)

View File

@ -36,7 +36,8 @@ class Locomotive.Views.Shared.FormView extends Backbone.View
previous_attributes = _.clone @model.attributes
@model.save {},
headers: options.headers
headers: options.headers
silent: true # since we pass an empty hash above, no need to trigger the callbacks
success: (model, response, xhr) =>
form.trigger('ajax:complete')

View File

@ -64,10 +64,13 @@ Backbone.ModelBinding = (function(Backbone, _, $){
this.modelBindings.push({model: model, eventName: eventName, callback: callback});
}
this.registerElementBinding = function(element, callback){
this.registerElementBinding = function(element, callback, callbackSilently){
// bind the form changes to the model
element.bind("change", callback);
this.elementBindings.push({element: element, eventName: "change", callback: callback});
if (callbackSilently)
element.bind("changeSilently", callbackSilently)
}
}
@ -188,18 +191,24 @@ Backbone.ModelBinding = (function(Backbone, _, $){
element.val(val);
};
var setModelValue = function(attr_name, value){
var setModelValue = function(attr_name, value, silent){
if (typeof(silent) === 'undefined' || silent == null) silent = false
var data = {};
data[attr_name] = value;
model.set(data);
model.set(data, { 'silent': silent });
};
var elementChange = function(ev){
setModelValue(attribute_name, view.$(ev.target).val());
};
// FIXME (Did): simple solution to update the model without triggering related callbacks (solving a bug with tinymce)
var elementChangeSilently = function(ev) {
setModelValue(attribute_name, view.$(ev.target).val(), true);
}
modelBinder.registerModelBinding(model, attribute_name, modelChange);
modelBinder.registerElementBinding(element, elementChange);
modelBinder.registerElementBinding(element, elementChange, elementChangeSilently);
// set the default value on the form, from the model
var attr_value = model.get(attribute_name);