BootstrapAdmin/Bootstrap.Admin/Content/js/longbow.dataentity.js

46 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-10-20 17:55:29 +08:00
(function ($) {
DataEntity = function (options) {
this.options = $.extend({ map: {} }, options);
};
DataEntity.VERSION = "1.0";
DataEntity.Author = "Argo Zhang";
DataEntity.Email = "argo@163.com";
DataEntity.prototype = {
load: function (value) {
for (name in this.options.map) {
2016-11-08 11:08:10 +08:00
var ctl = $("#" + this.options.map[name]);
ctl.val(value[name]);
if (ctl.attr('data-toggle') == "dropdown") {
2017-03-03 13:33:49 +08:00
var val = value[name];
2017-03-13 23:17:25 +08:00
if ((typeof val == "string" && val == "") || val == undefined) val = ctl.attr('data-default-val');
2017-03-03 13:33:49 +08:00
ctl.children(':first').text(ctl.next().find('[data-val="' + val + '"]').text());
}
2016-10-20 17:55:29 +08:00
}
},
reset: function () {
for (name in this.options.map) {
2016-11-08 16:31:23 +08:00
var ctl = $("#" + this.options.map[name]);
var dv = ctl.attr("data-default-val");
if (dv === undefined) dv = "";
ctl.val(dv);
if (ctl.attr('data-toggle') == "dropdown") {
ctl.children(':first').text(ctl.next().find('[data-val="' + dv + '"]').text());
}
2016-10-20 17:55:29 +08:00
}
},
get: function () {
var target = {};
for (name in this.options.map) {
2016-11-08 16:31:23 +08:00
var ctl = $("#" + this.options.map[name]);
var dv = ctl.attr('data-default-val');
2017-03-13 23:17:25 +08:00
if (dv != undefined && ctl.val() == "") target[name] = dv;
else target[name] = ctl.val();
2017-03-13 23:17:25 +08:00
if (target[name] == "true" || target[name] == "True") target[name] = true;
if (target[name] == "false" || target[name] == "False") target[name] = false;
2016-10-20 17:55:29 +08:00
}
return target;
}
}
}(jQuery));