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);
75 goog
.dom
.removeNode(this.element_
);
77 this.popup_
.dispose();
79 goog
.array
.remove(armadillo
.Actor
.actors_
, this);
84 * @param {int} x The X position to show at
85 * @param {int} y The Y position to show at
87 armadillo
.Actor
.prototype.show
= function(x
, y
) {
88 if (armadillo
.Actor
.isModal())
90 var firstBodyElement
= goog
.dom
.getFirstElementChild(document
.body
);
91 goog
.dom
.insertSiblingBefore(this.element_
, firstBodyElement
);
92 this.popup_
.setPinnedCorner(goog
.positioning
.Corner
.TOP_LEFT
);
93 this.popup_
.setPosition(new goog
.positioning
.ClientPosition(x
, y
));
94 this.popup_
.setHideOnEscape(true);
95 this.popup_
.setVisible(true);
101 armadillo
.Actor
.prototype.hide
= function() {
102 this.popup_
.setVisible(false);
106 * Creates the DOM Element that is inserted into the popup.
109 armadillo
.Actor
.prototype.createElement_
= function() {
110 var root
= goog
.dom
.createDom('div', 'actor');
111 for (var option
in armadillo
.Actor
.options_
) {
112 var tile
= goog
.dom
.createDom('div', 'tile');
113 var value
= armadillo
.Actor
.options_
[option];
114 var title
= goog
.dom
.createDom('span', 'title',
115 armadillo
.Actor
.optionStrings_
[value]);
116 goog
.dom
.appendChild(tile
, title
);
117 goog
.dom
.appendChild(root
, tile
);
118 tile
.actorOption
= value
;
119 tile
.actorListener
= goog
.events
.listen(tile
, goog
.events
.EventType
.CLICK
,
120 this.tileClickHandler_
, false, this);
126 * Click handler for individual tiles.
129 armadillo
.Actor
.prototype.tileClickHandler_
= function(e
) {
130 if (e
.target
.actorOption
== armadillo
.Actor
.options_
.DELETE
) {
131 console
.log("DELETE DELETE DELETE");
133 console
.log('You clicked ' + e
.target
.actorOption
);