diff options
author | mr <mr@mrautenberg.de> | 2011-01-31 11:45:53 +0100 |
---|---|---|
committer | mr <mr@mrautenberg.de> | 2011-01-31 11:45:53 +0100 |
commit | a64ce9f2e9c13b8f644bd75800ee6b1cd9942066 (patch) | |
tree | ccaffc933e870368b04083970d38eabc64548789 /public | |
parent | 3203db9d2b47d0ac86c74829193f6e53e5eb76a8 (diff) |
edit model name
Diffstat (limited to 'public')
-rwxr-xr-x | public/javascripts/toxcreate.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/public/javascripts/toxcreate.js b/public/javascripts/toxcreate.js index aef0455..493168f 100755 --- a/public/javascripts/toxcreate.js +++ b/public/javascripts/toxcreate.js @@ -95,6 +95,63 @@ $(function() { } }); +jQuery.fn.editModel = function(type, options) { + var defaults = { + method: 'get', + action: this.attr('href'), + trigger_on: 'click' + }; + var opts = $.extend(defaults, options); + this.bind(opts.trigger_on, function() { + $.ajax({ + type: opts.method, + url: opts.action, + dataType: 'html', + data: { + '_method': 'get' + }, + success: function(data) { + $("div#model_" + opts.id + "_name").html(data); + $("input#model_" + opts.id + "_name").focus(); + }, + error: function(data) { + alert("model edit error!"); + } + }); + return false; + }); +}; + +jQuery.fn.saveModel = function(type, options) { + var defaults = { + method: 'put', + action: 'model/' + options.id, + trigger_on: 'click' + }; + var opts = $.extend(defaults, options); + + this.bind(opts.trigger_on, function() { + var name = $("input#model_" + opts.id + "_name").val(); + $.ajax({ + type: opts.method, + url: opts.action, + dataType: 'html', + data: { + '_method': 'put', + 'name': name + }, + success: function(data) { + $("div#model_" + opts.id + "_name").html(data); + }, + error: function(data) { + alert("model save error!"); + } + }); + return false; + }); +}; + + jQuery.fn.deleteModel = function(type, options) { var defaults = { method: 'post', |