﻿(function (D) { var C = /\[([^\]]+)\]/g; var B = /<!--([\w\W]+)-->/g; var A = function (H) { var F; var E = []; var G = 0; H = H.replace(B, "$1"); if (H) { while ((F = C.exec(H)) != null) { if (G < H.length) { E.push(H.substring(G, F.index)) } E.push(F); G = F.index + F[0].length } F = E[E.length - 1]; if (G < H.length) { E.push(H.substring(G)) } } return E }; D.templater = function (E) { this.template = E }; window.templater = D.templater; D.templater.prototype = { bindData: function (J, H, K, G, E, F) { F = F || this; var I = []; this.processData(J, H, K, function (M, N, O, L) { if (G) { G.call(F, M, N, O, L) } I.push(N.join("")) }, E, F); return I.join("") }, processData: function (S, E, I, N, F, K) { K = K || this; if (!this.templateTree) { this.templateTree = A(this.template) } if (S && this.templateTree.length) { if (!D.isArray(S)) { S = [S] } for (var M = 0; M < S.length; M++) { var O = S[M]; var G = F || M; var H = []; var P = []; for (var J = 0; J < this.templateTree.length; J++) { var Q = this.templateTree[J]; P.push[Q[1]]; if (typeof Q === "string") { H.push(Q) } else { if (O[Q[1]] == undefined) { var L = false; if (I) { L = I.call(K, O, Q[1], Q[0], J, G) } if (L === false) { H.push(Q[0]) } else { H.push(L) } } else { var R = false; if (E) { R = E.call(K, O, Q[1], Q[0], J, G) } if (R === false) { H.push(O[Q[1]]) } else { H.push(R) } } } } if (N) { N.call(K, O, H, P, G) } } } } }; D.widget("lv.template", { options: { template: false, autoBind: true, jsonData: {}, itemBindCallback: false, unMatchCallback: false, rowBindCallback: false }, _create: function () { var E = this; if (!this.options.template) { this.template = this.element.html() } else { this.template = this.options.template } E.templater = new D.templater(this.template) }, _init: function () { var E = this; if (D.isFunction(this.options.jsonData)) { this.options.jsonData.call(this, function (F) { E.bindData(F) }) } else { this.dataSource = this.options.jsonData; if (this.options.autoBind) { this._render() } } }, _render: function () { this.element.html(this.templater.bindData(this.dataSource, this.options.itemBindCallback, this.options.unMatchCallback, this.options.rowBindCallback)) }, bindData: function (E) { this.dataSource = E; this._render() }, destroy: function () { D.Widget.prototype.destroy.call(this) } }) })(jQuery); (function (A) { A.widget("lv.repeater", { options: { autoBind: true, jsonData: {}, itemBindCallback: false, unMatchCallback: false, rowBindCallback: false, pager: true, templateSelector: { header: ">.header", footer: ">.footer", item: ">.item", alter: ">.alter", child: ">.child", pager: ">.pager"} }, _create: function () { this._mapTemplate(); if (!this.pagerTemplate) { this.pagerTemplate = A("<div/>") } }, _init: function () { var B = this; if (A.isFunction(this.options.jsonData)) { this.options.jsonData.call(this, function (C) { B.bindData(C) }) } else { this.bindData(this.options.jsonData) } }, _mapTemplate: function () { var B = this; var D = false; for (var C in this.options.templateSelector) { var E = A(this.options.templateSelector[C], B.element); if (E.size()) { D = true; if (C === "child" || C === "pager") { B[C + "Template"] = E.clone() } else { B[C + "Template"] = new A.templater(E.html()); B[C + "Template"].element = E } } } if (!D) { B.itemTemplate = new A.templater(B.element.html()) } }, _itemBindCallback: function (C, D, E, F, B) { if (D == "__child__" && this.childTemplate) { this.childTemplate.repeater({ jsonData: C[D] }); return this.childTemplate.html() } else { if (this.options.itemBindCallback) { return this.options.itemBindCallback(C, D, E, F, B) } else { return false } } }, _render: function () { var C = this; var D = []; if (this.headerTemplate) { D.push(this.headerTemplate.bindData(this.dataSource)) } if (this.dataSource.rows) { if (!this.alterTemplate) { if (this.itemTemplate) { D.push(this.itemTemplate.bindData(this.dataSource.rows, this._itemBindCallback, this.options.unMatchCallback, this.options.rowBindCallback, false, this)) } } else { for (var B = 0; B < this.dataSource.rows.length; B++) { if (B % 2 == 0) { D.push(this.itemTemplate.bindData(this.dataSource.rows[B], this._itemBindCallback, this.options.unMatchCallback, this.options.rowBindCallback, B, this)) } else { D.push(this.alterTemplate.bindData(this.dataSource.rows[B], this._itemBindCallback, this.options.unMatchCallback, this.options.rowBindCallback, B, this)) } } } } if (this.footerTemplate) { D.push(this.footerTemplate.bindData(this.dataSource)) } if (this.showPager) { this.pager = this.pagerTemplate.clone().pager(A.extend({}, this.dataSource.pager, { pageIndexChanged: function (E, F) { F.control = C; if (A.isFunction(C.options.jsonData)) { C.options.jsonData.call(C, function (G) { C.bindData(G); F.pager.active(F.index) }, F.index, F.pager.options.pageSize, F) } else { C._trigger("pageIndexChanged", E, F) } } })) } this.element.html(D.join("")); if (this.pager) { this.pager.appendTo(this.element) } }, _atachEvent: function () { }, _detachEvent: function () { }, bindData: function (B) { this.dataSource = B; this.showPager = this.options.pager && this.dataSource.pager; if (this.showPager) { this.pagerTemplate = this.pagerTemplate.template({ jsonData: A.extend({}, A.lv.pager.prototype.options, this.dataSource.pager) }) } this._render() }, destroy: function () { A.Widget.prototype.destroy.call(this); this._detachEvent() } }) })(jQuery); (function (A) { A.widget("lv.grid", A.lv.repeater, { options: { fixHeader: true, jScrollPane: true, jScrollPaneSetting: {}, rowsName: "rows", jsonData: { rows: []} }, _calMyHeight: function (B) { var D = B.parent().height(); var C = 0; B.siblings().each(function () { var E = A(this); if (E.css("position") != "absolute" && E.css("position") != "fixed") { C += E.outerHeight(true) } }); return D - C }, _create: function () { var B = this; A.extend(this.options.templateSelector, { header: ">thead", footer: ">tfoot", item: ">tbody>tr:first", alter: ">tbody>tr:eq(1)", child: false, pager: false }); if (!A(this.options.templateSelector.alter, this.element).size()) { this.options.templateSelector.item = ">tbody" } A.lv.repeater.prototype._create.apply(this); A(">tbody", this.element).empty(); this.options.fixHeader = this.options.fixHeader && parseInt(this.element.parent().css("height")); if (this.options.fixHeader) { this.innerWrapper = this.element.css({ "border-collapse": "collapse" }).wrap("<div><div/></div>").parent().addClass("ui-grid-inner").css({ "overflow": "auto" }); this.outerWrapper = this.innerWrapper.parent().css({ "position": "relative", "overflow": "hidden" }).addClass("ui-grid-outer"); this.container = this.outerWrapper.parent(); this.outerWrapper.css({ width: this.container.width() + "px", height: this._calMyHeight(this.outerWrapper) + "px" }); this.container.bind("resize-container", function () { if (!this.rendering) { B.fixHeader() } }); this.resizeWatcher = setInterval(function () { if (B.reszing) { return } B.reszing = true; B.size = B.size || { width: 0, height: 0 }; if (B.size.width != B.container.width() || B.size.height != B.container.height()) { B.size.width = B.container.width(); B.size.height = B.container.height(); B.container.trigger("resize-container") } B.reszing = false }, 100); this.fixedHeader = A("<div/>", { "class": "ui-grid-fixedHeader", "css": { position: "absolute", zIndex: "9", "background-color": "white", overflow: "hidden"} }).prependTo(this.outerWrapper).width(this.outerWrapper.width()); this.fixedHeader.html(this.element.clone()).height(this.element.children("thead").height()) } }, fixHeader: function () { var B = this; this.outerWrapper.css({ width: this.container.width() + "px", height: this._calMyHeight(this.outerWrapper) + "px" }); var D = A(".jScrollPaneContainer", this.outerWrapper); if (D.size()) { var C = D.width() - parseInt(this.innerWrapper.css("width")); this.innerWrapper.css("width", (this.outerWrapper.width() - C) + "px") } else { this.innerWrapper.css({ height: this._calMyHeight(this.innerWrapper) + "px" }) } if (D.size()) { D.css({ width: this.outerWrapper.width() + "px", height: this._calMyHeight(D) + "px" }); this.fixedHeader.width(this.innerWrapper.css("width")) } else { this.fixedHeader.width(this.element.outerWidth()) } if (A.fn.jScrollPane) { this.innerWrapper.jScrollPane(this.options.jScrollPaneSetting) } }, _render: function () { var D = this; this.rendering = true; if (this.headerTemplate) { this.headerTemplate.element.html(this.headerTemplate.bindData(this.dataSource)) } if (this.dataSource[this.options.rowsName]) { if (!this.alterTemplate) { if (this.itemTemplate) { this.itemTemplate.element.html(this.itemTemplate.bindData(this.dataSource.rows, this._itemBindCallback, this.options.unMatchCallback, this.options.rowBindCallback, false, this)) } } else { var G = A(">tbody", this.element); var E = []; var B = this.itemTemplate.element.attr("class"); var H = this.alterTemplate.element.attr("class"); for (var C = 0; C < this.dataSource.rows.length; C++) { var F = ""; if (C % 2 == 0) { F = '<tr class="' + B + '">' + this.itemTemplate.bindData(this.dataSource.rows[C], this._itemBindCallback, this.options.unMatchCallback, this.options.rowBindCallback, C, this) + "</tr>" } else { F = '<tr class="' + H + '">' + this.alterTemplate.bindData(this.dataSource.rows[C], this._itemBindCallback, this.options.unMatchCallback, this.options.rowBindCallback, C, this) + "</tr>" } E.push(F) } G.html(E.join("")) } } if (this.footerTemplate) { this.footerTemplate.element.html(this.footerTemplate.bindData(this.dataSource)) } if (this.showPager) { this.pager = this.pagerTemplate.clone().pager(A.extend({}, this.dataSource.pager, { pageIndexChanged: function (I, J) { J.control = D; if (A.isFunction(D.options.jsonData)) { D.options.jsonData.call(D, function (K) { D.bindData(K); J.pager.active(J.index) }, J.index, J.pager.options.pageSize, J) } else { D._trigger("pageIndexChanged", I, J) } } })); if (!this.footer) { this.footer = A("<div class='lv-grid-foot'/>"); if (this.options.fixHeader) { this.footer.appendTo(this.outerWrapper) } else { this.footer.insertAfter(this.element) } } this.footer.html(this.pager) } this.rendering = false; if (this.options.fixHeader) { this.fixHeader(); this.innerWrapper.scrollTop(0); if (this.innerWrapper.height() < this.element.height()) { this.fixedHeader.show().find(">table>tbody").replaceWith(this.element.children("tbody").clone()) } else { this.fixedHeader.hide() } } } }) })(jQuery); (function (B) { var A = new B.templater('<option value="[value]">[text]</option>'); B.fn.bindData = function (C) { C = B.extend({ textField: "text", valueField: "value", dataSource: [] }, C || {}); var D = C.dataSource; this.each(function () { var F = B(this); if (F.is("select")) { for (var E = 0; E < D.length; E++) { F.append(A.bindData({ text: D[E][C.textField], value: D[E][C.valueField] })) } } }); return this } })(jQuery);
