]>
src.bluestatic.org Git - armadillo.git/blob - web_frontend/actor.js
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');
11 goog
.provide('armadillo.Actor.TileControlRenderer_');
13 goog
.require('armadillo.PathControl');
14 goog
.require('armadillo.TVRenamer');
15 goog
.require('goog.array');
16 goog
.require('goog.dom');
17 goog
.require('goog.events');
18 goog
.require('goog.events.EventHandler');
19 goog
.require('goog.style');
20 goog
.require('goog.ui.Button');
21 goog
.require('goog.ui.Container');
24 * The Actor is a popup that displays the various actions that can be performed
26 * @param {armadillo.File} file The file to act on.
27 * @param {goog.dom.DomHelper} opt_domHelper
30 armadillo
.Actor = function(file
, opt_domHelper
) {
31 goog
.ui
.Container
.call(this, null, null, opt_domHelper
);
33 this.setFocusable(false);
34 this.setFocusableChildrenAllowed(true);
37 * The file object on which this acts.
38 * @type {armadillo.File}
43 * Registrar for all the Actor's events.
44 * @type {goog.events.EventHandler}
46 this.eh_
= new goog
.events
.EventHandler();
49 * The UI element used for a specific action.
50 * @type {goog.Disposable}
52 this.actionObject_
= null;
55 * Controls for the current action.
56 * @type {goog.ui.Control}
58 this.controlContainer_
= null;
60 goog
.inherits(armadillo
.Actor
, goog
.ui
.Container
);
63 * The different options that the Actor can perform.
65 armadillo
.Actor
.options_
= {
69 TV_RENAME : 'tv-rename'
73 * String values for the options.
75 armadillo
.Actor
.optionStrings_
= {
79 'tv-rename' : 'Rename TV Episode'
86 armadillo
.Actor
.prototype.disposeInternal = function() {
87 armadillo
.Actor
.superClass_
.disposeInternal
.call(this);
91 if (this.controlContainer_
)
92 this.controlContainer_
.dispose();
93 this.controlContainer_
= null;
95 // Remove the actor display element.
96 goog
.dom
.removeNode(this.element_
);
99 if (this.actionObject_
) {
100 this.actionObject_
.dispose();
101 this.actionObject_
= null;
107 armadillo
.Actor
.prototype.createDom = function() {
108 this.setElementInternal(this.dom_
.createDom('div'));
109 this.decorate(this.getElement());
113 * Decorates the given element into a path control.
114 * @param {Element} element
116 armadillo
.Actor
.prototype.decorateInternal = function(element
) {
117 this.element_
= element
;
118 goog
.dom
.classes
.add(this.element_
, 'actor');
119 this.dom_
.removeChildren(this.element_
);
120 for (var option
in armadillo
.Actor
.options_
) {
121 var tile
= this.createTile_(option
);
123 this.addChild(tile
, true);
126 this.controlContainer_
= new goog
.ui
.Control();
127 this.controlContainer_
.setSupportedState(goog
.ui
.Component
.State
.FOCUSED
, false);
128 this.addChild(this.controlContainer_
, true);
132 * Creates the DOM Element that is inserted into the popup.
133 * @param {armadillo.Actor.options_} Key of the option to create
134 * @returns {goog.ui.Control}
136 armadillo
.Actor
.prototype.createTile_ = function(option
) {
137 var value
= armadillo
.Actor
.options_
[option
];
139 // Create the title element.
140 var title
= this.dom_
.createDom('span', 'title',
141 armadillo
.Actor
.optionStrings_
[value
]);
143 var tile
= new goog
.ui
.Control(title
, new armadillo
.Actor
.TileControlRenderer_());
144 tile
.actorOption
= value
;
146 // Cannot open non-directory files.
147 if (value
== armadillo
.Actor
.options_
.OPEN
&& !this.file_
.isDirectory()) {
151 this.eh_
.listen(tile
, goog
.ui
.Component
.EventType
.ACTION
,
152 this.tileClickHandler_
, false, this);
157 * Click handler for individual tiles.
160 armadillo
.Actor
.prototype.tileClickHandler_ = function(e
) {
161 var option
= e
.target
.actorOption
;
162 this.controlContainer_
.removeChildren(true);
163 this.controlContainer_
.setVisible(true);
164 if (option
== armadillo
.Actor
.options_
.OPEN
) {
165 // TODO: assert that this.file_.isDirectory().
166 app
.navigate(this.file_
.getName());
167 } else if (option
== armadillo
.Actor
.options_
.MOVE
) {
169 } else if (option
== armadillo
.Actor
.options_
.DELETE
) {
170 this.performDelete_();
171 } else if (option
== armadillo
.Actor
.options_
.TV_RENAME
) {
172 this.performTVRename_();
177 * Subroutine to handle bringing up the move confirmation UI.
180 armadillo
.Actor
.prototype.performMove_ = function() {
181 var editor
= new armadillo
.PathControl(this.file_
.getFullPath(), true);
182 this.controlContainer_
.addChild(editor
, true);
184 var okCallback = function(e
) {
185 var newPath
= editor
.getPath();
186 this.file_
.move(newPath
);
188 this.createOkCancel_(goog
.bind(okCallback
, this), null);
192 * Subroutine to handle bringing up the delete confirmation UI.
195 armadillo
.Actor
.prototype.performDelete_ = function() {
196 var content
= goog
.dom
.createDom('span', null,
197 'Are you sure you want to delete:',
198 goog
.dom
.createElement('br'),
199 goog
.dom
.createDom('strong', null, this.file_
.getName()));
200 this.controlContainer_
.addChild(new goog
.ui
.Control(content
), true);
202 var okCallback = function(e
) {
205 this.createOkCancel_(goog
.bind(okCallback
, this), null);
209 * Subroutine that renames a file to it's title based on season and episode.
212 armadillo
.Actor
.prototype.performTVRename_ = function() {
213 var renamer
= new armadillo
.TVRenamer(this.file_
);
218 * Creates two buttons: one for OK one for Cancel and attahes them to the
219 * |controlContainer_|.
220 * @param {function(Event)?} okCallback
221 * @param {function(Event)?} cancelCallback
223 armadillo
.Actor
.prototype.createOkCancel_ = function(okCallback
, cancelCallback
) {
224 var ok
= new goog
.ui
.Button('OK');
226 this.eh_
.listen(ok
, goog
.ui
.Component
.EventType
.ACTION
, okCallback
);
227 var cancel
= new goog
.ui
.Button('Cancel');
229 cancelCallback
= goog
.bind(this.defaultCancelCallback_
, this);
230 this.eh_
.listen(cancel
, goog
.ui
.Component
.EventType
.ACTION
, cancelCallback
);
231 this.controlContainer_
.addChild(ok
, true);
232 this.controlContainer_
.addChild(cancel
, true);
236 * The default cancel callback for the above createOkCancel_().
240 armadillo
.Actor
.prototype.defaultCancelCallback_ = function(e
) {
241 this.controlContainer_
.removeChildren(true);
245 * Tile Control Renderer
248 armadillo
.Actor
.TileControlRenderer_ = function() {
249 goog
.ui
.ControlRenderer
.call(this);
251 goog
.inherits(armadillo
.Actor
.TileControlRenderer_
, goog
.ui
.ControlRenderer
);
254 * Returns the control's contents wrapped in a DIV, with the renderer's own
255 * CSS class and additional state-specific classes applied to it.
256 * @param {goog.ui.Control} control Control to render.
257 * @return {Element} Root element for the control.
259 armadillo
.Actor
.TileControlRenderer_
.prototype.createDom = function(control
) {
260 // Create and return DIV wrapping contents.
261 return control
.getDomHelper().createDom('div', 'tile', control
.getContent());