goog.require('goog.events');
goog.require('goog.positioning.ClientPosition');
goog.require('goog.positioning.Corner');
+goog.require('goog.ui.Dialog');
goog.require('goog.ui.Popup');
/**
*/
armadillo.Actor.prototype.tileClickHandler_ = function(e) {
if (e.target.actorOption == armadillo.Actor.options_.DELETE) {
- console.log("DELETE DELETE DELETE " + this.file_.getName());
+ var confirm = new goog.ui.Dialog();
+ confirm.setDisposeOnHide(true);
+ confirm.setEscapeToCancel(true);
+ confirm.setModal(true);
+ confirm.setDraggable(false);
+ confirm.setHasTitleCloseButton(false);
+ confirm.setTitle('Confirm Delete');
+
+ var container = confirm.getContentElement();
+ var content = goog.dom.createDom('span', null,
+ 'Are you sure you want to delete:',
+ goog.dom.createElement('br'),
+ goog.dom.createDom('strong', null, this.file_.getName()));
+ goog.dom.appendChild(container, content);
+
+ var closeCallback = function(e) {
+ if (e.key != goog.ui.Dialog.DefaultButtonKeys.CANCEL) {
+ this.file_.delete();
+ }
+ };
+ // Will be removed when the event source closes.
+ goog.events.listen(confirm, goog.ui.Dialog.SELECT_EVENT,
+ closeCallback, false, this);
+
+ confirm.setVisible(true);
}
console.log('You clicked ' + e.target.actorOption);
};
/**
* A file in a directory listing.
* @param {string} File name.
+ * @param {string} The path the file resides at.
* @constructor
*/
-armadillo.File = function(name) {
+armadillo.File = function(name, path) {
goog.Disposable.call(this);
this.name_ = name;
+ this.path_ = path;
+ console.log('creating file ' + path + name);
this.isDirectory_ = app.isDirectory(name);
};
goog.inherits(armadillo.File, goog.Disposable);
return this.element_;
};
+/**
+ * Deletes the given file in the backend by sending a request. On return, it
+ * will re-query the directory.
+ */
+armadillo.File.prototype.delete = function() {
+ var file = this;
+ var callback = function(data) {
+ if (data['error']) {
+ app.showError(data['message']);
+ return;
+ } else {
+ app.clearError();
+ }
+ app.list(file.path_);
+ };
+ app.sendRequest('delete', {'path':this.path_ + this.name_}, callback);
+};
+
/**
* Click handler for the list element.
* @param {Event} e
* @param {Object} extra_data Extra data to add.
* @param {Function} callback XHR callback.
*/
-armadillo.App.prototype.sendRequest_ = function(action, extra_data, callback) {
+armadillo.App.prototype.sendRequest = function(action, extra_data, callback) {
var data = new goog.Uri.QueryData();
data.set('action', action);
data.extend(extra_data);
var callback = function(e) {
var data = e.target.getResponseJson();
if (data['error']) {
- app.showError_(data['message']);
+ app.showError(data['message']);
return; // Error.
} else {
- app.clearError_();
+ app.clearError();
}
// Update the listing.
// Add items for each entry.
goog.array.forEach(data, function(file) {
- var fileObject = new armadillo.File(file);
+ var fileObject = new armadillo.File(file, path);
goog.dom.appendChild(list, fileObject.draw());
});
}
- this.sendRequest_('list', {'path':path}, callback);
+ this.sendRequest('list', {'path':path}, callback);
};
/**
return path[path.length - 1] == '/';
};
+/**
+ * Gets the current path of the directory being displayed, absolute to root.
+ * @returns string
+ */
+armadillo.App.prototype.getCurrentPath = function() {
+ return this.currentPath_;
+};
+
/**
* Strips the last path component from a path.
* @param {string} path
/**
* Clears the error message.
*/
-armadillo.App.prototype.clearError_ = function() {
+armadillo.App.prototype.clearError = function() {
this.errorEffect_.hide();
goog.dom.setTextContent(this.errorEffect_.element, '');
};
* Shows an error message.
* @param {string} message
*/
-armadillo.App.prototype.showError_ = function(message) {
+armadillo.App.prototype.showError = function(message) {
goog.dom.setTextContent(this.errorEffect_.element, message);
this.errorEffect_.show();
};
.actor .tile .title {
font-size: 0.7em;
}
+
+/**
+ * Delete Confirmation Dialog
+ * From Google Closure Library
+ *
+ * Copyright 2009 The Closure Library Authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by an Apache 2.0 License.
+ * See the COPYING file for details.
+
+ * Standard styling for goog.ui.Dialog.
+ *
+ * @author ssaviano@google.com (Steven Saviano)
+ * @author attila@google.com (Attila Bodis)
+ */
+
+.modal-dialog {
+ background: #c1d9ff;
+ border: 1px solid #3a5774;
+ color: #000;
+ padding: 4px;
+ position: absolute;
+}
+
+.modal-dialog a,
+.modal-dialog a:link,
+.modal-dialog a:visited {
+ color: #06c;
+ cursor: pointer;
+}
+
+.modal-dialog-bg {
+ background: #666;
+ left: 0;
+ position: absolute;
+ top: 0;
+}
+
+.modal-dialog-title {
+ background: #e0edfe;
+ color: #000;
+ cursor: pointer;
+ font-size: 120%;
+ font-weight: bold;
+ padding: 8px 15px 8px 8px;
+ position: relative;
+ _zoom: 1; /* Ensures proper width in IE6 RTL. */
+}
+
+.modal-dialog-title-close {
+ /* Client apps may override the URL at which they serve the sprite. */
+ background: #e0edfe url(https://ssl.gstatic.com/editor/editortoolbar.png) no-repeat -528px 0;
+ cursor: default;
+ height: 15px;
+ position: absolute;
+ right: 10px;
+ top: 8px;
+ width: 15px;
+ vertical-align: middle;
+}
+
+.modal-dialog-buttons,
+.modal-dialog-content {
+ background-color: #fff;
+ padding: 8px;
+}
+
+.goog-buttonset-default {
+ font-weight: bold;
+}
+