]>
src.bluestatic.org Git - armadillo.git/blob - actor.js
222174f0a26b6edcb0921bbefd7deab4c6b45e96
2 // Armadillo File Manager
3 // Copyright (c) 2010, 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 goog
.provide('armadillo.Actor');
12 goog
.require('armadillo.PathControl');
13 goog
.require('armadillo.TVRenamer');
16 * The Actor is a popup that displays the various actions that can be performed
18 * @param {armadillo.File} file The file to act on.
19 * @param {goog.dom.DomHelper} opt_domHelper
22 armadillo
.Actor = function(file
, opt_domHelper
) {
24 * The file object on which this acts.
25 * @type {armadillo.File}
30 * The UI element used for a specific action.
31 * @type {goog.Disposable}
33 this.actionObject_
= null;
36 * Controls for the current action.
37 * @type {goog.ui.Control}
39 this.controlContainer_
= null;
43 * The different options that the Actor can perform.
45 armadillo
.Actor
.options_
= {
49 TV_RENAME : 'tv-rename',
54 * String values for the options.
56 armadillo
.Actor
.optionStrings_
= {
60 'tv-rename' : 'Rename TV Episode',
61 'download' : 'Download'
64 armadillo
.Actor
.prototype.createDom = function() {
65 this.decorateInternal($.createDom('div'));
70 * Decorates the given element into a path control.
71 * @param {Element} element
73 armadillo
.Actor
.prototype.decorateInternal = function(element
) {
74 this.element_
= element
;
75 this.element_
.addClass('actor');
76 this.element_
.empty();
77 for (var option
in armadillo
.Actor
.options_
) {
78 var tile
= this.createTile_(option
);
80 this.element_
.append(tile
);
83 this.controlContainer_
= $.createDom('div');
84 this.element_
.append(this.controlContainer_
);
88 * Creates the DOM Element that is inserted into the popup.
89 * @param {armadillo.Actor.options_} Key of the option to create
90 * @returns {goog.ui.Control}
92 armadillo
.Actor
.prototype.createTile_ = function(option
) {
93 var value
= armadillo
.Actor
.options_
[option
];
95 // Create the title element.
96 var title
= $.createDom('span').addClass('title');
97 title
.text(armadillo
.Actor
.optionStrings_
[value
]);
99 var tile
= $.createDom('div').addClass('tile');
102 // Cannot open non-directory files.
103 if (value
== armadillo
.Actor
.options_
.OPEN
&& !this.file_
.isDirectory()) {
107 tile
.click(this.tileClickHandler_
.bind(this, value
));
112 * Click handler for individual tiles.
113 * @param {int} option The Actor.option used
116 armadillo
.Actor
.prototype.tileClickHandler_ = function(option
, e
) {
117 this.controlContainer_
.empty();
118 this.controlContainer_
.show();
119 if (option
== armadillo
.Actor
.options_
.OPEN
) {
120 // TODO: assert that this.file_.isDirectory().
121 app
.navigate(this.file_
.getName());
122 } else if (option
== armadillo
.Actor
.options_
.MOVE
) {
124 } else if (option
== armadillo
.Actor
.options_
.DELETE
) {
125 this.performDelete_();
126 } else if (option
== armadillo
.Actor
.options_
.TV_RENAME
) {
127 this.performTVRename_();
128 } else if (option
== armadillo
.Actor
.options_
.DOWNLOAD
) {
129 this.performDownload_();
134 * Subroutine to handle bringing up the move confirmation UI.
137 armadillo
.Actor
.prototype.performMove_ = function() {
138 var editor
= new armadillo
.PathControl(this.file_
.getFullPath(), true);
139 this.controlContainer_
.append(editor
.element_
);
141 var okCallback = function(e
) {
142 var newPath
= editor
.getPath();
143 this.file_
.move(newPath
);
145 this.createOkCancel_(okCallback
.bind(this), null);
149 * Subroutine to handle bringing up the delete confirmation UI.
152 armadillo
.Actor
.prototype.performDelete_ = function() {
153 var content
= $('<span>Are you sure you want to delete:<br/><strong>' +
154 this.file_
.getName() + '</strong></span>');
155 this.controlContainer_
.append(content
);
157 var okCallback = function(e
) {
160 this.createOkCancel_(okCallback
.bind(this), null);
164 * Subroutine that renames a file to it's title based on season and episode.
167 armadillo
.Actor
.prototype.performTVRename_ = function() {
168 var renamer
= new armadillo
.TVRenamer(this.file_
);
173 * Subroutine that streams a file.
176 armadillo
.Actor
.prototype.performDownload_ = function() {
177 window
.location
= '/download?path=' + this.file_
.getFullPath();
181 * Creates two buttons: one for OK one for Cancel and attahes them to the
182 * |controlContainer_|.
183 * @param {function(Event)?} okCallback
184 * @param {function(Event)?} cancelCallback
186 armadillo
.Actor
.prototype.createOkCancel_ = function(okCallback
, cancelCallback
) {
187 var ok
= $.createDom('button').text('OK');
189 ok
.click(okCallback
);
190 var cancel
= $.createDom('button').text('Cancel');
192 cancelCallback
= this.defaultCancelCallback_
.bind(this);
193 cancel
.click(cancelCallback
);
194 this.controlContainer_
.append(ok
);
195 this.controlContainer_
.append(cancel
);
199 * The default cancel callback for the above createOkCancel_().
203 armadillo
.Actor
.prototype.defaultCancelCallback_ = function(e
) {
204 this.controlContainer_
.empty();