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('goog.array');
13 goog
.require('goog.dom');
14 goog
.require('goog.events');
15 goog
.require('goog.positioning.ClientPosition');
16 goog
.require('goog.positioning.Corner');
17 goog
.require('goog.ui.Popup');
20 * The Actor is a popup that displays the various actions that can be performed
24 armadillo
.Actor
= function() {
25 goog
.Disposable
.call(this);
26 this.element_
= this.createElement_();
27 this.popup_
= new goog
.ui
.Popup(this.element_
);
28 armadillo
.Actor
.actors_
.push(this);
30 goog
.inherits(armadillo
.Actor
, goog
.Disposable
);
33 * An array of all the Actors that have been created.
35 armadillo
.Actor
.actors_
= new Array();
38 * The different options that the Actor can perform.
40 armadillo
.Actor
.options_
= {
48 * String values for the options.
50 armadillo
.Actor
.optionStrings_
= {
58 * A global property that should be checked to see if an actor is present,
59 * creating a modal session.
61 armadillo
.Actor
.isModal
= function() {
62 var isVisible
= false;
63 goog
.array
.forEach(armadillo
.Actor
.actors_
, function (e
) {
64 isVisible
|= e
.popup_
.isVisible();
73 armadillo
.Actor
.prototype.disposeInternal
= function() {
74 armadillo
.Actor
.superClass_
.disposeInternal
.call(this);
76 // Unlisten the tiles.
77 var tiles
= goog
.dom
.getElementsByClassName('tile', this.element_
);
78 goog
.array
.forEach(tiles
, function (tile
) {
79 goog
.events
.unlistenByKey(tile
.actorListener
);
82 // Remove the actor display element.
83 goog
.dom
.removeNode(this.element_
);
87 this.popup_
.dispose();
90 // Remove the actor from the list.
91 goog
.array
.remove(armadillo
.Actor
.actors_
, this);
96 * @param {int} x The X position to show at
97 * @param {int} y The Y position to show at
99 armadillo
.Actor
.prototype.show
= function(x
, y
) {
100 if (armadillo
.Actor
.isModal())
102 var firstBodyElement
= goog
.dom
.getFirstElementChild(document
.body
);
103 goog
.dom
.insertSiblingBefore(this.element_
, firstBodyElement
);
104 this.popup_
.setPinnedCorner(goog
.positioning
.Corner
.TOP_LEFT
);
105 this.popup_
.setPosition(new goog
.positioning
.ClientPosition(x
, y
));
106 this.popup_
.setHideOnEscape(true);
107 this.popup_
.setVisible(true);
113 armadillo
.Actor
.prototype.hide
= function() {
114 this.popup_
.setVisible(false);
118 * Creates the DOM Element that is inserted into the popup.
121 armadillo
.Actor
.prototype.createElement_
= function() {
122 var root
= goog
.dom
.createDom('div', 'actor');
123 for (var option
in armadillo
.Actor
.options_
) {
124 var tile
= goog
.dom
.createDom('div', 'tile');
125 var value
= armadillo
.Actor
.options_
[option];
126 var title
= goog
.dom
.createDom('span', 'title',
127 armadillo
.Actor
.optionStrings_
[value]);
128 goog
.dom
.appendChild(tile
, title
);
129 goog
.dom
.appendChild(root
, tile
);
130 tile
.actorOption
= value
;
131 tile
.actorListener
= goog
.events
.listen(tile
, goog
.events
.EventType
.CLICK
,
132 this.tileClickHandler_
, false, this);
138 * Click handler for individual tiles.
141 armadillo
.Actor
.prototype.tileClickHandler_
= function(e
) {
142 if (e
.target
.actorOption
== armadillo
.Actor
.options_
.DELETE
) {
143 console
.log("DELETE DELETE DELETE");
145 console
.log('You clicked ' + e
.target
.actorOption
);