1 // Place your application-specific JavaScript functions and classes here
2 // This file is automatically included by javascript_include_tag :defaults
4 Lyrix
= {}; // Our own little namespace.
6 // We can pass values from the server this way
7 // I like this syntax better
8 $P = function(element
) {
9 return $(element
).innerHTML
;
12 // Just a behaviors extraction of Script.aculo.us Draggable
13 Lyrix
.Draggable
= Behavior
.create({
14 initialize: function(options
) {
15 this.options
= Object
.extend({
18 this.draggable
= new Draggable(this.element
, this.options
);
22 Lyrix
.Droppable
= Behavior
.create({
23 initialize: function(options
) {
24 this.options
= (options
|| {});
25 Droppables
.add(this.element
, this.options
);
29 Lyrix
.Sortable
= Behavior
.create({
30 initialize: function(options
) {
31 this.options
= (options
|| {});
32 Sortable
.create(this.element
, this.options
);
37 '.song, .usage': Lyrix
.Draggable({handle
: 'drag_me'}),
38 '#songs_list': function() {
39 Lyrix
.Droppable
.attach(this, {
41 onDrop: function(element
) {
42 new Ajax
.Request('/usages?show_id=' + $P('show_id'), {
43 parameters
: 'id=' + encodeURIComponent(element
.id
.gsub('song_', ''))
47 Lyrix
.Sortable
.attach(this, {
50 onUpdate: function(element
) {
51 new Ajax
.Request('/shows/' + $P('show_id') + ';reorder', {
53 parameters
: Sortable
.serialize(element
)
58 '#side_songs_list': Lyrix
.Droppable({
60 onDrop: function(element
) {
61 id
= encodeURIComponent(element
.id
.gsub('usage_', ''));
62 new Ajax
.Request('/usages/' + id
, {