summaryrefslogtreecommitdiffstats
path: root/web/widget/abstract
diff options
context:
space:
mode:
Diffstat (limited to 'web/widget/abstract')
-rw-r--r--web/widget/abstract/base.js155
-rw-r--r--web/widget/abstract/fields.js137
-rw-r--r--web/widget/abstract/inline.js41
-rw-r--r--web/widget/abstract/node.js50
4 files changed, 0 insertions, 383 deletions
diff --git a/web/widget/abstract/base.js b/web/widget/abstract/base.js
deleted file mode 100644
index 5dd49a6..0000000
--- a/web/widget/abstract/base.js
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (c) 2012-2014 Kaarle Ritvanen
- * See LICENSE file for license details
- */
-
-define(
- ["aconf/dom", "aconf/error", "jquery", "underscore"],
- function(dom, formatError, $, _) {
- return {
- extend: function(spec) {
- var res = Object.create(this);
- for (key in spec) res[key] = spec[key];
- return res;
- },
-
- new: function(data, name, meta, level, editable, removable) {
- return Object.create(this).init(
- data, name, meta, level, editable, removable
- );
- },
-
- init: function(data, name, meta, level, editable, removable) {
- this.data = data;
- this.name = name;
- this.meta = meta;
- this.level = level;
-
- function appendRemoveButton(el) {
- if (removable) {
- var link = dom.href().click(function() {
- data.delete(name).done(function(txnValid) {
- $("#content").trigger("reload", [txnValid]);
- })
- }).text("Delete");
- el = dom.makeRow(el);
- if (el.is("tr")) link = $("<td>").html(link);
- el.append(link);
- }
-
- return el;
- }
-
- var value = data.get(name);
-
- if (!editable || !meta.editable) {
- var el = this.staticRender(value, meta);
- if (el) {
- el = appendRemoveButton(el);
-
- _.each(["start", "updated"], function(event) {
- el.on(event, function(event) {
- event.stopPropagation();
- });
- });
- dom.setStatus(el, data.status(name));
- return el;
- }
- }
-
- this.makeEl();
- this.dynamic = meta.dynamic;
- this.visible = true;
-
- this.wrapped = appendRemoveButton(this.wrap());
- this.wrapped.data("description", meta.description);
-
- this.handleResponse(this.requestData(value, meta));
-
- var self = this;
-
- function validate() {
- self.request.done(function(value) {
- self.validate(value);
- });
- }
-
- this.wrapped.on("start", function(event) {
- if (data.status(name) == "invalid") validate();
- else self.setVisible();
- event.stopPropagation();
- });
-
- this.wrapped.on("updated", function(event, field) {
- if (self.dynamic) self.refresh();
- if (!field ||
- self.dynamic ||
- (meta.condition && field in meta.condition))
- validate();
- event.stopPropagation();
- });
-
- return this.wrapped;
- },
-
- makeEl: function() { this.el = this.createEl(); },
-
- requestData: function(value, meta) {
- return $.Deferred().resolve(value, meta);
- },
-
- refreshData: function() {
- var def = $.Deferred();
- var self = this;
- this.data.metaRequest(this.name).done(function(data) {
- def.resolve(self.get(), data);
- });
- return def;
- },
-
- handleResponse: function(request) {
- this.request = request;
- var self = this;
- request.done(function(value, meta) {
- if (request != self.request) return;
- self.render(value, meta);
- self.updateStatus();
- });
- },
-
- refresh: function() { this.handleResponse(this.refreshData()); },
-
- wrap: function() { return this.el; },
-
- updateStatus: function() {
- this.setStatus(this.data.status(this.name));
- },
-
- showStatus: true,
-
- setStatus: function(status) {
- if (this.el && this.showStatus)
- dom.setStatus(this.statusEl(), status);
- },
-
- statusEl: function() { return this.el; },
-
- setVisible: function() {
- this.visible = this.data.match(this.meta.condition);
- if (this.wrapped)
- this.wrapped.trigger("setVisible", [this.visible]);
- },
-
- validate: function(value) { this.setVisible(); },
-
- formatValidationError: function(xhr) {
- if (_.isString(xhr)) return xhr;
-
- if (xhr.statusCode().status == 422)
- return _.values($.parseJSON(xhr.responseText)).join("\n");
-
- return formatError("Error", xhr);
- }
- };
- }
-);
diff --git a/web/widget/abstract/fields.js b/web/widget/abstract/fields.js
deleted file mode 100644
index f7fdfbe..0000000
--- a/web/widget/abstract/fields.js
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2012-2014 Kaarle Ritvanen
- * See LICENSE file for license details
- */
-
-define(
- [
- "aconf/dom",
- "aconf/widget/abstract/node",
- "jquery",
- "underscore",
- "aconf/widget/audio",
- "aconf/widget/checkbox",
- "aconf/widget/checkboxes",
- "aconf/widget/combobox",
- "aconf/widget/date",
- "aconf/widget/field",
- "aconf/widget/inline",
- "aconf/widget/reference"
- ],
- function(dom, Base, $, _) {
- return Base.extend({
- render: function(data, meta) {
- Base.render.call(this, data, meta);
-
- this.reqData = data;
- var self = this;
-
- if (meta.type == "model") {
- _.each(meta.actions, function(action) {
- self.addActionButton(action["ui-name"], function() {
- data.invoke(action.name)
- .done(function() { alert("Done"); })
- .fail(function() { alert("Failed"); });
- });
- });
-
- this.createModelWidgets(
- _.filter(meta.fields, function(field) {
- return field.visible;
- }),
- true
- );
-
- var labels = _.object(_.map(meta.fields, function(field) {
- return [field.name, field["ui-name"]];
- }));
-
- _.each(this.widgets, function(f1, name) {
- self.setupWidget(f1, labels[name]);
-
- f1.on("validated", function(event) {
- event.stopPropagation();
- });
-
- _.each(self.widgets, function(f2) {
- if (f1 != f2)
- f1.on("validated", function(event) {
- f2.trigger("updated", [name]);
- });
- });
- });
-
- _.each(this.widgets, function(widget) {
- widget.trigger("start");
- });
- }
-
- else _.each(data.data, function(value, name) {
- if (meta.type == "set") name = data.data[name];
- else if (_.isArray(data.data)) name++;
- self.renderCollectionMember(name, meta);
- });
- },
-
- createModelWidgets: function(fields, editable) {
- this.widgets = {};
- var self = this;
- _.each(fields, function(field) {
- var widget = self.createWidget(
- field.name, field, editable, false
- );
- if (widget) self.widgets[field.name] = widget;
- });
- },
-
- createWidget: function(name, meta, editable, removable) {
- var widget = this.widget(meta);
- if (widget)
- return widget.new(
- this.reqData,
- name,
- meta,
- this.level,
- editable,
- removable
- );
- },
-
- setupWidget: function(widget, label) {
- var container = this.appendWidget(widget, label);
- widget.on("setVisible", function(event, visible) {
- dom.setVisible(container, visible);
- event.stopPropagation();
- });
- },
-
- renderCollectionMember: function(name, meta) {
- var set = meta.type == "set";
- var widget = this.createWidget(
- name,
- meta.members,
- !set,
- _.contains(meta.removable, name)
- );
- this.setupWidget(
- widget, set ? null : meta["ui-member"] + " " + name
- );
- widget.trigger("start");
- return widget;
- },
-
- widget: function(meta) {
- return require("aconf/widget/" + meta.widget);
- },
-
- validate: function(data) {
- Base.validate.call(this, data);
-
- if (this.widgets)
- _.each(this.widgets, function(widget) {
- widget.trigger("updated");
- });
- }
- });
- }
-);
diff --git a/web/widget/abstract/inline.js b/web/widget/abstract/inline.js
deleted file mode 100644
index dedde36..0000000
--- a/web/widget/abstract/inline.js
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2012-2014 Kaarle Ritvanen
- * See LICENSE file for license details
- */
-
-define(
- ["aconf/statusbar", "aconf/widget/link", "jquery", "underscore"],
- function(statusBar, Base, $, _) {
- return Base.extend({
- init: function(
- data, name, meta, level, editable, removable
- ) {
- this.txnMgr = data.txnMgr;
- return Base.init.call(
- this, data, name, meta, level, editable, removable
- );
- },
-
- staticRender: function(value, meta) { return null; },
-
- createEl: function() { return $("<div>"); },
-
- requestData: function(value, meta) {
- this.path = value;
- return this._requestData(value, meta);
- },
-
- _requestData: function(value, meta) {
- return Base.requestData.call(this, value, meta);
- },
-
- refreshData: function() {
- var def = $.Deferred();
- this.txnMgr.query(this.path).done(function(data) {
- def.resolve(data, data.meta);
- });
- return def;
- }
- });
- }
-);
diff --git a/web/widget/abstract/node.js b/web/widget/abstract/node.js
deleted file mode 100644
index 22c35fa..0000000
--- a/web/widget/abstract/node.js
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2012-2014 Kaarle Ritvanen
- * See LICENSE file for license details
- */
-
-define(
- ["aconf/statusbar", "aconf/widget/abstract/inline", "jquery", "underscore"],
- function(statusBar, Base, $, _) {
- return Base.extend({
- init: function(
- data, name, meta, level, editable, removable
- ) {
- return Base.init.call(
- this,
- data,
- name,
- meta,
- Math.min(6, level + 1),
- editable,
- removable
- );
- },
-
- showStatus: false,
-
- _requestData: function(value, meta) { return this.refreshData(); },
-
- showHeading: true,
-
- render: function(data, meta) {
- if (this.showHeading)
- this.el.html(
- $("<h" + this.level + ">").text(meta["ui-name"])
- );
- },
-
- wrap: function() { return this.el; },
-
- validate: function(data) {
- Base.validate.call(this, data);
-
- if (this.data.match(this.meta.condition)) {
- var valid = data.validate();
- this.setStatus(data.status());
- statusBar.validationReady(valid);
- }
- }
- });
- }
-);