summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-02-06 22:47:49 +0200
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-02-12 12:38:31 +0200
commit96f7ffd1186aedcd606a330047b9072cb1fd0ede (patch)
treed9c0b9de45032d35317e4f713b7f871e7731645b
parent0caa116c914a4969556b4d671ffeadd8b9b12cc6 (diff)
downloadaconf-96f7ffd1186aedcd606a330047b9072cb1fd0ede.tar.bz2
aconf-96f7ffd1186aedcd606a330047b9072cb1fd0ede.tar.xz
web client: dom module
-rw-r--r--web/client.js55
-rw-r--r--web/dom.js31
2 files changed, 48 insertions, 38 deletions
diff --git a/web/client.js b/web/client.js
index 310c869..24d335f 100644
--- a/web/client.js
+++ b/web/client.js
@@ -19,6 +19,7 @@ requirejs.config({
require(
[
+ "acf2/dom",
"acf2/error",
"acf2/path",
"acf2/statusbar",
@@ -30,7 +31,7 @@ require(
"jquery-blockui",
"jquery-ui/sortable"
],
- function(formatError, pth, statusBar, txnMgr, type, $, _) {
+ function(dom, formatError, pth, statusBar, txnMgr, type, $, _) {
$("#login").submit(function() {
$.ajax("/login", {
@@ -46,28 +47,6 @@ require(
);
- function href() {
- return $("<a>").attr({href: "javascript:void(0);"});
- }
-
- function objectRef(value, el) {
- el = el || href();
- if (value) {
- el.click(function() {
- $.bbq.pushState("#" + value);
- }).text("Show");
- }
- return el;
- };
-
- function makeRow(el) {
- if (el.is("td")) return $("<tr>").html(el);
- return el;
- }
-
- function setStatus(el, status) { el.prop("class", status); }
-
-
var Widget = {
extend: function(spec) {
var res = Object.create(this);
@@ -101,7 +80,7 @@ require(
if (!editable || !meta.editable) {
var el = this.staticRender(value, meta);
if (el) {
- setStatus(el, status);
+ dom.setStatus(el, status);
return el;
}
}
@@ -125,12 +104,12 @@ require(
this.visible = true;
if (removable) {
- var link = href().click(function() {
+ var link = dom.href().click(function() {
data.delete(name).done(function(txnValid) {
$("#content").trigger("reload", [txnValid]);
})
}).text("Delete");
- this.wrapped = makeRow(this.wrapped);
+ this.wrapped = dom.makeRow(this.wrapped);
if (this.wrapped.is("tr")) link = $("<td>").html(link);
this.wrapped.append(link);
}
@@ -182,7 +161,7 @@ require(
setStatus: function(status) {
if (this.el && this.showStatus)
- setStatus(this.statusEl(), status);
+ dom.setStatus(this.statusEl(), status);
},
statusEl: function() { return this.el; },
@@ -345,12 +324,12 @@ require(
var Link = Widget.extend({
staticRender: function(value, meta) {
- return $("<td>").html(objectRef(value));
+ return $("<td>").html(dom.objectRef(value));
},
- createEl: href,
+ createEl: dom.href,
- render: function(value, meta) { objectRef(value, this.el) },
+ render: function(value, meta) { dom.objectRef(value, this.el) },
wrap: function() { return $("<td>").html(this.el); },
@@ -648,8 +627,8 @@ require(
appendWidget: function(el, label) {
var self = this;
- el = makeRow(el);
-
+ el = dom.makeRow(el);
+
if (el.is("tr")) {
el.prepend($("<td>").text(label));
this.appendRow(el);
@@ -740,13 +719,13 @@ require(
var item = $("<td>");
if (choice.ref)
- item.html(objectRef(choice.ref)
+ item.html(dom.objectRef(choice.ref)
.text(choice["ui-value"]));
else item.text(choice["ui-value"]);
row.append(item);
function setRowStatus() {
- setStatus(row, data.status(choice.value));
+ dom.setStatus(row, data.status(choice.value));
}
setRowStatus();
@@ -786,7 +765,7 @@ require(
},
staticRender: function(value, meta) {
- return $("<td>").html(objectRef(value).text(value));
+ return $("<td>").html(dom.objectRef(value).text(value));
},
statusEl: function() { return this.el.find("select"); },
@@ -801,8 +780,8 @@ require(
var link = $("<div>");
var update = _.bind(function() {
- link.html(objectRef(this.get()));
- }, this);
+ link.html(dom.objectRef(this.get()));
+ }, this);
this.el.append(link);
this.field.change(update);
@@ -921,7 +900,7 @@ require(
}
function addItem(path, ui_name, status, current) {
- var el = $("<li>").html(objectRef(path).text(ui_name));
+ var el = $("<li>").html(dom.objectRef(path).text(ui_name));
el.prop("class", status);
if (current) el.addClass("current");
target.append(el);
diff --git a/web/dom.js b/web/dom.js
new file mode 100644
index 0000000..44f8491
--- /dev/null
+++ b/web/dom.js
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012-2014 Kaarle Ritvanen
+ * See LICENSE file for license details
+ */
+
+define(["jquery", "jquery-bbq"], function($) {
+ function href() {
+ return $("<a>").attr({href: "javascript:void(0);"});
+ }
+
+ return {
+ href: href,
+
+ objectRef: function(value, el) {
+ el = el || href();
+ if (value) {
+ el.click(function() {
+ $.bbq.pushState("#" + value);
+ }).text("Show");
+ }
+ return el;
+ },
+
+ makeRow: function(el) {
+ if (el.is("td")) return $("<tr>").html(el);
+ return el;
+ },
+
+ setStatus: function(el, status) { el.prop("class", status); }
+ };
+});