ligerOverwrite.js 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783
  1. /**
  2. * ligerUI BUG修复和重写
  3. */
  4. (function ($, win) {
  5. /***************** 字典相关扩展 *************************/
  6. //字典数据
  7. $.ehrDict = {
  8. dictDataUrl: window.root + "/basedict/getDict", //字典数据获取路径
  9. dictCodeName: "code", //字典code字段
  10. dictValueName: "value", //字典Value字段
  11. dictExtendName: "extend", //字典扩展字段
  12. sysDict: {}, //系统字典
  13. orgDict: {}, //机构字典
  14. stdDitc: {}, //标准字典
  15. //后台加载数据
  16. loadDictData: function (dictName, type, where, callBack) {
  17. var me = this;
  18. $.post(
  19. me.dictDataUrl,
  20. {type: type, name: dictName, where: where},
  21. function (data, status) {
  22. try {
  23. if (data.successFlg) {
  24. var list = data.detailModelList;
  25. if (type == "1") //机构字典
  26. {
  27. me.orgDict[dictName] = list;
  28. }
  29. else if (type == "2") { //标准字典
  30. me.stdDitc[dictName] = list;
  31. }
  32. else { //系统字典
  33. me.sysDict[dictName] = list;
  34. }
  35. if ($.isFunction(callBack)) {
  36. callBack(me.listToDict(list));
  37. }
  38. }
  39. }
  40. catch (e) {
  41. return;
  42. }
  43. });
  44. },
  45. //格式转化
  46. listToDict: function (list) {
  47. var me = this;
  48. var dictItem = {};
  49. for (var item in list) {
  50. dictItem[list[item][me.dictCodeName]] = {
  51. value: list[item][me.dictValueName],
  52. extend: list[item][me.dictExtendName]
  53. };
  54. }
  55. return dictItem;
  56. },
  57. //获取字典数据
  58. getDictData: function (dictName, type, where, callBack) {
  59. var me = this;
  60. if (dictName != null && dictName.length > 0) {
  61. var re = null;
  62. if (type == "1") //机构字典
  63. {
  64. re = me.orgDict[dictName];
  65. }
  66. else if (type == "2") { //标准字典
  67. re = me.stdDitc[dictName];
  68. }
  69. else { //系统字典
  70. re = me.sysDict[dictName];
  71. }
  72. if (re != null) {
  73. if (re != "loading") {
  74. return re;
  75. }
  76. }
  77. else {
  78. if (type == "1") {
  79. me.orgDict[dictName] = "loading";
  80. }
  81. else if (type == "2") {
  82. me.stdDitc[dictName] = "loading";
  83. }
  84. else {
  85. me.sysDict[dictName] = "loading";
  86. }
  87. //加载数据
  88. me.loadDictData(dictName, type, where, callBack);
  89. }
  90. }
  91. return null;
  92. }
  93. };
  94. /******************************************************/
  95. //重写条件选择控件 add by hzp at 20160119
  96. $.extend($.ligerui.controls.Filter.prototype, {
  97. getValue: function () {
  98. var me = this;
  99. var options = me.options;
  100. var datas = me.getData();
  101. return datas;
  102. }
  103. });
  104. //重写下拉控件 add by hzp at 20160108
  105. $.extend($.ligerDefaults.ComboBox, {
  106. selectBoxWidth: 240,
  107. resize: false,
  108. valueField: 'code',
  109. textField: 'value',
  110. extendField: 'extend',
  111. dataParmName: 'detailModelList',
  112. dict: false, //是否下拉字典控件
  113. dictName: null, //字典名称
  114. dictType: null, //1机构字典 2标准字典 默认系统字典
  115. dictWhere: "" //表字典附加SQL条件
  116. });
  117. $.extend($.ligerui.controls.ComboBox.prototype, {
  118. _setUrl: function (url, callback) {
  119. var g = this, p = this.options;
  120. /****************** 下拉字典 ***********************/
  121. if (p.dict) {
  122. var dict = $.ehrDict.getDictData(p.dictName, p.dictType, p.dictWhere);
  123. if (dict != null) {
  124. g.setData(dict);
  125. return;
  126. }
  127. else {
  128. p.url = url = $.ehrDict.dictDataUrl;
  129. p.urlParms = {name: p.dictName, type: p.dictType, where: p.dictWhere};
  130. }
  131. }
  132. /***************************************************/
  133. if (!url) return;
  134. if (p.readonly) //只读状态不加载数据
  135. {
  136. return;
  137. }
  138. if (p.delayLoad && !g.isAccessDelay && !g.triggerLoaded) {
  139. g.isAccessDelay = true;//已经有一次延时加载了
  140. return;
  141. }
  142. url = $.isFunction(url) ? url.call(g) : url;
  143. var urlParms = $.isFunction(p.urlParms) ? p.urlParms.call(g) : p.urlParms;
  144. if (urlParms) {
  145. for (name in urlParms) {
  146. url += url.indexOf('?') == -1 ? "?" : "&";
  147. url += name + "=" + urlParms[name];
  148. }
  149. }
  150. var parms = $.isFunction(p.parms) ? p.parms.call(g) : p.parms;
  151. if (p.ajaxContentType == "application/json" && typeof (parms) != "string") {
  152. parms = liger.toJSON(parms);
  153. }
  154. var ajaxOp = {
  155. type: p.ajaxType,
  156. url: url,
  157. data: parms,
  158. cache: false,
  159. dataType: 'json',
  160. beforeSend: p.ajaxBeforeSend,
  161. complete: p.ajaxComplete,
  162. success: function (result) {
  163. var data = $.isFunction(p.dataGetter) ? data = p.dataGetter.call(g, result) : result;
  164. data = p.dataParmName && data ? data[p.dataParmName] : data;
  165. if (g.trigger('beforeSetData', [data]) == false) {
  166. return;
  167. }
  168. g.setData(data);
  169. g.trigger('success', [data]);
  170. if ($.isFunction(callback)) callback(data);
  171. },
  172. error: function (XMLHttpRequest, textStatus) {
  173. g.trigger('error', [XMLHttpRequest, textStatus]);
  174. }
  175. };
  176. if (p.ajaxContentType) {
  177. ajaxOp.contentType = p.ajaxContentType;
  178. }
  179. $.ajax(ajaxOp);
  180. },
  181. /***** 获取选中BUG修复 add by hzp at 20160224 **************/
  182. getSelected:function(){
  183. if(this.selected!=null)
  184. {
  185. return this.selected;
  186. }
  187. else{
  188. var me = this;
  189. var options = me.options;
  190. var selected = me.selectedValue;
  191. for (var i = 0; i < me.data.length; i++) {
  192. var item = me.data[i];
  193. if (item[options.valueField] == selected) {
  194. return item;
  195. }
  196. }
  197. }
  198. },
  199. _setDisabled: function (value)
  200. {
  201. //禁用样式
  202. if (value)
  203. {
  204. this.wrapper.addClass('l-text-disabled');
  205. $(".l-trigger-cancel").remove();
  206. } else
  207. {
  208. this.wrapper.removeClass('l-text-disabled');
  209. }
  210. },
  211. //获取扩展字段
  212. getExtendValue: function () {
  213. try {
  214. var me = this;
  215. var options = me.options;
  216. var selected = me.selectedValue;
  217. for (var i = 0; i < me.data.length; i++) {
  218. var item = me.data[i];
  219. if (item[options.valueField] == selected) {
  220. return item[options.extendField];
  221. }
  222. }
  223. }
  224. catch (e) {
  225. return "";
  226. }
  227. }
  228. });
  229. //重写Grid控件 add by hzp at 20160107
  230. $.extend($.ligerDefaults.Grid, {
  231. // 存储总记录数的字段名
  232. record: 'totalCount',
  233. // 数据源字段名
  234. root: 'detailModelList',
  235. // 每页记录数
  236. pageSize: 20,
  237. // 页记录数参数名,(提交给服务器)
  238. pagesizeParmName: 'rows',
  239. // 高度补差,当设置height:100%时,可能会有高度的误差,可以通过这个属性调整
  240. heightDiff: -14,
  241. height: '100%',
  242. // 是否显示行序号
  243. rownumbers: true,
  244. // 表头行的高度
  245. headerRowHeight: 40,
  246. // 行的高度
  247. rowHeight: 40,
  248. // 编辑器位置误差调整
  249. editorTopDiff: 1,
  250. allowAdjustColWidth: true
  251. });
  252. $.extend($.ligerui.controls.Grid.prototype, {
  253. _setHeight: function (h) {
  254. var g = this, p = this.options;
  255. g.unbind("SysGridHeightChanged");
  256. if (h == "auto")
  257. {
  258. g.bind("SysGridHeightChanged", function ()
  259. {
  260. if (g.enabledFrozen())
  261. g.gridview.height(Math.max(g.gridview1.height(), g.gridview2.height()));
  262. });
  263. return;
  264. }
  265. h = g._calculateGridBodyHeight(h);
  266. if (h > 0)
  267. {
  268. g.gridbody.height(h);
  269. if (p.frozen)
  270. {
  271. /*** 滚动条样式修改 add by hzp at 20160215***/
  272. //解决冻结列和活动列由上至下滚动错位的问题
  273. var w = g.gridbody.width(), w2 = $(":first-child", g.gridbody).width();
  274. if (w2 && (w2 + 6 >= w))
  275. {
  276. if (h > 6)
  277. g.f.gridbody.height(h - 6);
  278. } else
  279. {
  280. g.f.gridbody.height(h);
  281. }
  282. /********************************************/
  283. }
  284. /** 列表高度计算bug修改 **/
  285. var gridHeaderHeight = (p.headerRowHeight+1) * (g._columnMaxLevel - 1) + p.headerRowHeight + 1;
  286. /***********************/
  287. g.gridview.height(h + gridHeaderHeight);
  288. }
  289. g._updateHorizontalScrollStatus.ligerDefer(g, 10);
  290. },
  291. _calculateGridBodyHeight: function (h) {
  292. var g = this, p = this.options;
  293. if (typeof h == "string" && h.indexOf('%') > 0) {
  294. if (p.inWindow)
  295. h = $(window).height() * parseInt(h) * 0.01;
  296. else
  297. h = g.grid.parent().height() * parseInt(h) * 0.01;
  298. }
  299. if (p.title) h -= 24;
  300. /*** 隐藏分页 高度BUG修复 add by hzp at20160121 **/
  301. if (p.usePager && (p.pagerRender || !p.scrollToPage)) h -= g.toolbar.outerHeight();
  302. /******************************/
  303. if (p.totalRender) h -= 25;
  304. if (p.toolbar) h -= g.topbar.outerHeight();
  305. /** 列表高度计算bug修改 **/
  306. var gridHeaderHeight = (p.headerRowHeight+1) * (g._columnMaxLevel - 1) + p.headerRowHeight + 1;
  307. /***********************/
  308. h -= (gridHeaderHeight || 0);
  309. return h;
  310. },
  311. getColumns: function (columnLevel) {
  312. var g = this, p = this.options;
  313. var columns = [];
  314. for (var id in g._columns) {
  315. var col = g._columns[id];
  316. /********* 字典列翻译 ***********/
  317. if (col['dict']) {
  318. var dictName = col.dictName;
  319. //提前加载字典
  320. $.ehrDict.getDictData(dictName, col.dictType, col.dictWhere);
  321. //渲染字典字段
  322. col.render = function (row, index, data, _col) {
  323. var dict = $.ehrDict.getDictData(_col.dictName, col.dictType, col.dictWhere, function (response) {
  324. g.refreshColumn(_col.dictName, response);
  325. });
  326. if (dict != null) {
  327. if (dict[data] != null) {
  328. return dict[data].value;
  329. }
  330. else {
  331. return data;
  332. }
  333. }
  334. else {
  335. return "";
  336. }
  337. }
  338. }
  339. /********************/
  340. if (columnLevel != undefined) {
  341. if (col['__level'] == columnLevel) columns.push(col);
  342. }
  343. else {
  344. if (col['__leaf']) columns.push(col);
  345. }
  346. }
  347. return columns;
  348. },
  349. //字典返回后刷新列值
  350. refreshColumn: function (dictName, dict) {
  351. try {
  352. var me = this;
  353. for (var i = 0; i < me.columns.length; i++) {
  354. var col = me.columns[i];
  355. if (col.dict && col.dictName == dictName) {
  356. var colName = col.columnname;
  357. $.each($.find("td[id$='|" + col.__id + "']", me.gridbody[0]), function (index, obj) {
  358. var code = me.rows[index][colName];
  359. var cell = $.find("div.l-grid-row-cell-inner", obj)[0];
  360. if (dict[code] != null) {
  361. var val = dict[code].value;
  362. if (val != undefined && val != null) {
  363. $(cell).html(val);
  364. }
  365. }
  366. else {
  367. $(cell).html(code);
  368. }
  369. });
  370. }
  371. }
  372. }
  373. catch (e) {
  374. return;
  375. }
  376. },
  377. queryByText: function (filedName, text) {
  378. var data = this.data.detailModelList;
  379. for (var i = 0; i < data.length; i++) {
  380. var obj=JSON.stringify(data[i]);
  381. var r = eval("("+obj+"." + filedName+")");
  382. if (r.indexOf(text) >= 0) {
  383. this.select(data[i]);
  384. break;
  385. }
  386. }
  387. }
  388. });
  389. //重写树函数 add by hzp at 20160107
  390. $.extend($.ligerDefaults.Tree, {
  391. checkbox:false,
  392. parentIcon:false,
  393. childIcon:false,
  394. treeLine:false
  395. });
  396. $.extend($.ligerui.controls.Tree.prototype, {
  397. _upadteTreeWidth: function ()
  398. {
  399. var g = this, p = this.options;
  400. var treeWidth = g.maxOutlineLevel * 22;
  401. if (p.checkbox) treeWidth += 22;
  402. if (p.parentIcon || p.childIcon) treeWidth += 22;
  403. treeWidth += p.nodeWidth;
  404. treeWidth = p.adjustToWidth? $(g.element).width(): treeWidth; // TODO [代码片段001][修复树宽度自适应问题][yezehua]
  405. g.tree.width(treeWidth);
  406. },
  407. getDataByID: function (id) {
  408. var g = this, p = this.options;
  409. var data = null;
  410. if (g.data && g.data.length) {
  411. return find(g.data);
  412. }
  413. function find(items) {
  414. for (var i = 0; i < items.length; i++) {
  415. var dataItem = items[i];
  416. if (dataItem[p.idFieldName] == id) return dataItem;
  417. if (dataItem.children && dataItem.children.length) {
  418. /*** BUG修复 ***/
  419. var pre = find(dataItem.children);
  420. if (pre != null) return pre;
  421. /*************/
  422. }
  423. }
  424. return null;
  425. }
  426. $("li", g.tree).each(function () {
  427. if (data) return;
  428. var treeitem = $(this);
  429. var treedataindex = parseInt(treeitem.attr("treedataindex"));
  430. var treenodedata = g._getDataNodeByTreeDataIndex(g.data, treedataindex);
  431. if (treenodedata[p.idFieldName].toString() == id.toString()) {
  432. data = treenodedata;
  433. }
  434. });
  435. return data;
  436. },
  437. /**
  438. * 扩展方法1:
  439. * queryByText: 根据名字找出树的节点,并且打开节点
  440. */
  441. queryByText: function (text) {
  442. var $g = this, p = this.options;
  443. var nodeText = $("span", $g.tree);
  444. for (var i = 0; i < nodeText.length; i++) {
  445. if ($(nodeText[i]).text().indexOf(text) >= 0) {
  446. var id = $(nodeText[i]).closest("li").attr("id");
  447. $g.expandNode(id);
  448. $g.selectNode(id);
  449. break;
  450. }
  451. }
  452. },
  453. /**
  454. * expandNode:根据id打开节点
  455. * @param id
  456. */
  457. expandNode: function (id) {
  458. var $li = $("#" + id, this.tree).closest("li");
  459. var outlinelevel = $li.attr("outlinelevel");
  460. for (var j = 0; j < outlinelevel; j++) {
  461. if (j == 0) {
  462. $li.parent().parent().children(".l-body").children(".l-expandable-close").removeClass("l-expandable-close").addClass("l-expandable-open");
  463. $li = $li.parent().show();
  464. } else {
  465. $li.parent().children(".l-body").children(".l-expandable-close").removeClass("l-expandable-close").addClass("l-expandable-open");
  466. $li = $li.parent().parent().show();
  467. }
  468. }
  469. },
  470. /**
  471. * 扩展方法2:子节点是否全选
  472. * @param treenodedata
  473. * @returns {boolean}
  474. */
  475. isIncomplete: function (treenodedata)
  476. {
  477. var str = JSON.stringify(treenodedata.children);
  478. return (str.indexOf('"ischecked":null')!=-1 || str.indexOf('"ischecked":false')!=-1)
  479. && str.indexOf('"ischecked":true')!=-1;
  480. },
  481. //根据data生成最终完整的tree html
  482. _getTreeHTMLByData: function (data, outlineLevel, isLast, isExpand)
  483. {
  484. var g = this, p = this.options;
  485. if (g.maxOutlineLevel < outlineLevel)
  486. g.maxOutlineLevel = outlineLevel;
  487. isLast = isLast || [];
  488. outlineLevel = outlineLevel || 1;
  489. var treehtmlarr = [];
  490. if (!isExpand) treehtmlarr.push('<ul class="l-children" style="display:none">');
  491. else treehtmlarr.push("<ul class='l-children'>");
  492. for (var i = 0; i < data.length; i++)
  493. {
  494. var o = data[i];
  495. var isFirst = i == 0;
  496. var isLastCurrent = i == data.length - 1;
  497. var delay = g._getDelay(o, outlineLevel);
  498. var isExpandCurrent = delay ? false : g._isExpand(o, outlineLevel);
  499. treehtmlarr.push('<li ');
  500. if (o.treedataindex != undefined)
  501. treehtmlarr.push('treedataindex="' + o.treedataindex + '" ');
  502. if (isExpandCurrent)
  503. treehtmlarr.push('isexpand=' + o.isexpand + ' ');
  504. treehtmlarr.push('outlinelevel=' + outlineLevel + ' ');
  505. //增加属性支持
  506. for (var j = 0; j < g.sysAttribute.length; j++)
  507. {
  508. if ($(this).attr(g.sysAttribute[j]))
  509. data[dataindex][g.sysAttribute[j]] = $(this).attr(g.sysAttribute[j]);
  510. }
  511. for (var j = 0; j < p.attribute.length; j++)
  512. {
  513. if (o[p.attribute[j]])
  514. treehtmlarr.push(p.attribute[j] + '="' + o[p.attribute[j]] + '" ');
  515. }
  516. //css class
  517. treehtmlarr.push('class="');
  518. isFirst && treehtmlarr.push('l-first ');
  519. isLastCurrent && treehtmlarr.push('l-last ');
  520. isFirst && isLastCurrent && treehtmlarr.push('l-onlychild ');
  521. treehtmlarr.push('"');
  522. treehtmlarr.push('>');
  523. treehtmlarr.push('<div class="l-body');
  524. if (p.selectable && p.selectable(o) == false)
  525. {
  526. treehtmlarr.push(' l-unselectable');
  527. }
  528. treehtmlarr.push('">');
  529. for (var k = 0; k <= outlineLevel - 2; k++)
  530. {
  531. if (isLast[k]) treehtmlarr.push('<div class="l-box"></div>');
  532. else treehtmlarr.push('<div class="l-box l-line"></div>');
  533. }
  534. if (g.hasChildren(o))
  535. {
  536. if (isExpandCurrent) treehtmlarr.push('<div class="l-box l-expandable-open"></div>');
  537. else treehtmlarr.push('<div class="l-box l-expandable-close"></div>');
  538. if (p.checkbox)
  539. {
  540. if (o.ischecked)
  541. treehtmlarr.push('<div class="l-box l-checkbox l-checkbox-checked"></div>');
  542. // TODO add by lincl start
  543. else if(g.isIncomplete(o))
  544. treehtmlarr.push('<div class="l-box l-checkbox l-checkbox-incomplete"></div>');
  545. // add by lincl end
  546. else
  547. treehtmlarr.push('<div class="l-box l-checkbox l-checkbox-unchecked"></div>');
  548. }
  549. if (p.parentIcon)
  550. {
  551. //node icon
  552. treehtmlarr.push('<div class="l-box l-tree-icon ');
  553. treehtmlarr.push(g._getParentNodeClassName(isExpandCurrent ? true : false) + " ");
  554. if (p.iconFieldName && o[p.iconFieldName])
  555. treehtmlarr.push('l-tree-icon-none');
  556. treehtmlarr.push('">');
  557. if (p.iconFieldName && o[p.iconFieldName])
  558. treehtmlarr.push('<img src="' + o[p.iconFieldName] + '" />');
  559. treehtmlarr.push('</div>');
  560. }
  561. }
  562. else
  563. {
  564. if (isLastCurrent) treehtmlarr.push('<div class="l-box l-note-last"></div>');
  565. else treehtmlarr.push('<div class="l-box l-note"></div>');
  566. if (p.checkbox)
  567. {
  568. if (o.ischecked)
  569. treehtmlarr.push('<div class="l-box l-checkbox l-checkbox-checked"></div>');
  570. else
  571. treehtmlarr.push('<div class="l-box l-checkbox l-checkbox-unchecked"></div>');
  572. }
  573. if (p.childIcon)
  574. {
  575. //node icon
  576. treehtmlarr.push('<div class="l-box l-tree-icon ');
  577. treehtmlarr.push(g._getChildNodeClassName() + " ");
  578. if (p.iconFieldName && o[p.iconFieldName])
  579. treehtmlarr.push('l-tree-icon-none');
  580. treehtmlarr.push('">');
  581. if (p.iconFieldName && o[p.iconFieldName])
  582. treehtmlarr.push('<img src="' + o[p.iconFieldName] + '" />');
  583. treehtmlarr.push('</div>');
  584. }
  585. }
  586. if (p.render)
  587. {
  588. //treehtmlarr.push('<span>' + p.render(o, o[p.textFieldName]) + '</span>');
  589. treehtmlarr.push('<span title="'+ o[p.textFieldName] +'">' + p.render(o, o[p.textFieldName]) + '</span>');
  590. } else
  591. {
  592. // treehtmlarr.push('<span>' + o[p.textFieldName] + '</span>');
  593. treehtmlarr.push('<span title="'+ o[p.textFieldName] +'">' + o[p.textFieldName] + '</span>');
  594. }
  595. treehtmlarr.push('</div>');
  596. if (g.hasChildren(o))
  597. {
  598. var isLastNew = [];
  599. for (var k = 0; k < isLast.length; k++)
  600. {
  601. isLastNew.push(isLast[k]);
  602. }
  603. isLastNew.push(isLastCurrent);
  604. if (delay)
  605. {
  606. if (delay == true)
  607. {
  608. g.toggleNodeCallbacks.push({
  609. data: o,
  610. callback: function (dom, o)
  611. {
  612. var content = g._getTreeHTMLByData(o.children, outlineLevel + 1, isLastNew, isExpandCurrent).join('');
  613. $(dom).append(content);
  614. $(">.l-children .l-body", dom).hover(function ()
  615. {
  616. $(this).addClass("l-over");
  617. }, function ()
  618. {
  619. $(this).removeClass("l-over");
  620. });
  621. g._removeToggleNodeCallback(o);
  622. }
  623. });
  624. }
  625. else if (delay.url)
  626. {
  627. (function (o, url, parms)
  628. {
  629. g.toggleNodeCallbacks.push({
  630. data: o,
  631. callback: function (dom, o)
  632. {
  633. g.loadData(dom, url, parms, {
  634. showLoading: function ()
  635. {
  636. $("div.l-expandable-close:first", dom).addClass("l-box-loading");
  637. },
  638. hideLoading: function ()
  639. {
  640. $("div.l-box-loading:first", dom).removeClass("l-box-loading");
  641. }
  642. });
  643. g._removeToggleNodeCallback(o);
  644. }
  645. });
  646. })(o, delay.url, delay.parms);
  647. }
  648. }
  649. else
  650. {
  651. treehtmlarr.push(g._getTreeHTMLByData(o.children, outlineLevel + 1, isLastNew, isExpandCurrent).join(''));
  652. }
  653. }
  654. treehtmlarr.push('</li>');
  655. }
  656. treehtmlarr.push("</ul>");
  657. return treehtmlarr;
  658. }
  659. });
  660. //重写radio方法 add by hzp at 20160107
  661. $.extend($.ligerui.controls.Radio.prototype, {
  662. setValue: function (val) {
  663. var name = this.element.name;
  664. $('input[name="' + name + '"]').each(function () {
  665. var typeObj = $(this).closest('.l-radio-wrapper').find('a.l-radio');
  666. if (this.value == val) {
  667. typeObj.addClass("l-radio-checked");
  668. this.checked = true;
  669. }
  670. else {
  671. typeObj.removeClass("l-radio-checked");
  672. this.checked = false;
  673. }
  674. });
  675. },
  676. getValue: function () {
  677. var name = this.element.name;
  678. var re = "";
  679. $('input[name="' + name + '"]').each(function () {
  680. if (this.checked) {
  681. re = this.value;
  682. return;
  683. }
  684. });
  685. return re;
  686. }
  687. });
  688. //重写CheckBox方法 add by hzp at 20160107
  689. $.extend($.ligerui.controls.CheckBox.prototype, {
  690. setValue: function (val) {
  691. var name = this.element.name;
  692. var vals = null;
  693. if (val != null && val.length > 0) {
  694. vals = val.split(',');
  695. }
  696. $('input[name="' + name + '"]').each(function () {
  697. var typeObj = $(this).closest('.l-checkbox-wrapper').find('a.l-checkbox');
  698. var isChecked = false;
  699. if (vals != null) {
  700. for (var i = 0; i < vals.length; i++) {
  701. if (this.value == vals[i]) {
  702. isChecked = true;
  703. }
  704. }
  705. }
  706. if (isChecked) {
  707. typeObj.addClass("l-checkbox-checked");
  708. this.checked = true;
  709. }
  710. else {
  711. typeObj.removeClass("l-checkbox-checked");
  712. this.checked = false;
  713. }
  714. });
  715. },
  716. getValue: function () {
  717. var name = this.element.name;
  718. var re = "";
  719. $('input[name="' + name + '"]').each(function () {
  720. if (this.checked) {
  721. re += this.value + ",";
  722. }
  723. });
  724. if (re.length > 0) {
  725. re = re.substr(0, re.length - 1);
  726. }
  727. return re;
  728. }
  729. });
  730. //重写时间控件方法 add by hzp at 20160107
  731. $.extend($.ligerDefaults.DateEditor,{
  732. format: "yyyy-MM-dd hh:mm:ss"
  733. });
  734. $.extend($.ligerui.controls.DateEditor.prototype, {
  735. getYear: function () {
  736. return this.currentDate.year;
  737. },
  738. getMonth: function () {
  739. return this.currentDate.month;
  740. },
  741. getDate: function () {
  742. return this.currentDate.date;
  743. },
  744. getHour: function () {
  745. return this.currentDate.hour;
  746. },
  747. getMinute: function () {
  748. return this.currentDate.minute;
  749. },
  750. _render: function ()
  751. {
  752. var g = this, p = this.options;
  753. /**** 增加秒显示 *****/
  754. if (!p.showTime && p.format.indexOf(" hh:mm:ss") > -1)
  755. p.format = p.format.replace(" hh:mm:ss", "");
  756. /********************/
  757. if (this.element.tagName.toLowerCase() != "input" || this.element.type != "text")
  758. return;
  759. g.inputText = $(this.element);
  760. if (!g.inputText.hasClass("l-text-field"))
  761. g.inputText.addClass("l-text-field");
  762. g.link = $('<div class="l-trigger"><div class="l-trigger-icon"></div></div>');
  763. g.text = g.inputText.wrap('<div class="l-text l-text-date"></div>').parent();
  764. g.text.append('<div class="l-text-l"></div><div class="l-text-r"></div>');
  765. g.text.append(g.link);
  766. //添加个包裹,
  767. g.textwrapper = g.text.wrap('<div class="l-text-wrapper"></div>').parent();
  768. var dateeditorHTML = "";
  769. dateeditorHTML += "<div class='l-box-dateeditor' style='display:none'>";
  770. dateeditorHTML += " <div class='l-box-dateeditor-header'>";
  771. dateeditorHTML += " <div class='l-box-dateeditor-header-btn l-box-dateeditor-header-prevyear'><span></span></div>";
  772. dateeditorHTML += " <div class='l-box-dateeditor-header-btn l-box-dateeditor-header-prevmonth'><span></span></div>";
  773. dateeditorHTML += " <div class='l-box-dateeditor-header-text'><a class='l-box-dateeditor-header-month'></a> , <a class='l-box-dateeditor-header-year'></a></div>";
  774. dateeditorHTML += " <div class='l-box-dateeditor-header-btn l-box-dateeditor-header-nextmonth'><span></span></div>";
  775. dateeditorHTML += " <div class='l-box-dateeditor-header-btn l-box-dateeditor-header-nextyear'><span></span></div>";
  776. dateeditorHTML += " </div>";
  777. dateeditorHTML += " <div class='l-box-dateeditor-body'>";
  778. dateeditorHTML += " <table cellpadding='0' cellspacing='0' border='0' class='l-box-dateeditor-calendar'>";
  779. dateeditorHTML += " <thead>";
  780. dateeditorHTML += " <tr><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td></tr>";
  781. dateeditorHTML += " </thead>";
  782. dateeditorHTML += " <tbody>";
  783. dateeditorHTML += " <tr class='l-first'><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td></tr><tr><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td></tr><tr><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td></tr><tr><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td></tr><tr><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td></tr><tr><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td><td align='center'></td></tr>";
  784. dateeditorHTML += " </tbody>";
  785. dateeditorHTML += " </table>";
  786. dateeditorHTML += " <ul class='l-box-dateeditor-monthselector'><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul>";
  787. dateeditorHTML += " <ul class='l-box-dateeditor-yearselector'><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul>";
  788. dateeditorHTML += " <ul class='l-box-dateeditor-hourselector'><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul>";
  789. dateeditorHTML += " <ul class='l-box-dateeditor-minuteselector'><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul>";
  790. dateeditorHTML += " </div>";
  791. dateeditorHTML += " <div class='l-box-dateeditor-toolbar'>";
  792. /**************** 添加“时间:”标识 add by hzp at 20160217 *********/
  793. dateeditorHTML += " <div class='l-box-dateeditor-time'>时间:</div>";
  794. /********************************************************/
  795. dateeditorHTML += " <div class='l-button l-button-today'></div>";
  796. dateeditorHTML += " <div class='l-button l-button-close'></div>";
  797. dateeditorHTML += " <div class='l-clear'></div>";
  798. dateeditorHTML += " </div>";
  799. dateeditorHTML += "</div>";
  800. g.dateeditor = $(dateeditorHTML);
  801. if (p.absolute)
  802. g.dateeditor.appendTo('body').addClass("l-box-dateeditor-absolute");
  803. else
  804. g.textwrapper.append(g.dateeditor);
  805. g.header = $(".l-box-dateeditor-header", g.dateeditor);
  806. g.body = $(".l-box-dateeditor-body", g.dateeditor);
  807. g.toolbar = $(".l-box-dateeditor-toolbar", g.dateeditor);
  808. g.body.thead = $("thead", g.body);
  809. g.body.tbody = $("tbody", g.body);
  810. g.body.monthselector = $(".l-box-dateeditor-monthselector", g.body);
  811. g.body.yearselector = $(".l-box-dateeditor-yearselector", g.body);
  812. g.body.hourselector = $(".l-box-dateeditor-hourselector", g.body);
  813. g.body.minuteselector = $(".l-box-dateeditor-minuteselector", g.body);
  814. g.toolbar.time = $(".l-box-dateeditor-time", g.toolbar);
  815. g.toolbar.time.hour = $("<a></a>");
  816. g.toolbar.time.minute = $("<a></a>");
  817. g.buttons = {
  818. btnPrevYear: $(".l-box-dateeditor-header-prevyear", g.header),
  819. btnNextYear: $(".l-box-dateeditor-header-nextyear", g.header),
  820. btnPrevMonth: $(".l-box-dateeditor-header-prevmonth", g.header),
  821. btnNextMonth: $(".l-box-dateeditor-header-nextmonth", g.header),
  822. btnYear: $(".l-box-dateeditor-header-year", g.header),
  823. btnMonth: $(".l-box-dateeditor-header-month", g.header),
  824. btnToday: $(".l-button-today", g.toolbar),
  825. btnClose: $(".l-button-close", g.toolbar)
  826. };
  827. var nowDate = new Date();
  828. g.now = {
  829. year: nowDate.getFullYear(),
  830. month: nowDate.getMonth() + 1, //注意这里
  831. day: nowDate.getDay(),
  832. date: nowDate.getDate(),
  833. hour: nowDate.getHours(),
  834. minute: nowDate.getMinutes()
  835. };
  836. //当前的时间
  837. g.currentDate = {
  838. year: nowDate.getFullYear(),
  839. month: nowDate.getMonth() + 1,
  840. day: nowDate.getDay(),
  841. date: nowDate.getDate(),
  842. hour: nowDate.getHours(),
  843. minute: nowDate.getMinutes()
  844. };
  845. //选择的时间
  846. g.selectedDate = null;
  847. //使用的时间
  848. g.usedDate = null;
  849. //初始化数据
  850. //设置周日至周六
  851. $("td", g.body.thead).each(function (i, td)
  852. {
  853. $(td).html(p.dayMessage[i]);
  854. });
  855. //设置一月到十一二月
  856. $("li", g.body.monthselector).each(function (i, li)
  857. {
  858. $(li).html(p.monthMessage[i]);
  859. });
  860. //设置按钮
  861. g.buttons.btnToday.html(p.todayMessage);
  862. g.buttons.btnClose.html(p.closeMessage);
  863. //设置时间
  864. if (p.showTime)
  865. {
  866. g.toolbar.time.show();
  867. g.toolbar.time.append(g.toolbar.time.hour).append(":").append(g.toolbar.time.minute);
  868. $("li", g.body.hourselector).each(function (i, item)
  869. {
  870. var str = i;
  871. if (i < 10) str = "0" + i.toString();
  872. $(this).html(str);
  873. });
  874. $("li", g.body.minuteselector).each(function (i, item)
  875. {
  876. var str = i;
  877. if (i < 10) str = "0" + i.toString();
  878. $(this).html(str);
  879. });
  880. }
  881. //设置主体
  882. g.bulidContent();
  883. //初始化
  884. //初始值
  885. if (p.initValue)
  886. {
  887. g.inputText.val(p.initValue);
  888. }
  889. if (g.inputText.val() != "")
  890. {
  891. g.onTextChange();
  892. }
  893. /**************
  894. **bulid evens**
  895. *************/
  896. g.dateeditor.hover(null, function (e)
  897. {
  898. if (g.dateeditor.is(":visible") && !g.editorToggling)
  899. {
  900. g.toggleDateEditor(true);
  901. }
  902. });
  903. //toggle even
  904. g.link.hover(function ()
  905. {
  906. if (p.disabled) return;
  907. this.className = "l-trigger-hover";
  908. }, function ()
  909. {
  910. if (p.disabled) return;
  911. this.className = "l-trigger";
  912. }).mousedown(function ()
  913. {
  914. if (p.disabled) return;
  915. this.className = "l-trigger-pressed";
  916. }).mouseup(function ()
  917. {
  918. if (p.disabled) return;
  919. this.className = "l-trigger-hover";
  920. }).click(function ()
  921. {
  922. if (p.disabled) return;
  923. g.bulidContent();
  924. g.toggleDateEditor(g.dateeditor.is(":visible"));
  925. });
  926. //不可用属性时处理
  927. if (p.disabled)
  928. {
  929. g.inputText.attr("readonly", "readonly");
  930. g.text.addClass('l-text-disabled');
  931. }
  932. g.buttons.btnClose.click(function ()
  933. {
  934. g.toggleDateEditor(true);
  935. });
  936. //日期 点击
  937. $("td", g.body.tbody).hover(function ()
  938. {
  939. if ($(this).hasClass("l-box-dateeditor-today")) return;
  940. $(this).addClass("l-box-dateeditor-over");
  941. }, function ()
  942. {
  943. $(this).removeClass("l-box-dateeditor-over");
  944. }).click(function ()
  945. {
  946. $(".l-box-dateeditor-selected", g.body.tbody).removeClass("l-box-dateeditor-selected");
  947. if (!$(this).hasClass("l-box-dateeditor-today"))
  948. $(this).addClass("l-box-dateeditor-selected");
  949. g.currentDate.date = parseInt($(this).html());
  950. g.currentDate.day = new Date(g.currentDate.year, g.currentDate.month - 1, 1).getDay();
  951. if ($(this).hasClass("l-box-dateeditor-out"))
  952. {
  953. if ($("tr", g.body.tbody).index($(this).parent()) == 0)
  954. {
  955. if (--g.currentDate.month == 0)
  956. {
  957. g.currentDate.month = 12;
  958. g.currentDate.year--;
  959. }
  960. } else
  961. {
  962. if (++g.currentDate.month == 13)
  963. {
  964. g.currentDate.month = 1;
  965. g.currentDate.year++;
  966. }
  967. }
  968. }
  969. g.selectedDate = {
  970. year: g.currentDate.year,
  971. month: g.currentDate.month,
  972. date: g.currentDate.date
  973. };
  974. g.showDate();
  975. g.editorToggling = true;
  976. g.dateeditor.slideToggle('fast', function ()
  977. {
  978. g.editorToggling = false;
  979. });
  980. });
  981. $(".l-box-dateeditor-header-btn", g.header).hover(function ()
  982. {
  983. $(this).addClass("l-box-dateeditor-header-btn-over");
  984. }, function ()
  985. {
  986. $(this).removeClass("l-box-dateeditor-header-btn-over");
  987. });
  988. //选择年份
  989. g.buttons.btnYear.click(function ()
  990. {
  991. //build year list
  992. if (!g.body.yearselector.is(":visible"))
  993. {
  994. $("li", g.body.yearselector).each(function (i, item)
  995. {
  996. var currentYear = g.currentDate.year + (i - 4);
  997. if (currentYear == g.currentDate.year)
  998. $(this).addClass("l-selected");
  999. else
  1000. $(this).removeClass("l-selected");
  1001. $(this).html(currentYear);
  1002. });
  1003. }
  1004. g.body.yearselector.slideToggle();
  1005. });
  1006. g.body.yearselector.hover(function () { }, function ()
  1007. {
  1008. $(this).slideUp();
  1009. });
  1010. $("li", g.body.yearselector).click(function ()
  1011. {
  1012. g.currentDate.year = parseInt($(this).html());
  1013. g.body.yearselector.slideToggle();
  1014. g.bulidContent();
  1015. });
  1016. //select month
  1017. g.buttons.btnMonth.click(function ()
  1018. {
  1019. $("li", g.body.monthselector).each(function (i, item)
  1020. {
  1021. //add selected style
  1022. if (g.currentDate.month == i + 1)
  1023. $(this).addClass("l-selected");
  1024. else
  1025. $(this).removeClass("l-selected");
  1026. });
  1027. g.body.monthselector.slideToggle();
  1028. });
  1029. g.body.monthselector.hover(function () { }, function ()
  1030. {
  1031. $(this).slideUp("fast");
  1032. });
  1033. $("li", g.body.monthselector).click(function ()
  1034. {
  1035. var index = $("li", g.body.monthselector).index(this);
  1036. g.currentDate.month = index + 1;
  1037. g.body.monthselector.slideToggle();
  1038. g.bulidContent();
  1039. });
  1040. //选择小时
  1041. g.toolbar.time.hour.click(function ()
  1042. {
  1043. $("li", g.body.hourselector).each(function (i, item)
  1044. {
  1045. //add selected style
  1046. if (g.currentDate.hour == i)
  1047. $(this).addClass("l-selected");
  1048. else
  1049. $(this).removeClass("l-selected");
  1050. });
  1051. g.body.hourselector.slideToggle();
  1052. });
  1053. g.body.hourselector.hover(function () { }, function ()
  1054. {
  1055. $(this).slideUp("fast");
  1056. });
  1057. $("li", g.body.hourselector).click(function ()
  1058. {
  1059. var index = $("li", g.body.hourselector).index(this);
  1060. g.currentDate.hour = index;
  1061. g.body.hourselector.slideToggle();
  1062. g.bulidContent();
  1063. g.showDate();
  1064. });
  1065. //选择分钟
  1066. g.toolbar.time.minute.click(function ()
  1067. {
  1068. $("li", g.body.minuteselector).each(function (i, item)
  1069. {
  1070. //add selected style
  1071. if (g.currentDate.minute == i)
  1072. $(this).addClass("l-selected");
  1073. else
  1074. $(this).removeClass("l-selected");
  1075. });
  1076. g.body.minuteselector.slideToggle("fast", function ()
  1077. {
  1078. var index = $("li", this).index($('li.l-selected', this));
  1079. if (index > 29)
  1080. {
  1081. var offSet = ($('li.l-selected', this).offset().top - $(this).offset().top);
  1082. $(this).animate({ scrollTop: offSet });
  1083. }
  1084. });
  1085. });
  1086. g.body.minuteselector.hover(function () { }, function ()
  1087. {
  1088. $(this).slideUp("fast");
  1089. });
  1090. $("li", g.body.minuteselector).click(function ()
  1091. {
  1092. var index = $("li", g.body.minuteselector).index(this);
  1093. g.currentDate.minute = index;
  1094. g.body.minuteselector.slideToggle("fast");
  1095. g.bulidContent();
  1096. g.showDate();
  1097. });
  1098. //上个月
  1099. g.buttons.btnPrevMonth.click(function ()
  1100. {
  1101. if (--g.currentDate.month == 0)
  1102. {
  1103. g.currentDate.month = 12;
  1104. g.currentDate.year--;
  1105. }
  1106. g.bulidContent();
  1107. });
  1108. //下个月
  1109. g.buttons.btnNextMonth.click(function ()
  1110. {
  1111. if (++g.currentDate.month == 13)
  1112. {
  1113. g.currentDate.month = 1;
  1114. g.currentDate.year++;
  1115. }
  1116. g.bulidContent();
  1117. });
  1118. //上一年
  1119. g.buttons.btnPrevYear.click(function ()
  1120. {
  1121. g.currentDate.year--;
  1122. g.bulidContent();
  1123. });
  1124. //下一年
  1125. g.buttons.btnNextYear.click(function ()
  1126. {
  1127. g.currentDate.year++;
  1128. g.bulidContent();
  1129. });
  1130. //今天
  1131. g.buttons.btnToday.click(function ()
  1132. {
  1133. g.currentDate = {
  1134. year: g.now.year,
  1135. month: g.now.month,
  1136. day: g.now.day,
  1137. date: g.now.date
  1138. };
  1139. g.selectedDate = {
  1140. year: g.now.year,
  1141. month: g.now.month,
  1142. day: g.now.day,
  1143. date: g.now.date
  1144. };
  1145. g.showDate();
  1146. g.dateeditor.slideToggle("fast");
  1147. });
  1148. //文本框
  1149. g.inputText.change(function ()
  1150. {
  1151. g.onTextChange();
  1152. }).blur(function ()
  1153. {
  1154. g.text.removeClass("l-text-focus");
  1155. }).focus(function ()
  1156. {
  1157. g.text.addClass("l-text-focus");
  1158. });
  1159. g.text.hover(function ()
  1160. {
  1161. g.text.addClass("l-text-over");
  1162. }, function ()
  1163. {
  1164. g.text.removeClass("l-text-over");
  1165. });
  1166. //LEABEL 支持
  1167. if (p.label)
  1168. {
  1169. g.labelwrapper = g.textwrapper.wrap('<div class="l-labeltext"></div>').parent();
  1170. g.labelwrapper.prepend('<div class="l-text-label" style="float:left;display:inline;">' + p.label + ':&nbsp</div>');
  1171. g.textwrapper.css('float', 'left');
  1172. if (!p.labelWidth)
  1173. {
  1174. p.labelWidth = $('.l-text-label', g.labelwrapper).outerWidth();
  1175. } else
  1176. {
  1177. $('.l-text-label', g.labelwrapper).outerWidth(p.labelWidth);
  1178. }
  1179. $('.l-text-label', g.labelwrapper).width(p.labelWidth);
  1180. $('.l-text-label', g.labelwrapper).height(g.text.height());
  1181. g.labelwrapper.append('<br style="clear:both;" />');
  1182. if (p.labelAlign)
  1183. {
  1184. $('.l-text-label', g.labelwrapper).css('text-align', p.labelAlign);
  1185. }
  1186. g.textwrapper.css({ display: 'inline' });
  1187. g.labelwrapper.width(g.text.outerWidth() + p.labelWidth + 2);
  1188. }
  1189. g.set(p);
  1190. //增加鼠标在日期控件外点击隐藏日期选择框功能
  1191. $(document).bind("click.dateeditor", function (e)
  1192. {
  1193. if (g.dateeditor.is(":visible") && $((e.target || e.srcElement)).closest( ".l-box-dateeditor, .l-text-date" ).length == 0)
  1194. {
  1195. g.toggleDateEditor(true);
  1196. }
  1197. });
  1198. },
  1199. updateSelectBoxPosition: function ()
  1200. {
  1201. var g = this, p = this.options;
  1202. if (p.absolute)
  1203. {
  1204. var contentHeight = $(document).height();
  1205. /** 定位BUG修复 add by hzp at 20160217 ***********/
  1206. if (Number(g.text.offset().top + 1 + g.text.outerHeight() + g.dateeditor.height()) > contentHeight
  1207. && contentHeight > Number(g.dateeditor.height() + 1))
  1208. {
  1209. //若下拉框大小超过当前document下边框,且当前document上留白大于下拉内容高度,下拉内容向上展现
  1210. g.dateeditor.css({ left: g.text.offset().left, top: g.text.offset().top + 1 - g.dateeditor.height() });
  1211. } else
  1212. {
  1213. g.dateeditor.css({ left: g.text.offset().left, top: g.text.offset().top - 1 + g.text.outerHeight() });
  1214. }
  1215. /********************************************/
  1216. }
  1217. else
  1218. {
  1219. if (g.text.offset().top + 4 > g.dateeditor.height() && g.text.offset().top + g.dateeditor.height() + textHeight + 4 - $(window).scrollTop() > $(window).height())
  1220. {
  1221. g.dateeditor.css("marginTop", -1 * (g.dateeditor.height() + textHeight + 5));
  1222. g.showOnTop = true;
  1223. }
  1224. else
  1225. {
  1226. g.showOnTop = false;
  1227. }
  1228. }
  1229. },
  1230. getValue: function(){
  1231. return $(this.element).val();
  1232. },
  1233. setValue: function (value)
  1234. {
  1235. var g = this;
  1236. if (!value) g.inputText.val('');
  1237. if (typeof value == "string")
  1238. {
  1239. if (/^\/Date/.test(value))
  1240. {
  1241. value = value.replace(/^\//, "new ").replace(/\/$/, "");
  1242. eval("value = " + value);
  1243. }
  1244. /******* 时间格式BUG ***********/
  1245. else{
  1246. if(value.length > g.options.format.length)
  1247. {
  1248. value = value.substr(0,g.options.format.length);
  1249. }
  1250. }
  1251. g.inputText.val(value);
  1252. g.usedDate = value;
  1253. /******* 时间格式BUG ***********/
  1254. g.onTextChange();
  1255. /******************/
  1256. }
  1257. if (typeof value == "object")
  1258. {
  1259. if (value instanceof Date)
  1260. {
  1261. g.inputText.val(g.getFormatDate(value));
  1262. g.onTextChange();
  1263. }
  1264. }
  1265. }
  1266. });
  1267. //重写弹窗控件 add by hzp at 20160217
  1268. $.extend($.ligerui.controls.Dialog.prototype,{
  1269. _setImage: function ()
  1270. {
  1271. var g = this, p = this.options;
  1272. if (p.type)
  1273. {
  1274. /************* 修改弹出对话框样式 *******************************/
  1275. var alertCss = { padding:"10px",textAlign:"center",fontWeight:"bolder",fontSize:"14px",lineHeight:"24px"};
  1276. g.dialog.body.css({width:300});
  1277. /*******************************************************/
  1278. if (p.type == 'success' || p.type == 'donne' || p.type == 'ok')
  1279. {
  1280. $(".l-dialog-image", g.dialog).addClass("l-dialog-image-donne").show();
  1281. g.dialog.content.css(alertCss);
  1282. }
  1283. else if (p.type == 'error')
  1284. {
  1285. $(".l-dialog-image", g.dialog).addClass("l-dialog-image-error").show();
  1286. g.dialog.content.css(alertCss);
  1287. }
  1288. else if (p.type == 'warn')
  1289. {
  1290. $(".l-dialog-image", g.dialog).addClass("l-dialog-image-warn").show();
  1291. g.dialog.content.css(alertCss);
  1292. }
  1293. else if (p.type == 'question')
  1294. {
  1295. $(".l-dialog-image", g.dialog).addClass("l-dialog-image-question").show();
  1296. g.dialog.content.css(alertCss);
  1297. }
  1298. }
  1299. }
  1300. });
  1301. //重写layout控件 add by hzp at 20160229
  1302. $.extend($.ligerui.controls.Layout.prototype,{
  1303. _render: function ()
  1304. {
  1305. var g = this, p = this.options;
  1306. g.layout = $(this.element);
  1307. g.layout.addClass("l-layout");
  1308. g.width = g.layout.width();
  1309. //top
  1310. if ($("> div[position=top]", g.layout).length > 0)
  1311. {
  1312. g.top = $("> div[position=top]", g.layout).wrap('<div class="l-layout-top" style="top:0px;"></div>').parent();
  1313. g.top.content = $("> div[position=top]", g.top);
  1314. if (!g.top.content.hasClass("l-layout-content"))
  1315. g.top.content.addClass("l-layout-content");
  1316. g.topHeight = p.topHeight;
  1317. if (g.topHeight)
  1318. {
  1319. g.top.height(g.topHeight);
  1320. }
  1321. }
  1322. //bottom
  1323. if ($("> div[position=bottom]", g.layout).length > 0)
  1324. {
  1325. g.bottom = $("> div[position=bottom]", g.layout).wrap('<div class="l-layout-bottom"></div>').parent();
  1326. g.bottom.content = $("> div[position=bottom]", g.bottom);
  1327. if (!g.bottom.content.hasClass("l-layout-content"))
  1328. g.bottom.content.addClass("l-layout-content");
  1329. g.bottomHeight = p.bottomHeight;
  1330. if (g.bottomHeight)
  1331. {
  1332. g.bottom.height(g.bottomHeight);
  1333. }
  1334. //set title
  1335. var bottomtitle = g.bottom.content.attr("title");
  1336. if (bottomtitle)
  1337. {
  1338. g.bottom.header = $('<div class="l-layout-header"></div>');
  1339. g.bottom.prepend(g.bottom.header);
  1340. g.bottom.header.html(bottomtitle);
  1341. g.bottom.content.attr("title", "");
  1342. }
  1343. }
  1344. //left
  1345. if ($("> div[position=left]", g.layout).length > 0)
  1346. {
  1347. g.left = $("> div[position=left]", g.layout).wrap('<div class="l-layout-left" style="left:0px;"></div>').parent();
  1348. g.left.header = $('<div class="l-layout-header"><div class="l-layout-header-toggle"></div><div class="l-layout-header-inner"></div></div>');
  1349. g.left.header.toggle = $(".l-layout-header-toggle", g.left.header);
  1350. g.left.content = $("> div[position=left]", g.left);
  1351. if (!g.left.content.hasClass("l-layout-content"))
  1352. g.left.content.addClass("l-layout-content");
  1353. if (!p.allowLeftCollapse) $(".l-layout-header-toggle", g.left.header).remove();
  1354. //set title
  1355. var lefttitle = g.left.content.attr("title");
  1356. if (lefttitle)
  1357. {
  1358. g.left.prepend(g.left.header);
  1359. g.left.content.attr("title", "");
  1360. $(".l-layout-header-inner", g.left.header).html(lefttitle);
  1361. }
  1362. //set title
  1363. if (g.left.content.attr("hidetitle"))
  1364. {
  1365. g.left.content.attr("title", "");
  1366. g.left.header.remove();
  1367. }
  1368. //set width
  1369. g.leftWidth = p.leftWidth;
  1370. if (g.leftWidth)
  1371. g.left.width(g.leftWidth);
  1372. }
  1373. //center
  1374. if ($("> div[position=center]", g.layout).length > 0)
  1375. {
  1376. g.center = $("> div[position=center]", g.layout).wrap('<div class="l-layout-center" ></div>').parent();
  1377. g.center.content = $("> div[position=center]", g.center);
  1378. g.center.content.addClass("l-layout-content");
  1379. //set title
  1380. var centertitle = g.center.content.attr("title");
  1381. if (centertitle)
  1382. {
  1383. g.center.content.attr("title", "");
  1384. g.center.header = $('<div class="l-layout-header"></div>');
  1385. g.center.prepend(g.center.header);
  1386. g.center.header.html(centertitle);
  1387. }
  1388. if (g.center.content.attr("hidetitle"))
  1389. {
  1390. g.center.content.attr("title", "");
  1391. g.center.header.remove();
  1392. }
  1393. //set width
  1394. g.centerWidth = p.centerWidth;
  1395. if (g.centerWidth)
  1396. g.center.width(g.centerWidth);
  1397. //centerBottom
  1398. if ($("> div[position=centerbottom]", g.layout).length > 0)
  1399. {
  1400. g.centerBottom = $("> div[position=centerbottom]", g.layout).wrap('<div class="l-layout-centerbottom" ></div>').parent();
  1401. g.centerBottom.content = $("> div[position=centerbottom]", g.centerBottom);
  1402. g.centerBottom.content.addClass("l-layout-content");
  1403. //set title
  1404. var centertitle = g.centerBottom.content.attr("title");
  1405. if (centertitle)
  1406. {
  1407. g.centerBottom.content.attr("title", "");
  1408. g.centerBottom.header = $('<div class="l-layout-header"></div>');
  1409. g.centerBottom.prepend(g.centerBottom.header);
  1410. g.centerBottom.header.html(centertitle);
  1411. }
  1412. if (g.centerBottom.content.attr("hidetitle"))
  1413. {
  1414. g.centerBottom.content.attr("title", "");
  1415. if (g.centerBottom.header)
  1416. {
  1417. g.centerBottom.header.remove();
  1418. }
  1419. }
  1420. if (g.centerWidth)
  1421. g.centerBottom.width(g.centerWidth);
  1422. }
  1423. }
  1424. //right
  1425. if ($("> div[position=right]", g.layout).length > 0)
  1426. {
  1427. g.right = $("> div[position=right]", g.layout).wrap('<div class="l-layout-right"></div>').parent();
  1428. g.right.header = $('<div class="l-layout-header"><div class="l-layout-header-toggle"></div><div class="l-layout-header-inner"></div></div>');
  1429. g.right.prepend(g.right.header);
  1430. g.right.header.toggle = $(".l-layout-header-toggle", g.right.header);
  1431. if (!p.allowRightCollapse) $(".l-layout-header-toggle", g.right.header).remove();
  1432. g.right.content = $("> div[position=right]", g.right);
  1433. if (!g.right.content.hasClass("l-layout-content"))
  1434. g.right.content.addClass("l-layout-content");
  1435. //set title
  1436. var righttitle = g.right.content.attr("title");
  1437. if (righttitle)
  1438. {
  1439. g.right.content.attr("title", "");
  1440. $(".l-layout-header-inner", g.right.header).html(righttitle);
  1441. }
  1442. if (g.right.content.attr("hidetitle"))
  1443. {
  1444. g.right.content.attr("title", "");
  1445. g.right.header.remove();
  1446. }
  1447. //set width
  1448. g.rightWidth = p.rightWidth;
  1449. if (g.rightWidth)
  1450. g.right.width(g.rightWidth);
  1451. }
  1452. //lock
  1453. g.layout.lock = $("<div class='l-layout-lock'></div>");
  1454. g.layout.append(g.layout.lock);
  1455. //DropHandle
  1456. g._addDropHandle();
  1457. //Collapse
  1458. g.isLeftCollapse = p.isLeftCollapse;
  1459. g.isRightCollapse = p.isRightCollapse;
  1460. g.leftCollapse = $('<div class="l-layout-collapse-left" style="display: none; "><div class="l-layout-collapse-left-toggle"></div></div>');
  1461. g.rightCollapse = $('<div class="l-layout-collapse-right" style="display: none; "><div class="l-layout-collapse-right-toggle"></div></div>');
  1462. g.layout.append(g.leftCollapse).append(g.rightCollapse);
  1463. g.leftCollapse.toggle = $("> .l-layout-collapse-left-toggle", g.leftCollapse);
  1464. g.rightCollapse.toggle = $("> .l-layout-collapse-right-toggle", g.rightCollapse);
  1465. g._setCollapse();
  1466. //init
  1467. g._bulid();
  1468. $(window).resize(function ()
  1469. {
  1470. g._onResize();
  1471. });
  1472. g.set(p);
  1473. g.mask.height(g.layout.height());
  1474. },
  1475. _onResize: function ()
  1476. {
  1477. var g = this, p = this.options;
  1478. var oldheight = g.layout.height();
  1479. //set layout height
  1480. var h = 0;
  1481. var windowHeight = $(window).height();
  1482. var parentHeight = null;
  1483. if (typeof (p.height) == "string" && p.height.indexOf('%') > 0)
  1484. {
  1485. var layoutparent = g.layout.parent();
  1486. if (p.inWindow || layoutparent[0].tagName.toLowerCase() == "body")
  1487. {
  1488. parentHeight = windowHeight;
  1489. parentHeight -= parseInt($('body').css('paddingTop'));
  1490. parentHeight -= parseInt($('body').css('paddingBottom'));
  1491. }
  1492. else
  1493. {
  1494. parentHeight = layoutparent.height();
  1495. }
  1496. h = parentHeight * parseFloat(p.height) * 0.01;
  1497. if (p.inWindow || layoutparent[0].tagName.toLowerCase() == "body")
  1498. h -= (g.layout.offset().top - parseInt($('body').css('paddingTop')));
  1499. /****** 判断是否比外层高 add by hzp at 2016-03-15 **********/
  1500. if(layoutparent.height() >0 && h > layoutparent.height())
  1501. {
  1502. var padding = layoutparent.innerHeight() - layoutparent.height();
  1503. var margin = layoutparent.outerHeight(true) - layoutparent.outerHeight();
  1504. h = layoutparent.height() - padding - margin;
  1505. }
  1506. /*************************************************/
  1507. }
  1508. else
  1509. {
  1510. h = parseInt(p.height);
  1511. }
  1512. h += p.heightDiff;
  1513. g.layout.height(h);
  1514. g.layoutHeight = g.layout.height();
  1515. g.middleWidth = g.layout.width();
  1516. g.middleHeight = g.layout.height();
  1517. if (g.top)
  1518. {
  1519. g.middleHeight -= g.top.height();
  1520. g.middleHeight -= parseInt(g.top.css('borderTopWidth'));
  1521. g.middleHeight -= parseInt(g.top.css('borderBottomWidth'));
  1522. g.middleHeight -= p.space;
  1523. }
  1524. if (g.bottom)
  1525. {
  1526. g.middleHeight -= g.bottom.height();
  1527. g.middleHeight -= parseInt(g.bottom.css('borderTopWidth'));
  1528. g.middleHeight -= parseInt(g.bottom.css('borderBottomWidth'));
  1529. g.middleHeight -= p.space;
  1530. }
  1531. //specific
  1532. g.middleHeight -= 2;
  1533. if (g.hasBind('heightChanged') && g.layoutHeight != oldheight)
  1534. {
  1535. g.trigger('heightChanged', [{ layoutHeight: g.layoutHeight, diff: g.layoutHeight - oldheight, middleHeight: g.middleHeight}]);
  1536. }
  1537. if (g.center)
  1538. {
  1539. g.centerWidth = g.middleWidth;
  1540. if (g.left)
  1541. {
  1542. if (g.isLeftCollapse)
  1543. {
  1544. g.centerWidth -= g.leftCollapse.width();
  1545. g.centerWidth -= parseInt(g.leftCollapse.css('borderLeftWidth'));
  1546. g.centerWidth -= parseInt(g.leftCollapse.css('borderRightWidth'));
  1547. g.centerWidth -= parseInt(g.leftCollapse.css('left'));
  1548. g.centerWidth -= p.space;
  1549. }
  1550. else
  1551. {
  1552. g.centerWidth -= g.leftWidth;
  1553. g.centerWidth -= parseInt(g.left.css('borderLeftWidth'));
  1554. g.centerWidth -= parseInt(g.left.css('borderRightWidth'));
  1555. g.centerWidth -= parseInt(g.left.css('left'));
  1556. g.centerWidth -= p.space;
  1557. }
  1558. }
  1559. if (g.right)
  1560. {
  1561. if (g.isRightCollapse)
  1562. {
  1563. g.centerWidth -= g.rightCollapse.width();
  1564. g.centerWidth -= parseInt(g.rightCollapse.css('borderLeftWidth'));
  1565. g.centerWidth -= parseInt(g.rightCollapse.css('borderRightWidth'));
  1566. g.centerWidth -= parseInt(g.rightCollapse.css('right'));
  1567. g.centerWidth -= p.space;
  1568. }
  1569. else
  1570. {
  1571. g.centerWidth -= g.rightWidth;
  1572. g.centerWidth -= parseInt(g.right.css('borderLeftWidth'));
  1573. g.centerWidth -= parseInt(g.right.css('borderRightWidth'));
  1574. g.centerWidth -= p.space;
  1575. }
  1576. }
  1577. g.centerLeft = 0;
  1578. if (g.left)
  1579. {
  1580. if (g.isLeftCollapse)
  1581. {
  1582. g.centerLeft += g.leftCollapse.width();
  1583. g.centerLeft += parseInt(g.leftCollapse.css('borderLeftWidth'));
  1584. g.centerLeft += parseInt(g.leftCollapse.css('borderRightWidth'));
  1585. g.centerLeft += parseInt(g.leftCollapse.css('left'));
  1586. g.centerLeft += p.space;
  1587. }
  1588. else
  1589. {
  1590. g.centerLeft += g.left.width();
  1591. g.centerLeft += parseInt(g.left.css('borderLeftWidth'));
  1592. g.centerLeft += parseInt(g.left.css('borderRightWidth'));
  1593. g.centerLeft += p.space;
  1594. }
  1595. }
  1596. g.center.css({ left: g.centerLeft });
  1597. g.centerWidth >= 0 && g.center.width(g.centerWidth);
  1598. g.middleHeight >= 0 && g.center.height(g.middleHeight);
  1599. var contentHeight = g.middleHeight;
  1600. if (g.center.header) contentHeight -= g.center.header.height();
  1601. var padding = g.center.content.innerHeight() - g.center.content.height();
  1602. var margin = g.center.content.outerHeight(true) - g.center.content.outerHeight();
  1603. contentHeight = contentHeight-padding-margin;
  1604. contentHeight >= 0 && g.center.content.height(contentHeight);
  1605. g._updateCenterBottom(true);
  1606. }
  1607. if (g.left)
  1608. {
  1609. g.leftCollapse.height(g.middleHeight);
  1610. g.left.height(g.middleHeight);
  1611. /********* 左布局高度BUG修复 add by hzp at 20160229 *******/
  1612. var contentHeight = g.middleHeight;
  1613. if (g.left.header) contentHeight -= g.left.header.height();
  1614. var padding = g.left.content.innerHeight() - g.left.content.height();
  1615. var margin = g.left.content.outerHeight(true) - g.left.content.outerHeight();
  1616. contentHeight = contentHeight-padding-margin;
  1617. contentHeight >= 0 && g.left.content.height(contentHeight);
  1618. /***************************************************/
  1619. }
  1620. if (g.right)
  1621. {
  1622. g.rightCollapse.height(g.middleHeight);
  1623. g.right.height(g.middleHeight);
  1624. //set left
  1625. g.rightLeft = 0;
  1626. if (g.left)
  1627. {
  1628. if (g.isLeftCollapse)
  1629. {
  1630. g.rightLeft += g.leftCollapse.width();
  1631. g.rightLeft += parseInt(g.leftCollapse.css('borderLeftWidth'));
  1632. g.rightLeft += parseInt(g.leftCollapse.css('borderRightWidth'));
  1633. g.rightLeft += p.space;
  1634. }
  1635. else
  1636. {
  1637. g.rightLeft += g.left.width();
  1638. g.rightLeft += parseInt(g.left.css('borderLeftWidth'));
  1639. g.rightLeft += parseInt(g.left.css('borderRightWidth'));
  1640. g.rightLeft += parseInt(g.left.css('left'));
  1641. g.rightLeft += p.space;
  1642. }
  1643. }
  1644. if (g.center)
  1645. {
  1646. g.rightLeft += g.center.width();
  1647. g.rightLeft += parseInt(g.center.css('borderLeftWidth'));
  1648. g.rightLeft += parseInt(g.center.css('borderRightWidth'));
  1649. g.rightLeft += p.space;
  1650. }
  1651. g.right.css({ left: g.rightLeft });
  1652. }
  1653. if (g.bottom)
  1654. {
  1655. g.bottomTop = g.layoutHeight - g.bottom.height() - 2;
  1656. g.bottom.css({ top: g.bottomTop });
  1657. }
  1658. g._setDropHandlePosition();
  1659. }
  1660. });
  1661. //重写数值控件 add by hzp at 20160308
  1662. $.extend($.ligerDefaults.DateEditor,{
  1663. isNegative:false
  1664. });
  1665. $.extend($.ligerui.controls.Spinner.prototype,{
  1666. _showValue: function (value)
  1667. {
  1668. var g = this, p = this.options;
  1669. /**** 默认值为空 ************/
  1670. if (!value || value == "NaN") value = "";
  1671. /***************************/
  1672. if (p.type == 'float')
  1673. {
  1674. value = parseFloat(value).toFixed(p.decimalplace);
  1675. }
  1676. this.inputText.val(value)
  1677. }
  1678. });
  1679. //重写Tip控件 add by hzp at 20160314
  1680. $.extend($.ligerui.controls.Tip.prototype,{
  1681. _render: function ()
  1682. {
  1683. var g = this, p = this.options;
  1684. var tip = $('<div class="l-verify-tip"><div class="l-verify-tip-corner"></div><div class="l-verify-tip-content"></div></div>');
  1685. g.tip = tip;
  1686. g.tip.attr("id", g.id);
  1687. if (p.content)
  1688. {
  1689. $("> .l-verify-tip-content:first", tip).html(p.content);
  1690. tip.appendTo('body');
  1691. }
  1692. else
  1693. {
  1694. return;
  1695. }
  1696. /************* 样式调整修改 *********************************/
  1697. tip.css({ left: p.x, top: p.y+3 }).show();
  1698. p.width && $("> .l-verify-tip-content:first", tip).width(p.width - 36);
  1699. /**********************************************/
  1700. p.height && $("> .l-verify-tip-content:first", tip).width(p.height);
  1701. eee = p.appendIdTo;
  1702. if (p.appendIdTo)
  1703. {
  1704. p.appendIdTo.attr("ligerTipId", g.id);
  1705. }
  1706. if (p.target)
  1707. {
  1708. $(p.target).attr("ligerTipId", g.id);
  1709. p.target.ligeruitipid = g.id;
  1710. }
  1711. p.callback && p.callback(tip);
  1712. g.set(p);
  1713. },
  1714. });
  1715. })(jQuery, window);