| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- (function ($) {
- var o = $.myflow;
- $.extend(true, o.editors, {
- inputEditor: function () {
- var d, _k, _div, _src, _r;
- this.init = function (a, k, b, c, r) {
- d = a;
- _k = k;
- _div = b;
- _src = c;
- _r = r;
- $('<input style="width:calc(100% - 6px);" title="' + (a[_k].title ? a[_k].title : '') + '"/>').val(a[_k].value).change(function () {
- a[_k].value = $(this).val()
- }).appendTo('#' + _div);
- $('#' + _div).data('editor', this)
- };
- this.destroy = function () {
- $('#' + _div + ' input').each(function () {
- d[_k].value = $(this).val()
- })
- }
- },
- selectEditor: function (i) {
- var j, _k, _div, _src, _r;
- this.init = function (d, k, e, f, r) {
- j = d;
- _k = k;
- _div = e;
- _src = f;
- _r = r;
- var g = $('<select style="width:100%;"/>').val(d[_k].value).change(function () {
- d[_k].value = $(this).val()
- }).appendTo('#' + _div);
- if (typeof i === 'string') {
- $.ajax({
- type: "GET",
- url: i,
- success: function (a) {
- var b = eval(a);
- if (b && b.length) {
- for (var c = 0; c < b.length; c++) {
- g.append('<option value="' + b[c].value + '">' + b[c].name + '</option>')
- };
- g.val(j[_k].value)
- }
- }
- })
- } else {
- for (var h = 0; h < i.length; h++) {
- g.append('<option value="' + i[h].value + '">' + i[h].name + '</option>')
- }
- g.val(j[_k].value)
- }
- $('#' + _div).data('editor', this)
- };
- this.destroy = function () {
- $('#' + _div + ' select').each(function () {
- j[_k].value = $(this).val()
- })
- }
- },
- tableEditor: function (h) {
- var j, _k, _div, _src, _r, _this = this;
- this.init = function (c, k, d, e, r) {
- j = c;
- _k = k;
- _div = d;
- _src = e;
- _r = r;
- var f = '<table id="children" style="width:calc(100% - 6px);" border="1" cellpadding="0" cellspacing="0"><tr>';
- for (var l in h) {
- f += '<th>' + h[l].label + '</th>'
- }
- f += '<th><button type="button" class="addrow" >+</button></th></tr></table>';
- $(f).appendTo('#' + _div).find(".addrow").click(function () {
- var a = '<tr class="item">';
- for (var l in h) {
- switch (h[l].type) {
- case 'input':
- a += '<td><input style="width:calc(100% - 6px);" class="' + h[l].name + '"/></td>';
- break;
- case 'select':
- a += '<td style="width:80px;"><select style="width:calc(100% - 6px);" class="' + h[l].name + '">';
- $(h[l].options).each(function (i, n) {
- a += '<option value="' + n.value + '">' + n.name + '</option>'
- });
- a += '</select></td>';
- break
- }
- };
- a += '<th><button type="button" class="delrow" >-</button></th></tr>';
- var b = $(a).appendTo('#children');
- b.find(".delrow").click(function () {
- $(this).parent().parent().remove();
- _this.destroy()
- });
- b.find('input').change(function () {
- _this.destroy()
- });
- b.find('select').change(function () {
- _this.destroy()
- });
- _this.destroy()
- });
- if (c[_k].value) {
- var g = JSON.parse(c[_k].value);
- $(g).each(function (i, n) {
- var a = '<tr class="item">';
- for (var l in h) {
- switch (h[l].type) {
- case 'input':
- a += '<td><input style="width:calc(100% - 6px);" class="' + h[l].name + '" value="' + n[h[l].name] + '"/></td>';
- break;
- case 'select':
- a += '<td style="width:80px;"><select style="width:calc(100% - 6px);" class="' + h[l].name + '">';
- $(h[l].options).each(function (i, m) {
- a += '<option value="' + m.value + '" ' + (m.value == n[h[l].name] ? 'selected' : '') + '>' + m.name + '</option>'
- });
- a += '</select></td>';
- break
- }
- };
- a += '<th><button type="button" class="delrow" >-</button></th></tr>';
- var b = $(a).appendTo('#children');
- b.find(".delrow").click(function () {
- $(this).parent().parent().remove();
- _this.destroy()
- });
- b.find('input').change(function () {
- _this.destroy()
- });
- b.find('select').change(function () {
- _this.destroy()
- })
- })
- };
- $('#' + _div).data('editor', this)
- };
- this.destroy = function () {
- var b = [];
- $('#' + _div + ' .item').each(function () {
- var a = {};
- for (var l in h) {
- a[h[l].name] = $(this).find("." + h[l].name).val()
- }
- b.push(a)
- });
- j[_k].value = JSON.stringify(b)
- }
- },
- })
- })(jQuery);
|