summaryrefslogtreecommitdiffstats
path: root/web/widget/combobox.js
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-02-06 23:09:13 +0200
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-02-14 22:35:56 +0200
commit38ac196b2f00c1e13a0928cd892384bc296c8a98 (patch)
tree473663650b5b4fd898bd9bab4c666dca6b900dd4 /web/widget/combobox.js
parent7d434464a843a8ca8acc903367492186a0ae13e8 (diff)
downloadaconf-38ac196b2f00c1e13a0928cd892384bc296c8a98.tar.bz2
aconf-38ac196b2f00c1e13a0928cd892384bc296c8a98.tar.xz
web client: extract each widget to a dedicated file
Diffstat (limited to 'web/widget/combobox.js')
-rw-r--r--web/widget/combobox.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/web/widget/combobox.js b/web/widget/combobox.js
new file mode 100644
index 0000000..72761ee
--- /dev/null
+++ b/web/widget/combobox.js
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2012-2014 Kaarle Ritvanen
+ * See LICENSE file for license details
+ */
+
+define(["acf2/widget/field", "jquery", "underscore"], function(Base, $, _) {
+ var Class = Base.extend({
+ createEl: function() { return $("<select>"); },
+
+ staticRender: function(value, meta) {
+ return this.super(
+ Class,
+ "staticRender",
+ _.findWhere(meta.choice, {value: value})["ui-value"],
+ meta
+ );
+ },
+
+ render: function(value, meta) {
+ var el = this.field.empty();
+
+ function opt(value, ui_value, selected) {
+ el.append($("<option>").attr(
+ {value: value, selected: selected}
+ ).text(ui_value));
+ }
+
+ if (!meta.required) opt("", "(none)", value == null);
+
+ _.each(
+ meta.choice,
+ function(choice) {
+ var selected = value == choice.value;
+ if (choice.enabled || selected)
+ opt(choice.value, choice["ui-value"], selected);
+ }
+ );
+ }
+ });
+
+ return Class;
+});