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

62 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-06-07 00:45:47 +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) {
var ctl = $("#" + this.options.map[name]);
if (ctl.attr('data-toggle') == "dropdown") {
var val = value[name];
if ((typeof val == "string" && val == "") || val == undefined) val = ctl.attr('data-default-val');
2018-08-05 01:19:34 +08:00
ctl.text(ctl.parent().find('.dropdown-menu [data-val="' + val + '"]').text());
ctl.attr('data-val', val);
2018-06-07 00:45:47 +08:00
}
else if (ctl.attr('data-toggle') == 'toggle') {
ctl.bootstrapToggle(value[name] ? 'on' : 'off');
}
2018-08-05 01:19:34 +08:00
else ctl.val(value[name]);
2018-06-07 00:45:47 +08:00
}
},
reset: function () {
for (name in this.options.map) {
var ctl = $("#" + this.options.map[name]);
var dv = ctl.attr("data-default-val");
if (dv === undefined) dv = "";
if (ctl.attr('data-toggle') == "dropdown") {
2018-08-05 01:19:34 +08:00
ctl.text(ctl.parent().find('.dropdown-menu [data-val="' + dv + '"]').text());
2018-06-07 00:45:47 +08:00
}
else if (ctl.attr('data-toggle') == 'toggle') {
ctl.bootstrapToggle(dv == "true" ? 'on' : 'off');
}
2018-08-05 01:19:34 +08:00
else ctl.val(dv);
2018-06-07 00:45:47 +08:00
}
},
get: function () {
var target = {};
for (name in this.options.map) {
var ctl = $("#" + this.options.map[name]);
var dv = ctl.attr('data-default-val');
if (ctl.attr('data-toggle') == 'toggle') {
target[name] = ctl.prop('checked');
continue;
}
2018-08-05 01:19:34 +08:00
else if (ctl.attr('data-toggle') == 'dropdown') {
target[name] = ctl.attr('data-val');
continue;
}
2018-06-07 00:45:47 +08:00
else if (dv != undefined && ctl.val() == "") target[name] = dv;
else target[name] = ctl.val();
if (target[name] == "true" || target[name] == "True") target[name] = true;
if (target[name] == "false" || target[name] == "False") target[name] = false;
}
return target;
}
}
2016-10-20 17:55:29 +08:00
}(jQuery));