diff options
Diffstat (limited to 'web/widget')
-rw-r--r-- | web/widget/abstract/base.js | 155 | ||||
-rw-r--r-- | web/widget/abstract/fields.js | 137 | ||||
-rw-r--r-- | web/widget/abstract/inline.js | 41 | ||||
-rw-r--r-- | web/widget/abstract/node.js | 50 | ||||
-rw-r--r-- | web/widget/audio.html | 6 | ||||
-rw-r--r-- | web/widget/audio.js | 23 | ||||
-rw-r--r-- | web/widget/checkbox.html | 17 | ||||
-rw-r--r-- | web/widget/checkbox.js | 21 | ||||
-rw-r--r-- | web/widget/checkboxes.html | 8 | ||||
-rw-r--r-- | web/widget/checkboxes.js | 73 | ||||
-rw-r--r-- | web/widget/combobox.html | 18 | ||||
-rw-r--r-- | web/widget/combobox.js | 41 | ||||
-rw-r--r-- | web/widget/date.html | 6 | ||||
-rw-r--r-- | web/widget/date.js | 13 | ||||
-rw-r--r-- | web/widget/field.html | 11 | ||||
-rw-r--r-- | web/widget/field.js | 94 | ||||
-rw-r--r-- | web/widget/inline.html | 6 | ||||
-rw-r--r-- | web/widget/inline.js | 184 | ||||
-rw-r--r-- | web/widget/link.html | 8 | ||||
-rw-r--r-- | web/widget/link.js | 23 | ||||
-rw-r--r-- | web/widget/reference.html | 23 | ||||
-rw-r--r-- | web/widget/reference.js | 50 | ||||
-rw-r--r-- | web/widget/table/header.js | 33 | ||||
-rw-r--r-- | web/widget/table/row.js | 64 |
24 files changed, 103 insertions, 1002 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); - } - } - }); - } -); diff --git a/web/widget/audio.html b/web/widget/audio.html new file mode 100644 index 0000000..9fbe3f3 --- /dev/null +++ b/web/widget/audio.html @@ -0,0 +1,6 @@ +<!-- + Copyright (c) 2012-2015 Kaarle Ritvanen + See LICENSE file for license details +--> + +<aconf-audio></aconf-audio> diff --git a/web/widget/audio.js b/web/widget/audio.js deleted file mode 100644 index 99e410d..0000000 --- a/web/widget/audio.js +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2012-2014 Kaarle Ritvanen - * See LICENSE file for license details - */ - -define( - ["aconf/dom", "aconf/widget/abstract/inline", "jquery", "underscore"], - function(dom, Base, $, _) { - return Base.extend({ - render: function(value, meta) { - if (!value) return; - - var self = this; - - this.el.html(_.isObject(value) ? $("<audio>").attr( - {src: value.data, autoplay: true, controls: true} - ) : dom.href().text("Play").click(function() { - self.refresh(); - })); - } - }); - } -); diff --git a/web/widget/checkbox.html b/web/widget/checkbox.html new file mode 100644 index 0000000..2f52ca4 --- /dev/null +++ b/web/widget/checkbox.html @@ -0,0 +1,17 @@ +<!-- + Copyright (c) 2012-2015 Kaarle Ritvanen + See LICENSE file for license details +--> + +<div ng-if="!field.editable"> + <label ng-if="field.label">{{ field.label }}</label> + <div ng-if="!value">No</div> + <div ng-if="value">Yes</div> +</div> +<div ng-if="field.editable" class="checkbox"> + <label> + <input type="checkbox" class="aconf-sync" name="{{ name }}" ng-model="value"> + <div class="checkbox-changed" ng-if="!field.label">[changed]</div> + {{ field.label }} + </label> +</div> diff --git a/web/widget/checkbox.js b/web/widget/checkbox.js deleted file mode 100644 index 7be08db..0000000 --- a/web/widget/checkbox.js +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2012-2014 Kaarle Ritvanen - * See LICENSE file for license details - */ - -define(["aconf/widget/field", "jquery"], function(Base, $) { - return Base.extend({ - staticRender: function(value, meta) { - return $("<td>").text(value ? "Yes" : "No"); - }, - - statusEl: function() { return this.el.parent(); }, - - render: function(value, meta) { - this.field.attr("type", "checkbox"); - if (value) this.field.attr("checked", "true"); - }, - - get: function() { return this.field.is(":checked"); } - }); -}); diff --git a/web/widget/checkboxes.html b/web/widget/checkboxes.html new file mode 100644 index 0000000..8323dad --- /dev/null +++ b/web/widget/checkboxes.html @@ -0,0 +1,8 @@ +<!-- + Copyright (c) 2012-2015 Kaarle Ritvanen + See LICENSE file for license details +--> + +<aconf-inline> + <aconf-header></aconf-header><aconf-checkboxes></aconf-checkboxes> +</aconf-inline> diff --git a/web/widget/checkboxes.js b/web/widget/checkboxes.js deleted file mode 100644 index 5bafd77..0000000 --- a/web/widget/checkboxes.js +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2012-2014 Kaarle Ritvanen - * See LICENSE file for license details - */ - -define( - [ - "aconf/dom", - "aconf/statusbar", - "aconf/widget/abstract/node", - "jquery", - "underscore" - ], - function(dom, statusBar, Base, $, _) { - return Base.extend({ - showStatus: true, - - setStatus: function(status) { - Base.setStatus.call( - this, status == "invalid" ? "invalid" : null - ); - }, - - render: function(data, meta) { - this.dynamic = meta.members.dynamic; - - Base.render.call(this, data, meta); - - var table = $("<tbody>"); - this.el.append($("<table>").html(table)); - - var self = this; - - _.each(meta.members.choice, function(choice) { - var selected = _.contains(data.data, choice.value); - if (!(choice.enabled || selected)) return; - - var cbox = $("<input>").attr("type", "checkbox"); - if (selected) cbox.attr("checked", "true"); - - var row = $("<tr>"); - row.append($("<td>").html(cbox)); - - var item = $("<td>"); - if (choice.ref) - item.html(dom.objectRef(choice.ref) - .text(choice["ui-value"])); - else item.text(choice["ui-value"]); - row.append(item); - - function setRowStatus() { - dom.setStatus(row, data.status(choice.value)); - } - setRowStatus(); - - cbox.change(function() { - ( - cbox.is(":checked") ? - data.add(choice.value) : - data.delete(choice.value) - ).done(function(txnValid) { - self.setStatus(data.status()); - setRowStatus(); - statusBar.validationReady(txnValid); - }); - }); - - table.append(row); - }); - } - }); - } -); diff --git a/web/widget/combobox.html b/web/widget/combobox.html new file mode 100644 index 0000000..1d48938 --- /dev/null +++ b/web/widget/combobox.html @@ -0,0 +1,18 @@ +<!-- + Copyright (c) 2012-2015 Kaarle Ritvanen + See LICENSE file for license details +--> + +<label for="{{ name }}" class="control-label" ng-if="field.label"> + {{ field.label }} +</label> +<div ng-if="!field.editable"> + <div ng-repeat="choice in field.meta.choice" ng-if="choice.value == value"> + {{ choice["ui-value"] }} + </div> + <aconf-del-button></aconf-del-button> +</div> +<div ng-if="field.editable"> + <aconf-error></aconf-error> + <aconf-input><aconf-select></aconf-select></aconf-input> +</div> diff --git a/web/widget/combobox.js b/web/widget/combobox.js deleted file mode 100644 index e1759ad..0000000 --- a/web/widget/combobox.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2012-2014 Kaarle Ritvanen - * See LICENSE file for license details - */ - -define(["aconf/widget/field", "jquery", "underscore"], function(Base, $, _) { - return Base.extend({ - createEl: function() { return $("<select>"); }, - - staticRender: function(value, meta) { - return Base.staticRender.call( - this, - value ? _.findWhere( - meta.choice, {value: value} - )["ui-value"] : "", - meta - ); - }, - - render: function(value, meta) { - var el = this.field.empty(); - - function opt(value, ui_value, selected) { - var option = $("<option>").attr("value", value).text(ui_value); - if (selected) option.attr("selected", "true"); - el.append(option); - } - - 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); - } - ); - } - }); -}); diff --git a/web/widget/date.html b/web/widget/date.html new file mode 100644 index 0000000..4ef15c5 --- /dev/null +++ b/web/widget/date.html @@ -0,0 +1,6 @@ +<!-- + Copyright (c) 2012-2015 Kaarle Ritvanen + See LICENSE file for license details +--> + +<aconf-basic-input><aconf-date></aconf-date></aconf-basic-input> diff --git a/web/widget/date.js b/web/widget/date.js deleted file mode 100644 index 23c8fe0..0000000 --- a/web/widget/date.js +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2012-2014 Kaarle Ritvanen - * See LICENSE file for license details - */ - -define(["aconf/widget/field", "jquery-ui/datepicker"], function(Base) { - return Base.extend({ - createEl: function() { - return Base.createEl.call(this) - .datepicker({dateFormat: "yy-mm-dd"}); - } - }); -}); diff --git a/web/widget/field.html b/web/widget/field.html new file mode 100644 index 0000000..44ad4ee --- /dev/null +++ b/web/widget/field.html @@ -0,0 +1,11 @@ +<!-- + Copyright (c) 2012-2015 Kaarle Ritvanen + See LICENSE file for license details +--> + +<aconf-basic-input> + <input type="text" + class="form-control aconf-sync" + name="{{ name }}" + ng-model="value"> +</aconf-basic-input> diff --git a/web/widget/field.js b/web/widget/field.js deleted file mode 100644 index d54d504..0000000 --- a/web/widget/field.js +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2012-2014 Kaarle Ritvanen - * See LICENSE file for license details - */ - -define( - [ - "aconf/dom", - "aconf/error", - "aconf/statusbar", - "aconf/widget/abstract/base", - "jquery", - "underscore" - ], - function(dom, formatError, statusBar, Base, $, _) { - return Base.extend({ - init: function( - data, name, meta, level, editable, removable - ) { - this.editable = editable && meta.editable; - - var el = Base.init.call( - this, - data, - name, - meta, - level, - editable, - removable - ); - - if (this.editable) - this.field.change(_.bind(this.validateChange, this)); - - return el; - }, - - staticRender: function(value, meta) { - return $("<td>").text(value == null ? "" : value); - }, - - makeEl: function() { - Base.makeEl.call(this); - if (!this.field) this.field = this.el; - }, - - createEl: function() { return $("<input>"); }, - - render: function(value, meta) { - this.field.attr({type: "text", value: value}); - }, - - wrap: function() { - var td = $("<td>"); - this.msg = $("<div>"); - td.append(this.msg); - td.append(this.el); - return td; - }, - - validate: function(value) { - Base.validate.call(this, value); - if (!this.visible || !this.editable) return; - this.validateChange(); - }, - - validateChange: function() { - this.msg.text("[checking]"); - statusBar.setError("Validating changes", "validate"); - - var self = this; - - this.data.set(this.name, this.get()) - .done(function(txnValid) { - self.msg.empty() - self.updateStatus(); - statusBar.validationReady(txnValid); - self.el.trigger("validated"); - - }) - .fail(function(xhr) { - dom.setText(self.msg, self.formatValidationError(xhr)); - self.setStatus("invalid"); - statusBar.validationReady(false); - }); - }, - - get: function() { - return this.editable ? - (this.field.val() || null) : this.data.get(this.name); - } - }); - } -); diff --git a/web/widget/inline.html b/web/widget/inline.html new file mode 100644 index 0000000..5930bb8 --- /dev/null +++ b/web/widget/inline.html @@ -0,0 +1,6 @@ +<!-- + Copyright (c) 2012-2015 Kaarle Ritvanen + See LICENSE file for license details +--> + +<aconf-fields path="value"></aconf-fields> diff --git a/web/widget/inline.js b/web/widget/inline.js deleted file mode 100644 index 4f66e54..0000000 --- a/web/widget/inline.js +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2012-2015 Kaarle Ritvanen - * See LICENSE file for license details - */ - -define( - [ - "aconf/dom", - "aconf/statusbar", - "aconf/type", - "aconf/widget/abstract/fields", - "jquery", - "underscore", - "jquery-ui/sortable" - ], - function(dom, statusBar, type, Base, $, _) { - return Base.extend({ - wrap: function() { return $("<div>").html(this.el); }, - - render: function(data, meta) { - this.div = $("<div>"); - - Base.render.call(this, data, meta); - - this.el.append(this.div); - - if (meta.editable && type.isCollection(meta)) { - if (!this.table) this.makeSortable(this.div); - - var self = this; - - var button = dom.button("Insert", function() { - - var getter, row; - - function insert() { - var name = getter(); - var set = meta.type == "set"; - - if (set ? _.contains(data.data, name) : - name in data.data) { - - statusBar.setError( - "Already exists: " + name, "txn" - ); - return; - } - - function render(txnValid) { - statusBar.validationReady(txnValid); - if (row) row.remove(); - return self.renderCollectionMember(name, meta); - } - - var task; - if (type.isTreeNode(meta.members)) - task = data.set(name, {}); - else if (set) task = data.add(name); - - if (task) - task.done(function(txnValid) { - render(txnValid); - button.show(); - }).fail(function(xhr) { - statusBar.setError( - self.formatValidationError(xhr), "txn" - ); - data.delete(name); - }); - - else data.set(name, null).always(function() { - var widget = render(false); - function handler(event) { - button.show(); - widget.off("validated", handler); - } - widget.on("validated", handler); - }); - } - - button.hide(); - - if (meta.type == "list") { - getter = function() { - return data.data.length + 1; - }; - insert(); - } - else { - var field = $("<input>").attr({type: "text"}) - .change(insert); - row = $("<tr>").html($("<td>").html(field)); - getter = function() { return field.val(); } - self.appendRow(row); - field.focus(); - } - }); - this.el.append($("<p>").html(button)); - } - }, - - addActionButton: function(label, action) { - this.div.append(dom.button(label, action)); - }, - - appendWidget: function(el, label) { - var self = this; - var description = el.data("description"); - - var labelTd = label ? $("<td>").text(label) : null; - if (labelTd) - el.on("hasDetails", function(event, path) { - labelTd.html(dom.objectRef(path).text(label)); - el.on("statusChanged", function(event, status) { - dom.setStatus(labelTd, status); - event.stopPropagation(); - }); - event.stopPropagation(); - }); - function prependLabel(el) { if (labelTd) el.prepend(labelTd); } - - el = dom.makeRow(el); - - if (el.is("tr")) { - prependLabel(el); - if (description) el.append($("<td>").text(description)); - this.appendRow(el); - } - else { - if (el.is("table")) { - this.makeSortable(el.find("tbody")); - var tr; - el.find("tr").each(function(index, row) { - tr = $(row); - tr.prepend($("<td>")); - }); - tr.children().first().remove(); - prependLabel(tr); - this.table = el; - } - else this.table = null; - this.div.append(el); - } - - return el; - }, - - appendRow: function(row) { - if (!this.table) { - this.table = this.makeSortable($("<tbody>")); - this.div.append($("<table>").html(this.table)); - } - this.table.append(row); - }, - - makeSortable: function(el) { - var data = this.reqData; - - if (data.meta.type == "list" && data.meta.editable) - el.sortable({ - start: function(event, ui) { - $(":focus").change(); - ui.item.data("index", ui.item.index()); - }, - stop: function(event, ui) { - if (!data.isSubtreeValid()) { - el.sortable("cancel"); - return; - } - - var oldIndex = ui.item.data("index") + 1; - var newIndex = ui.item.index() + 1; - if (newIndex != oldIndex) - data.move(oldIndex, newIndex) - .done(function(txnValid) { - $("#content").trigger("reload", [txnValid]); - }); - } - }); - return el; - } - }); - } -); diff --git a/web/widget/link.html b/web/widget/link.html new file mode 100644 index 0000000..750f76a --- /dev/null +++ b/web/widget/link.html @@ -0,0 +1,8 @@ +<!-- + Copyright (c) 2012-2015 Kaarle Ritvanen + See LICENSE file for license details +--> + +<aconf-link path="value" label="{{ field.label }}" status="status"> +</aconf-link> +<aconf-del-button></aconf-del-button> diff --git a/web/widget/link.js b/web/widget/link.js deleted file mode 100644 index f2094a8..0000000 --- a/web/widget/link.js +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2012-2014 Kaarle Ritvanen - * See LICENSE file for license details - */ - -define( - ["aconf/dom", "aconf/widget/abstract/base", "jquery"], - function(dom, Base, $) { - return Base.extend({ - staticRender: function(value, meta) { - return $("<td>").html(dom.objectRef(value)); - }, - - createEl: dom.href, - - render: function(value, meta) { dom.objectRef(value, this.el) }, - - wrap: function() { return $("<td>").html(this.el); }, - - get: function() { return {}; } - }); - } -); diff --git a/web/widget/reference.html b/web/widget/reference.html new file mode 100644 index 0000000..adca467 --- /dev/null +++ b/web/widget/reference.html @@ -0,0 +1,23 @@ +<!-- + Copyright (c) 2012-2015 Kaarle Ritvanen + See LICENSE file for license details +--> + +<label for="{{ name }}" class="control-label" ng-if="field.label"> + {{ field.label }} +</label> +<div ng-if="!field.editable"> + <div ng-repeat="choice in field.meta.choice" ng-if="choice.value == value"> + <a class="btn btn-default" + href="#/config{{ value }}">{{ choice["ui-value"] }}</a> + </div> + <aconf-del-button></aconf-del-button> +</div> +<div ng-if="field.editable"> + <aconf-error></aconf-error> + <fieldset class="form-inline"> + <aconf-select></aconf-select> + <a class="btn btn-default" ng-if="value" href="#/config{{ value }}">Show</a> + <aconf-del-button></aconf-del-button> + </fieldset> +</div> diff --git a/web/widget/reference.js b/web/widget/reference.js deleted file mode 100644 index 7c5a143..0000000 --- a/web/widget/reference.js +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2012-2014 Kaarle Ritvanen - * See LICENSE file for license details - */ - -define( - ["aconf/dom", "aconf/widget/combobox", "jquery", "underscore"], - function(dom, Base, $, _) { - return Base.extend({ - init: function( - data, name, meta, level, editable, removable - ) { - this.field = Base.createEl(); - return Base.init.call( - this, - data, - name, - meta, - level, - editable, - removable - ); - }, - - staticRender: function(value, meta) { - return $("<td>").html(dom.objectRef(value).text(value)); - }, - - statusEl: function() { return this.el.find("select"); }, - - createEl: function() { return $("<div>"); }, - - render: function(value, meta) { - Base.render.call(this, value, meta); - - this.el.html(this.field); - this.el.append(" "); - - var link = $("<div>"); - var update = _.bind(function() { - link.html(dom.objectRef(this.get())); - }, this); - this.el.append(link); - - this.field.change(update); - update(); - } - }); - } -); diff --git a/web/widget/table/header.js b/web/widget/table/header.js deleted file mode 100644 index e6683c1..0000000 --- a/web/widget/table/header.js +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2012-2014 Kaarle Ritvanen - * See LICENSE file for license details - */ - -define(["aconf/widget/table/row", "jquery"], function(Base, $) { - return Base.extend({ - init: function( - data, name, meta, level, editable, removable - ) { - this.header = $("<tr>"); - var table = $("<table>"); - table.append($("<thead>").html(this.header)); - table.append($("<tbody>").html( - Base.init.call( - this, - data, - name, - meta, - level, - editable, - removable - ) - )); - return table; - }, - - appendWidget: function(el, label) { - this.header.append($("<th>").text(label)); - return Base.appendWidget.call(this, el, label); - } - }); -}); diff --git a/web/widget/table/row.js b/web/widget/table/row.js deleted file mode 100644 index d563afb..0000000 --- a/web/widget/table/row.js +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2012-2014 Kaarle Ritvanen - * See LICENSE file for license details - */ - -define( - ["aconf/dom", "aconf/widget/abstract/fields", "jquery", "underscore"], - function(dom, Base, $, _) { - return Base.extend({ - createEl: function() { - this.prevAction = null; - this.prevWidget = null; - return $("<tr>").html($("<td>").addClass("placeholder")); - }, - - setStatus: function(status) { - this.wrapped.trigger("statusChanged", [status]); - }, - - showHeading: false, - - addActionButton: function(label, action) { - (this.prevAction ? - this.prevAction : this.el.find(".placeholder")).after( - $("<td>").html(dom.href().text(label).click(action)) - ); - }, - - createModelWidgets: function(fields, editable) { - Base.createModelWidgets.call(this, fields, editable); - - var self = this; - var tdFields = []; - _.each(fields, function(field) { - if (field.name in self.widgets && - self.widgets[field.name].is("td")) - tdFields.push(field); - }); - if (_.size(tdFields) == _.size(fields)) return; - - Base.createModelWidgets.call(this, tdFields, false); - this.wrapped.trigger("hasDetails", [this.path]); - }, - - createWidget: function(name, meta, editable, removable) { - if (!(meta.detail || meta.condition)) - return Base.createWidget.call( - this, name, meta, editable, removable - ); - }, - - appendWidget: function(el, label) { - if (this.prevWidget) this.prevWidget.after(el); - else { - var ph = this.el.find(".placeholder"); - ph.after(el); - ph.remove(); - } - this.prevWidget = el; - return el; - } - }); - } -); |