Created
June 8, 2012 14:32
-
-
Save zenlor/2895919 to your computer and use it in GitHub Desktop.
inplace editing with ender
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Admin.controllers :photos do | |
| post :rename do | |
| if params[:gallery] | |
| Photo.set({:gallery => params[:gallery]}, {:gallery => params[:name], :gallery_slug => params[:name].to_slug}) | |
| {name: params[:name]}.to_json | |
| else | |
| 403 | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $.fn.inEdit = function (target, options) { | |
| var el = $(this); | |
| target = $(target); | |
| el.bind("click", function(e){ | |
| e.preventDefault(); | |
| target.attr('contenteditable', 'true') | |
| .focus() | |
| .bind('keydown', function(e){ | |
| if (e.keyCode != 13) return; | |
| $(this).blur(); | |
| e.preventDefault(); | |
| target.attr('contenteditable', false); | |
| var data = options.data || {}; | |
| data[options.name || 'name'] = target.text(); | |
| $.ajax({ | |
| url: options.url | |
| , method: options.method | |
| , type: 'json' | |
| , data: data | |
| , success: options.success || function(){} | |
| , error: options.error || function(e) {console.log(e)} | |
| }); | |
| }); | |
| // window.getSelection().setPosition(0); | |
| }); | |
| } | |
| $.domReady(function(){ | |
| $('a.edit.sym').each(function(el){ | |
| var el = $(el) | |
| , target = el.parent().find('span'); | |
| el.inEdit( | |
| target | |
| , { | |
| url:'/photos/rename' | |
| , name: 'name' | |
| , data: {gallery: target.text()} | |
| , method:'post' | |
| , success: function () { ui.notify('Photo', 'galleria rinominata').effect('slide'); } | |
| , error: function () { ui.error('Photo', 'galleria rinominata').effect('slide'); } | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment