Add the Actor class that will be the foundation for the file controls.
[armadillo.git] / web_frontend / actor.js
1 //
2 // Armadillo File Manager
3 // Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
4 //
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.
8 //
9
10 goog.provide('armadillo.Actor');
11
12 goog.require('goog.array');
13 goog.require('goog.dom');
14 goog.require('goog.positioning.ClientPosition');
15 goog.require('goog.positioning.Corner');
16 goog.require('goog.ui.Popup');
17
18 /**
19 * The Actor is a popup that displays the various actions that can be performed
20 * on a given File.
21 * @constructor
22 */
23 armadillo.Actor = function() {
24 goog.Disposable.call(this);
25 this.element_ = this.createElement_();
26 this.popup_ = new goog.ui.Popup(this.element_);
27 armadillo.Actor.actors_.push(this);
28 }
29 goog.inherits(armadillo.Actor, goog.Disposable);
30
31 /**
32 * An array of all the Actors that have been created.
33 */
34 armadillo.Actor.actors_ = new Array();
35
36 /**
37 * A global property that should be checked to see if an actor is present,
38 * creating a modal session.
39 */
40 armadillo.Actor.isModal = function() {
41 var isVisible = false;
42 goog.array.forEach(armadillo.Actor.actors_, function (e) {
43 isVisible |= e.popup_.isVisible();
44 });
45 return isVisible;
46 };
47
48 /**
49 * Disposer
50 * @protected
51 */
52 armadillo.Actor.prototype.disposeInternal = function() {
53 armadillo.Actor.superClass_.disposeInternal.call(this);
54 goog.dom.removeNode(this.element_);
55 this.element_ = null;
56 this.popup_.dispose();
57 this.popup_ = null;
58 goog.array.remove(armadillo.Actor.actors_, this);
59 };
60
61 /**
62 * Shows the popup.
63 * @param {int} x The X position to show at
64 * @param {int} y The Y position to show at
65 */
66 armadillo.Actor.prototype.show = function(x, y) {
67 if (armadillo.Actor.isModal())
68 return;
69 var firstBodyElement = goog.dom.getFirstElementChild(document.body);
70 goog.dom.insertSiblingBefore(this.element_, firstBodyElement);
71 this.popup_.setPinnedCorner(goog.positioning.Corner.TOP_LEFT);
72 this.popup_.setPosition(new goog.positioning.ClientPosition(x, y));
73 this.popup_.setVisible(true);
74 };
75
76 /**
77 * Hides the popup.
78 */
79 armadillo.Actor.prototype.hide = function() {
80 this.popup_.setVisible(false);
81 };
82
83 /**
84 * Creates the DOM Element that is inserted into the popup.
85 * @returns Element
86 */
87 armadillo.Actor.prototype.createElement_ = function() {
88 var root = goog.dom.createDom('div', 'actor');
89 goog.dom.setTextContent(root, 'foo bar');
90 return root;
91 };