diff options
-rw-r--r-- | web/widget/abstract/fields.js | 15 | ||||
-rw-r--r-- | web/widget/inline.js | 24 | ||||
-rw-r--r-- | web/widget/table/row.js | 49 |
3 files changed, 46 insertions, 42 deletions
diff --git a/web/widget/abstract/fields.js b/web/widget/abstract/fields.js index ae7b5bf..1a442e5 100644 --- a/web/widget/abstract/fields.js +++ b/web/widget/abstract/fields.js @@ -22,12 +22,18 @@ define( render: function(data, meta) { Base.render.call(this, data, meta); - this.appendAboveFields(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.fields = {}; _.each(meta.fields, function(field) { if (field.visible) @@ -60,13 +66,8 @@ define( else if (_.isArray(data.data)) name++; self.renderCollectionMember(name, meta); }); - - this.appendBelowFields(data, meta); }, - appendAboveFields: function(data, meta) {}, - appendBelowFields: function(data, meta) {}, - renderField: function( name, meta, label, editable, removable ) { diff --git a/web/widget/inline.js b/web/widget/inline.js index e9fe068..08ac14c 100644 --- a/web/widget/inline.js +++ b/web/widget/inline.js @@ -17,25 +17,13 @@ define( return Base.extend({ wrap: function() { return $("<div>").html(this.el); }, - appendAboveFields: function(data, meta) { + render: function(data, meta) { this.div = $("<div>"); - this.el.append(this.div); - var self = this; - - if (meta.type == "model") - _.each(meta.actions, function(action) { - self.div.append( - dom.button(action["ui-name"], function() { - data.invoke(action.name) - .done(function() { alert("Done"); }) - .fail(function() { alert("Failed"); }); - }) - ); - }); - }, + Base.render.call(this, data, meta); + + this.el.append(this.div); - appendBelowFields: function(data, meta) { if (meta.editable && _.contains(["collection", "list"], meta.type)) { if (!this.table) this.makeSortable(this.div); @@ -95,6 +83,10 @@ define( } }, + addActionButton: function(label, action) { + this.div.append(dom.button(label, action)); + }, + appendWidget: function(el, label, description) { var self = this; el = dom.makeRow(el); diff --git a/web/widget/table/row.js b/web/widget/table/row.js index 717b4da..69c116e 100644 --- a/web/widget/table/row.js +++ b/web/widget/table/row.js @@ -3,25 +3,36 @@ * See LICENSE file for license details */ -define(["acf2/widget/abstract/fields", "jquery"], function(Base, $) { - return Base.extend({ - createEl: function() { - this.previous = null; - return $("<tr>").html($("<td>").prop("class", "placeholder")); - }, +define( + ["acf2/dom", "acf2/widget/abstract/fields", "jquery"], + function(dom, Base, $) { + return Base.extend({ + createEl: function() { + this.prevAction = null; + this.prevWidget = null; + return $("<tr>").html($("<td>").prop("class", "placeholder")); + }, - showHeading: false, + showHeading: false, - appendWidget: function(el, label, description) { - if (!el.is("td")) return null; - if (this.previous) this.previous.after(el); - else { - var ph = this.el.find(".placeholder"); - ph.after(el); - ph.remove(); + addActionButton: function(label, action) { + (this.prevAction ? + this.prevAction : this.el.find(".placeholder")).after( + $("<td>").html(dom.href().text(label).click(action)) + ); + }, + + appendWidget: function(el, label, description) { + if (!el.is("td")) return null; + if (this.prevWidget) this.prevWidget.after(el); + else { + var ph = this.el.find(".placeholder"); + ph.after(el); + ph.remove(); + } + this.prevWidget = el; + return el; } - this.previous = el; - return el; - } - }); -}); + }); + } +); |