Skip to content

Commit

Permalink
added afterSave callback
Browse files Browse the repository at this point in the history
  • Loading branch information
nakajima committed Aug 7, 2008
1 parent ee78a13 commit 85964e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ var Editable = Class.create({
this.element.hide();
this.editForm.show();
this.editInput.activate();
event.stop();
if (event) { event.stop(); }
},

// Event handler that makes request to server, then handles a JSON response.
save: function(event) {
var form = event.element();
var pars = form.serialize();
var url = form.readAttribute('action');
form.disable();
var pars = this.editForm.serialize();
var url = this.editForm.readAttribute('action');
this.editForm.disable();
new Ajax.Request(url, {
method: 'put',
parameters: pars,
Expand All @@ -80,23 +79,24 @@ var Editable = Class.create({
else { this.value = json[this.fieldName]; }
this.editInput.value = this.value;
this.element.update(this.value);
form.enable();
this.editForm.enable();
if (Editable.afterSave) { Editable.afterSave(this); }
this.cancel();
}.bind(this),
onFailure: function(transport) {
this.cancel();
alert("Your change could not be saved.");
}.bind(this)
});
event.stop();
if (event) { event.stop(); }
},

// Event handler that restores original editable value and hides form.
cancel: function(event) {
this.element.show();
this.editInput.value = this.value;
this.editForm.hide();
event.stop();
if (event) { event.stop(); }
},

// Removes editable behavior from an element.
Expand Down
12 changes: 12 additions & 0 deletions test/unit/editable_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ <h1>Better Edit in Place test file</h1>
});
},

testShouldCallAfterSaveCallback: function() {
this.called = false;
Editable.afterSave = function(editable) {
this.called = true;
this.assertEqual(this.list, editable);
}.bind(this);
this.list.save();
this.wait(300, function() {
this.assert(this.called, "didn't call afterSave callback");
});
},

teardown: function() {
this.list.clobber();
this.user.clobber();
Expand Down

0 comments on commit 85964e9

Please sign in to comment.