Sortables are no longer in the view
[lyrix.git] / public / javascripts / application.js
blob43ba0f8d21cbafc8e95ed02a8455cae0dc4c9c06
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({
16 revert : true
17 }, options || {});
18 this.draggable = new Draggable(this.element, this.options);
20 });
22 Lyrix.Droppable = Behavior.create({
23 initialize: function(options) {
24 this.options = (options || {});
25 Droppables.add(this.element, this.options);
27 });
29 Lyrix.Sortable = Behavior.create({
30 initialize: function(options) {
31 this.options = (options || {});
32 Sortable.create(this.element, this.options);
34 });
36 Event.addBehavior({
37 '.song, .usage': Lyrix.Draggable({handle: 'drag_me'}),
38 '#songs_list': function() {
39 Lyrix.Droppable.attach(this, {
40 accept: 'song',
41 onDrop: function(element) {
42 new Ajax.Request('/usages?show_id=' + $P('show_id'), {
43 parameters: 'id=' + encodeURIComponent(element.id.gsub('song_', ''))
44 });
46 });
47 Lyrix.Sortable.attach(this, {
48 constraint: false,
49 handle: 'drag_me',
50 onUpdate: function(element) {
51 new Ajax.Request('/shows/' + $P('show_id') + ';reorder', {
52 method: 'put',
53 parameters: Sortable.serialize(element)
56 });
58 '#side_songs_list': Lyrix.Droppable({
59 accept: 'usage',
60 onDrop: function(element) {
61 id = encodeURIComponent(element.id.gsub('usage_', ''));
62 new Ajax.Request('/usages/' + id, {
63 method: 'delete'
64 });
67 });