summaryrefslogtreecommitdiffstats
path: root/web/widget/abstract
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-04-05 21:24:23 +0300
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-04-05 22:33:08 +0300
commitd6b297b77701dd6f9fe313a05d9b8ef8af44f125 (patch)
tree4fb2bfcda8f52699bb996aa63c50c0aa3bf3f83e /web/widget/abstract
parent23613ea3bc6ca862c876d701c689ec8b92efaefa (diff)
downloadaconf-d6b297b77701dd6f9fe313a05d9b8ef8af44f125.tar.bz2
aconf-d6b297b77701dd6f9fe313a05d9b8ef8af44f125.tar.xz
web client: add missing module dependency
Diffstat (limited to 'web/widget/abstract')
-rw-r--r--web/widget/abstract/base.js267
1 files changed, 135 insertions, 132 deletions
diff --git a/web/widget/abstract/base.js b/web/widget/abstract/base.js
index 58a1932..4b2fc37 100644
--- a/web/widget/abstract/base.js
+++ b/web/widget/abstract/base.js
@@ -3,145 +3,148 @@
* See LICENSE file for license details
*/
-define(["aconf/dom", "jquery", "underscore"], function(dom, $, _) {
- 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;
-
- var value = data.get(name);
-
- if (!removable && (!editable || !meta.editable)) {
- var el = this.staticRender(value, meta);
- if (el) {
- _.each(["start", "updated"], function(event) {
- el.on(event, function(event) {
- event.stopPropagation();
+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;
+
+ var value = data.get(name);
+
+ if (!removable && (!editable || !meta.editable)) {
+ var el = this.staticRender(value, meta);
+ if (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.wrapped = this.wrap();
+ this.visible = true;
+
+ if (removable) {
+ var link = dom.href().click(function() {
+ data.delete(name).done(function(txnValid) {
+ $("#content").trigger("reload", [txnValid]);
+ })
+ }).text("Delete");
+ this.wrapped = dom.makeRow(this.wrapped);
+ if (this.wrapped.is("tr")) link = $("<td>").html(link);
+ this.wrapped.append(link);
+ }
+
+ 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);
});
- dom.setStatus(el, data.status(name));
- return el;
}
- }
- this.makeEl();
- this.dynamic = meta.dynamic;
-
- this.wrapped = this.wrap();
- this.visible = true;
-
- if (removable) {
- var link = dom.href().click(function() {
- data.delete(name).done(function(txnValid) {
- $("#content").trigger("reload", [txnValid]);
- })
- }).text("Delete");
- this.wrapped = dom.makeRow(this.wrapped);
- if (this.wrapped.is("tr")) link = $("<td>").html(link);
- this.wrapped.append(link);
- }
+ this.wrapped.on("start", function(event) {
+ if (data.status(name) == "invalid") validate();
+ else self.setVisible();
+ event.stopPropagation();
+ });
- this.wrapped.data("description", meta.description);
+ 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;
+ },
- this.handleResponse(this.requestData(value, meta));
+ makeEl: function() { this.el = this.createEl(); },
- var self = this;
+ requestData: function(value, meta) {
+ return $.Deferred().resolve(value, meta);
+ },
- function validate() {
- self.request.done(function(value) {
- self.validate(value);
+ 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);
+ },
- 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);
- }
- };
-});
+ 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);
+ }
+ };
+ }
+);