2 // Armadillo File Manager
3 // Copyright (c) 2010-2011, Robert Sesek <http://www.bluestatic.org>
5 // This program is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free Software
7 // Foundation, either version 3 of the License, or any later version.
10 $.namespace('armadillo.Actor');
13 * The Actor is a popup that displays the various actions that can be performed
15 * @param {armadillo.File} file The file to act on.
18 armadillo
.Actor
= function(file
) {
20 * The file object on which this acts.
21 * @type {armadillo.File}
26 * The root DOM element for the actor.
32 * Controls for the current action.
35 this.controlContainer_
= null;
39 * Gets the root of the Actor.
42 armadillo
.Actor
.prototype.getElement
= function() {
47 * The different options that the Actor can perform.
49 armadillo
.Actor
.options_
= {
53 TV_RENAME
: 'tv-rename',
58 * String values for the options.
60 armadillo
.Actor
.optionStrings_
= {
64 'tv-rename' : 'Rename TV Episode',
65 'download' : 'Download'
69 * Creates and sets the elemnt this object represents.
72 armadillo
.Actor
.prototype.createDom
= function() {
73 this.element_
= $.createDom('div').addClass('actor').empty();
74 for (var option
in armadillo
.Actor
.options_
) {
75 var tile
= this.createTile_(option
);
77 this.element_
.append(tile
);
82 this.controlContainer_
= $.createDom('div');
83 this.element_
.append(this.controlContainer_
);
89 * Creates the DOM Element that is inserted into the popup.
90 * @param {armadillo.Actor.options_} Key of the option to create
93 armadillo
.Actor
.prototype.createTile_
= function(option
) {
94 var value
= armadillo
.Actor
.options_
[option];
96 // Create the title element.
97 var title
= $.createDom('span').addClass('title');
98 title
.text(armadillo
.Actor
.optionStrings_
[value]);
100 var tile
= $.createDom('div').addClass('tile');
103 // Cannot open non-directory files.
104 if (value
== armadillo
.Actor
.options_
.OPEN
&& !this.file_
.isDirectory()) {
108 tile
.click(this.tileClickHandler_
.bind(this, value
));
113 * Click handler for individual tiles.
114 * @param {int} option The Actor.option used
117 armadillo
.Actor
.prototype.tileClickHandler_
= function(option
, e
) {
118 this.controlContainer_
.empty();
119 this.controlContainer_
.show();
120 if (option
== armadillo
.Actor
.options_
.OPEN
) {
121 // TODO: assert that this.file_.isDirectory().
122 app
.navigate(this.file_
.getName());
123 } else if (option
== armadillo
.Actor
.options_
.MOVE
) {
125 } else if (option
== armadillo
.Actor
.options_
.DELETE
) {
126 this.performDelete_();
127 } else if (option
== armadillo
.Actor
.options_
.TV_RENAME
) {
128 this.performTVRename_();
129 } else if (option
== armadillo
.Actor
.options_
.DOWNLOAD
) {
130 this.performDownload_();
135 * Subroutine to handle bringing up the move confirmation UI.
138 armadillo
.Actor
.prototype.performMove_
= function() {
139 var editor
= new armadillo
.PathControl(this.file_
.getFullPath(), true);
140 this.controlContainer_
.append(editor
.createDom());
142 var okCallback
= function(e
) {
143 var newPath
= editor
.getPath();
144 this.file_
.move(newPath
);
146 this.createOkCancel_(okCallback
.bind(this), null);
150 * Subroutine to handle bringing up the delete confirmation UI.
153 armadillo
.Actor
.prototype.performDelete_
= function() {
154 var content
= $('<div>Are you sure you want to delete:<br/><strong>' +
155 this.file_
.getName() + '</strong></div>');
156 this.controlContainer_
.append(content
);
158 var okCallback
= function(e
) {
161 this.createOkCancel_(okCallback
.bind(this), null);
165 * Subroutine that renames a file to it's title based on season and episode.
168 armadillo
.Actor
.prototype.performTVRename_
= function() {
169 var renamer
= new armadillo
.TVRenamer(this.file_
);
174 * Subroutine that streams a file.
177 armadillo
.Actor
.prototype.performDownload_
= function() {
178 window
.location
= 'download?path=' + this.file_
.getFullPath();
182 * Creates two buttons: one for OK one for Cancel and attahes them to the
183 * |controlContainer_|.
184 * @param {function(Event)?} okCallback
185 * @param {function(Event)?} cancelCallback
187 armadillo
.Actor
.prototype.createOkCancel_
= function(okCallback
, cancelCallback
) {
188 var ok
= $.createDom('button').text('OK');
190 ok
.click(okCallback
);
191 var cancel
= $.createDom('button').text('Cancel');
193 cancelCallback
= this.defaultCancelCallback_
.bind(this);
194 cancel
.click(cancelCallback
);
195 this.controlContainer_
.append(ok
);
196 this.controlContainer_
.append(cancel
);
200 * The default cancel callback for the above createOkCancel_().
204 armadillo
.Actor
.prototype.defaultCancelCallback_
= function(e
) {
205 this.controlContainer_
.empty();