From 2f8fc9b6fbcf1c842bb6024700ab6c0ab4c0ef47 Mon Sep 17 00:00:00 2001 From: Matt Moriarity Date: Sat, 28 Jul 2007 16:00:11 -0400 Subject: [PATCH] Removed delete links from the view Now just give a link the 'deletable' class and it will submit using the DELETE method. --- app/views/shows/edit.haml | 2 +- app/views/songs/edit.haml | 2 +- public/javascripts/application.js | 32 ++++++++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/app/views/shows/edit.haml b/app/views/shows/edit.haml index f26164d..748dae4 100644 --- a/app/views/shows/edit.haml +++ b/app/views/shows/edit.haml @@ -1,6 +1,6 @@ %p = link_to image_tag('film_go.png', :border => 0) + ' view this show', show_path(@show), :class => 'no_underline' - = link_to image_tag('film_delete.png', :border => 0) + ' delete this show', show_path(@show), :method => 'delete', :class => 'no_underline' + = link_to image_tag('film_delete.png', :border => 0) + ' delete this show', show_path(@show), :class => 'deletable no_underline' %span#show_id= @show.id diff --git a/app/views/songs/edit.haml b/app/views/songs/edit.haml index c1e34b1..5cb3df4 100644 --- a/app/views/songs/edit.haml +++ b/app/views/songs/edit.haml @@ -1,6 +1,6 @@ %p = link_to image_tag('cd_go.png', :border => 0) + ' view this song', song_path(@song), :class => 'no_underline' - = link_to image_tag('cd_delete.png', :border => 0) + ' delete this song', song_path(@song), :method => 'delete', :class => 'no_underline' + = link_to image_tag('cd_delete.png', :border => 0) + ' delete this song', song_path(@song), :class => 'deletable no_underline' %h1= in_place_editor_field :song, :title, {}, :options => '{method: "put"}' %h2 diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 43ba0f8..3be0bec 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -1,6 +1,3 @@ -// Place your application-specific JavaScript functions and classes here -// This file is automatically included by javascript_include_tag :defaults - Lyrix = {}; // Our own little namespace. // We can pass values from the server this way @@ -9,7 +6,9 @@ $P = function(element) { return $(element).innerHTML; } -// Just a behaviors extraction of Script.aculo.us Draggable +// =============================================== +// = Behavior proxies to Script.aculo.us objects = +// =============================================== Lyrix.Draggable = Behavior.create({ initialize: function(options) { this.options = Object.extend({ @@ -33,7 +32,32 @@ Lyrix.Sortable = Behavior.create({ } }); +// ==================== +// = Custom behaviors = +// ==================== +Lyrix.DeleteLink = Behavior.create({ + initialize: function() { + this.form = $form({ + style: 'display:none', + method: 'post', + action: this.element.href + }, $input({ + type: 'hidden', + name: '_method', + value: 'delete' + })); + }, + onclick: function(e) { + this.form.submit(); + Event.stop(e); + } +}); + +// ================================= +// = Behaviors for the application = +// ================================= Event.addBehavior({ + 'a.deletable': Lyrix.DeleteLink, '.song, .usage': Lyrix.Draggable({handle: 'drag_me'}), '#songs_list': function() { Lyrix.Droppable.attach(this, { -- 2.11.4.GIT