]>
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.Container');
21 goog
.require('goog.ui.Dialog');
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
);
34 * The file object on which this acts.
35 * @type {armadillo.File}
40 * Registrar for all the Actor's events.
41 * @type {goog.events.EventHandler}
43 this.eh_
= new goog
.events
.EventHandler();
46 * The UI element used for a specific action.
47 * @type {goog.Disposable}
49 this.actionObject_
= null;
51 goog
.inherits(armadillo
.Actor
, goog
.ui
.Container
);
54 * The different options that the Actor can perform.
56 armadillo
.Actor
.options_
= {
61 TV_RENAME : 'tv-rename'
65 * String values for the options.
67 armadillo
.Actor
.optionStrings_
= {
72 'tv-rename' : 'Rename TV Episode'
79 armadillo
.Actor
.prototype.disposeInternal = function() {
80 armadillo
.Actor
.superClass_
.disposeInternal
.call(this);
84 // Remove the actor display element.
85 goog
.dom
.removeNode(this.element_
);
88 if (this.actionObject_
) {
89 this.actionObject_
.dispose();
90 this.actionObject_
= null;
96 armadillo
.Actor
.prototype.createDom = function() {
97 this.setElementInternal(this.dom_
.createDom('div'));
98 this.decorate(this.getElement());
102 * Decorates the given element into a path control.
103 * @param {Element} element
105 armadillo
.Actor
.prototype.decorateInternal = function(element
) {
106 this.element_
= element
;
107 goog
.dom
.classes
.add(this.element_
, 'actor');
108 this.dom_
.removeChildren(this.element_
);
109 for (var option
in armadillo
.Actor
.options_
) {
110 var tile
= this.createTile_(option
);
112 this.addChild(tile
, true);
118 * Creates the DOM Element that is inserted into the popup.
119 * @param {armadillo.Actor.options_} Key of the option to create
120 * @returns {goog.ui.Control}
122 armadillo
.Actor
.prototype.createTile_ = function(option
) {
123 var value
= armadillo
.Actor
.options_
[option
];
125 // Create the title element.
126 var title
= this.dom_
.createDom('span', 'title',
127 armadillo
.Actor
.optionStrings_
[value
]);
129 var tile
= new goog
.ui
.Control(title
, new armadillo
.Actor
.TileControlRenderer_());
130 tile
.actorOption
= value
;
132 // Cannot open non-directory files.
133 if (value
== armadillo
.Actor
.options_
.OPEN
&& !this.file_
.isDirectory()) {
137 this.eh_
.listen(tile
, goog
.ui
.Component
.EventType
.ACTION
,
138 this.tileClickHandler_
, false, this);
143 * Click handler for individual tiles.
146 armadillo
.Actor
.prototype.tileClickHandler_ = function(e
) {
147 var option
= e
.target
.actorOption
;
148 if (option
== armadillo
.Actor
.options_
.OPEN
) {
149 // TODO: assert that this.file_.isDirectory().
150 app
.navigate(this.file_
.getName());
151 } else if (option
== armadillo
.Actor
.options_
.MOVE
||
152 option
== armadillo
.Actor
.options_
.RENAME
) {
154 } else if (option
== armadillo
.Actor
.options_
.DELETE
) {
155 this.performDelete_();
156 } else if (option
== armadillo
.Actor
.options_
.TV_RENAME
) {
157 this.performTVRename_();
162 * Subroutine to handle bringing up the move confirmation UI.
165 armadillo
.Actor
.prototype.performMove_ = function() {
166 this.actionObject_
= this.createActionDialog_();
167 this.actionObject_
.setTitle('Move File');
169 var editor
= new armadillo
.PathControl(this.file_
.getFullPath(), true);
170 this.actionObject_
.addChild(editor
, true);
172 var closeCallback = function(e
) {
173 if (e
.key
!= goog
.ui
.Dialog
.DefaultButtonKeys
.CANCEL
) {
174 var newPath
= editor
.getPath();
175 this.file_
.move(newPath
);
178 // Will be removed when the event source closes.
179 this.eh_
.listen(this.actionObject_
, goog
.ui
.Dialog
.SELECT_EVENT
,
180 closeCallback
, false, this);
182 this.actionObject_
.setVisible(true);
183 var position
= goog
.style
.getPosition(this.actionObject_
.getElement());
184 goog
.style
.setPosition(this.actionObject_
.getElement(), position
.x
, '10%');
188 * Subroutine to handle bringing up the delete confirmation UI.
191 armadillo
.Actor
.prototype.performDelete_ = function() {
192 this.actionObject_
= this.createActionDialog_();
193 this.actionObject_
.setTitle('Confirm Delete');
195 var container
= this.actionObject_
.getContentElement();
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 goog
.dom
.appendChild(container
, content
);
202 var closeCallback = function(e
) {
203 if (e
.key
!= goog
.ui
.Dialog
.DefaultButtonKeys
.CANCEL
) {
207 // Will be removed when the event source closes.
208 this.eh_
.listen(this.actionObject_
, goog
.ui
.Dialog
.SELECT_EVENT
,
209 closeCallback
, false, this);
211 this.actionObject_
.setVisible(true);
215 * Subroutine that renames a file to it's title based on season and episode.
218 armadillo
.Actor
.prototype.performTVRename_ = function() {
219 var renamer
= new armadillo
.TVRenamer(this.file_
);
224 * Creates a new instance of a Dialog that has some basic properties set that
225 * are common to performing actions.
228 armadillo
.Actor
.prototype.createActionDialog_ = function() {
229 var confirm
= new goog
.ui
.Dialog();
230 confirm
.setDisposeOnHide(true);
231 confirm
.setEscapeToCancel(true);
232 confirm
.setModal(true);
233 confirm
.setDraggable(false);
234 confirm
.setHasTitleCloseButton(false);
239 * Tile Control Renderer
242 armadillo
.Actor
.TileControlRenderer_ = function() {
243 goog
.ui
.ControlRenderer
.call(this);
245 goog
.inherits(armadillo
.Actor
.TileControlRenderer_
, goog
.ui
.ControlRenderer
);
248 * Returns the control's contents wrapped in a DIV, with the renderer's own
249 * CSS class and additional state-specific classes applied to it.
250 * @param {goog.ui.Control} control Control to render.
251 * @return {Element} Root element for the control.
253 armadillo
.Actor
.TileControlRenderer_
.prototype.createDom = function(control
) {
254 // Create and return DIV wrapping contents.
255 return control
.getDomHelper().createDom('div', 'tile', control
.getContent());