From 0e04455c56962a8bbd76b35481c4b1d24a689e15 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 6 Sep 2010 16:52:48 -0400 Subject: [PATCH] Add the Actor class that will be the foundation for the file controls. --- build.py | 1 + web_frontend/actor.js | 91 +++++++++++++++++++++++++++++++++++++++++ web_frontend/file.js | 11 ++++- web_frontend/screen.css | 8 ++++ 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 web_frontend/actor.js diff --git a/build.py b/build.py index 0de1e2e..c69b301 100755 --- a/build.py +++ b/build.py @@ -29,6 +29,7 @@ SOURCES = [ 'main.go' ] SOURCES_FE = [ + 'actor.js', 'file.js', 'main.js', ] diff --git a/web_frontend/actor.js b/web_frontend/actor.js new file mode 100644 index 0000000..83a6d00 --- /dev/null +++ b/web_frontend/actor.js @@ -0,0 +1,91 @@ +// +// Armadillo File Manager +// Copyright (c) 2010, Robert Sesek +// +// This program is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation, either version 3 of the License, or any later version. +// + +goog.provide('armadillo.Actor'); + +goog.require('goog.array'); +goog.require('goog.dom'); +goog.require('goog.positioning.ClientPosition'); +goog.require('goog.positioning.Corner'); +goog.require('goog.ui.Popup'); + +/** + * The Actor is a popup that displays the various actions that can be performed + * on a given File. + * @constructor + */ +armadillo.Actor = function() { + goog.Disposable.call(this); + this.element_ = this.createElement_(); + this.popup_ = new goog.ui.Popup(this.element_); + armadillo.Actor.actors_.push(this); +} +goog.inherits(armadillo.Actor, goog.Disposable); + +/** + * An array of all the Actors that have been created. + */ +armadillo.Actor.actors_ = new Array(); + +/** + * A global property that should be checked to see if an actor is present, + * creating a modal session. + */ +armadillo.Actor.isModal = function() { + var isVisible = false; + goog.array.forEach(armadillo.Actor.actors_, function (e) { + isVisible |= e.popup_.isVisible(); + }); + return isVisible; +}; + +/** + * Disposer + * @protected + */ +armadillo.Actor.prototype.disposeInternal = function() { + armadillo.Actor.superClass_.disposeInternal.call(this); + goog.dom.removeNode(this.element_); + this.element_ = null; + this.popup_.dispose(); + this.popup_ = null; + goog.array.remove(armadillo.Actor.actors_, this); +}; + +/** + * Shows the popup. + * @param {int} x The X position to show at + * @param {int} y The Y position to show at + */ +armadillo.Actor.prototype.show = function(x, y) { + if (armadillo.Actor.isModal()) + return; + var firstBodyElement = goog.dom.getFirstElementChild(document.body); + goog.dom.insertSiblingBefore(this.element_, firstBodyElement); + this.popup_.setPinnedCorner(goog.positioning.Corner.TOP_LEFT); + this.popup_.setPosition(new goog.positioning.ClientPosition(x, y)); + this.popup_.setVisible(true); +}; + +/** + * Hides the popup. + */ +armadillo.Actor.prototype.hide = function() { + this.popup_.setVisible(false); +}; + +/** + * Creates the DOM Element that is inserted into the popup. + * @returns Element + */ +armadillo.Actor.prototype.createElement_ = function() { + var root = goog.dom.createDom('div', 'actor'); + goog.dom.setTextContent(root, 'foo bar'); + return root; +}; diff --git a/web_frontend/file.js b/web_frontend/file.js index d40f0b9..09f7c76 100644 --- a/web_frontend/file.js +++ b/web_frontend/file.js @@ -9,6 +9,7 @@ goog.provide('armadillo.File'); +goog.require('armadillo.Actor'); goog.require('goog.Disposable'); goog.require('goog.dom'); @@ -79,6 +80,9 @@ armadillo.File.prototype.draw = function() { * @param {Event} e */ armadillo.File.prototype.clickHandler_ = function(e) { + if (armadillo.Actor.isModal()) { + return; + } if (this.isDirectory_) { app.navigate(this.name_); } @@ -90,6 +94,8 @@ armadillo.File.prototype.clickHandler_ = function(e) { * @param {Event} e */ armadillo.File.prototype.hoverHandler_ = function(e) { + if (armadillo.Actor.isModal()) + return; var display = (e.type == goog.events.EventType.MOUSEOVER); this.button_.style.display = (display ? '' : 'none'); }; @@ -99,8 +105,11 @@ armadillo.File.prototype.hoverHandler_ = function(e) { * @param {Event} e */ armadillo.File.prototype.buttonClickHandler_ = function(e) { + if (armadillo.Actor.isModal()) + return; e.stopPropagation(); - alert('choose your bidding'); + var actor = new armadillo.Actor(); + actor.show(e.clientX, e.clientY); }; /** diff --git a/web_frontend/screen.css b/web_frontend/screen.css index f1b7517..31c4f9e 100644 --- a/web_frontend/screen.css +++ b/web_frontend/screen.css @@ -45,3 +45,11 @@ h1 { background-color: rgba(167, 40, 26, 0.1); color: rgb(0, 30, 30); } + +.actor { + width: 3em; + height: 3em; + position: absolute; + background-color: red; + visibility: hidden; +} -- 2.43.5