Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed mootols and prototype version and updated readme

  • Loading branch information...
commit 6a3aaa57265f8efb17ba8d63264cbc80bfcb6763 1 parent ce78bdd
@janv authored
View
17 README.markdown
@@ -19,6 +19,9 @@ The editor works by PUTting the updated value to the server and GETting the
updated record afterwards to display the updated value.
That way any authentication methods or otherwise funky workflows in your
controllers are used for the inplace-editors requests.
+To save the additional GET request, you can take the shortcut of returning the
+updated record in the response to the PUT request. See the testapp for an
+example.
URL: <http://github.com/janv/rest_in_place/>
REPOSITORY: git://github.com/janv/rest_in_place.git
@@ -119,8 +122,6 @@ follows:
To write your own form types, just extend the `RestInPlace.forms` object
and select your new form type throught the `data-formtype` attribute.
-
- **This feature is only supported in the jQuery version.**
Example
=======
@@ -145,7 +146,7 @@ Your app/controllers/users_controller.rb:
if @user.update_attributes!(params[:user])
respond_to do |format|
format.html { redirect_to( @person ) }
- format.json { render :nothing => true }
+ format.json { render :json => @user }
end
else
respond_to do |format|
@@ -211,12 +212,6 @@ bug in the tracker at github: <http://github.com/janv/rest_in_place/issues>
For general comments and questions, please use the comment function on my blog:
<http://jan.varwig.org/projects/rest-in-place>
-Acknowledgements
-================
-
-Thanks to Kevin Valdek for the mootools version (commit 086b409d38932426540f402bb642c66165c78976)
-and improvements to the testapp (commit 8eb121271345943588fe2a8467c790e7e37f3d7a).
-
-Thanks to nando for commit 17ca4e3060a1420bf13d9b9d89ceeba2bcc144d2
-Copyright (c) 2010 [Jan Varwig], released under the MIT license
+---
+Copyright (c) 2010 [Jan Varwig], released under the MIT license
View
68 javascripts/mootools.rest_in_place.js
@@ -1,68 +0,0 @@
-var RestInPlace = new Class({
-
- Binds: ['onClick', 'onSubmit'], // uses Bind Mutator (http://www.clientcide.com/code-releases/classbinds-for-mootols-is-back/)
-
- initialize: function(element) {
- this.element = $(element);
- this.elements = [this.element].extend(this.element.getParents()); // element with parents
- this.element.addEvent('click', this.onClick);
- },
-
- onClick: function() {
- this.element.removeEvent('click', this.onClick)
- var value = this.element.get('text');
-
- var form = new Element('form', { styles: { display: 'inline' } });
- var input = new Element('input', {
- type: 'text',
- value: value,
- events: {
- blur: function() {
- this.element.set('html', value);
- this.element.addEvent('click', this.onClick);
- }.bind(this)
- }
- });
- this.element.empty().grab(form.grab(input));
- input.focus()
- form.addEvent('submit', this.onSubmit);
- },
-
- onSubmit: function(e) {
- e.preventDefault();
- var value = this.element.getElement('input').get('value');
- this.element.set('html', 'saving...')
-
- var object = this.getOption('data-object') || this.getObjectFromId();
- var attribute = this.getOption('data-attribute');
- var url = this.getOption('data-url') || document.location.pathname;
- new Request.HTML({
- url: url,
- method: 'put',
- onSuccess: function() {
- new Request.JSON({
- url: url,
- method: 'get',
- onSuccess: function(json) {
- this.element.set('html', json[object][attribute]);
- this.element.addEvent('click', this.onClick);
- }.bind(this)
- }).setHeader('Accept', 'application/json').send();
- }.bind(this)
- }).send(object + '[' + attribute +']=' + encodeURIComponent(value) + (window.rails_authenticity_token ? "&authenticity_token="+encodeURIComponent(window.rails_authenticity_token) : ''));
- },
-
- getOption: function(name) {
- for( var i = 0; i < this.elements.length; i++ ) if( property = this.elements[i].getProperty(name) ) return property;
- },
-
- getObjectFromId: function() {
- var parents = this.element.getParents();
- for( var i = 0; i < parents.length; i++ ) if(match = parents[i].id.match(/^(\w+)_(\d+)$/i)) return match[1];
- }
-
-});
-
-window.addEvent('domready', function() {
- $$('.rest_in_place').each(function(field) { new RestInPlace(field); });
-});
View
57 javascripts/rest_in_place.js
@@ -1,57 +0,0 @@
-rest_in_place = function(element, url, objectName, attributeName){
- var e = element;
-
- function clickFunction(){
- var oldValue = e.innerHTML;
- function submitFunction(){
- var value = Form.Element.getValue(e.select('input')[0]);
- e.innerHTML = "saving...";
- new Ajax.Request(url,{
- method: 'put',
- parameters: objectName+'['+attributeName+']='+encodeURIComponent(value)+(window.rails_authenticity_token ? "&authenticity_token="+encodeURIComponent(window.rails_authenticity_token) : ''),
- onSuccess: function(transport){
- new Ajax.Request(url, {
- method: 'get',
- requestHeaders: { "Accept" : "application/json"},
- onSuccess : function(xhr){
- var data = xhr.responseText.evalJSON();
- e.innerHTML = data[objectName][attributeName];
- Event.observe(e,'click', clickFunction);
- }
- });
- }
- });
- return false;
- }
- e.innerHTML = '<form action="javascript:void(0)" style="display:inline;"><input type="text" value="' + oldValue + '"></form>';
- Form.Element.select(e.select('input')[0]);
- Event.stopObserving(e, 'click', clickFunction);
- Event.observe(e.select('input')[0], 'blur', function(){
- e.innerHTML = oldValue;
- Event.observe(e, 'click', clickFunction);
- });
- Event.observe(e.select('form')[0], 'submit', submitFunction)
- }
-
- Event.observe(e,'click', clickFunction)
-}
-
-Event.observe(window, 'load',function() {
- $$(".rest_in_place").each(function(e){
- var url; var obj; var attrib;
- Element.ancestors(e).each(function(a){
- url = url || Element.readAttribute(a, 'data-url');
- obj = obj || Element.readAttribute(a, 'data-object');
- attrib = attrib || Element.readAttribute(a, 'data-attribute');
- });
- Element.ancestors(e).each(function(a){
- if (res = a.id.match(/^(\w+)_(\d+)$/i)) {
- obj = obj || res[1];
- }
- });
- url = Element.readAttribute(e, 'data-url') || url || document.location.pathname;
- obj = Element.readAttribute(e, 'data-object') || obj;
- attrib = Element.readAttribute(e, 'data-attribute') || attrib;
- rest_in_place(e, url, obj, attrib);
- });
-});

0 comments on commit 6a3aaa5

Please sign in to comment.
Something went wrong with that request. Please try again.