/*
* Copyright (c) 2012-2014 Kaarle Ritvanen
* See LICENSE file for license details
*/
define(
["acf2/statusbar", "acf2/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,
Math.min(6, level + 1),
editable,
removable
);
},
staticRender: function(value, meta) { return null; },
createEl: function() { return $("
"); },
showStatus: false,
requestData: function(value, meta) {
this.path = value;
return this.refreshData();
},
refreshData: function() {
var def = $.Deferred();
this.txnMgr.query(this.path).done(function(data) {
def.resolve(data, data.meta);
});
return def;
},
showHeading: true,
render: function(data, meta) {
if (this.showHeading)
this.el.html(
$("").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);
}
if (this.fields)
_.each(this.fields, function(field) {
field.trigger("updated");
});
}
});
}
);