Bowin.Controls.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. var FormatType = {
  2. None: 0,
  3. DateTime: 1
  4. };
  5. var EditerModel = {
  6. Disabled: 0,
  7. Enabled: 1,
  8. Forthwith: 2
  9. };
  10. var TableModel = {
  11. Normal: 0,
  12. OverLoad: 1//超载模式
  13. };
  14. var HandleResult = {
  15. Failure: 0,
  16. Succeed: 1,
  17. Defects: 2
  18. };
  19. var BowinFunction = {
  20. /// <summary>
  21. /// <para>CMS框架内置顶级对象,所有内置函数或对象的祖先对象</para>
  22. /// <para>Add : by 劳炳辉 (忘记时间了-_-)</para>
  23. /// </summary>
  24. Untility: {
  25. ConvertObjectDateFormat: function (obj) {
  26. for (var itemName in obj) {
  27. var val = obj[itemName];
  28. if (typeof (val) == "string") {
  29. if (val.indexOf("/Date(") != -1) {
  30. obj[itemName] = val.toDateString("yyyy-MM-dd HH:mm:ss.S");
  31. }
  32. }
  33. else if (typeof (val) == "object") {
  34. BowinFunction.Untility.ConvertObjectDateFormat(val);
  35. }
  36. }
  37. return obj;
  38. }
  39. },
  40. UpdateClockFun: function (controlID) {
  41. /// <summary>
  42. /// <para>系统时钟定时器方法</para>
  43. /// </summary>
  44. var control = controlID.indexOf("#") == -1 ? ("#" + controlID) : controlID;
  45. var timeStr = $(control).find('span').eq(0).html().replace('年', '-').replace('月', '-').replace('日', '-').replace(" ", '').replace(/\:/g, '-');
  46. var timeStrArray = timeStr.split("-");
  47. var yyyy = parseInt(timeStrArray[0]);
  48. var MM = parseInt((timeStrArray[1].indexOf("0") == 0 && timeStrArray[1].length > 1 ? timeStrArray[1].substr(1) : timeStrArray[1])) - 1;
  49. var dd = parseInt((timeStrArray[2].indexOf("0") == 0 && timeStrArray[2].length > 1 ? timeStrArray[2].substr(1) : timeStrArray[2]));
  50. var HH = parseInt((timeStrArray[3].indexOf("0") == 0 && timeStrArray[3].length > 1 ? timeStrArray[3].substr(1) : timeStrArray[3]));
  51. var mm = parseInt((timeStrArray[4].indexOf("0") == 0 && timeStrArray[4].length > 1 ? timeStrArray[4].substr(1) : timeStrArray[4]));
  52. var ss = parseInt((timeStrArray[5].indexOf("0") == 0 && timeStrArray[5].length > 1 ? timeStrArray[5].substr(1) : timeStrArray[5]));
  53. var oldTime = new Date(yyyy, MM, dd, HH, mm, ss);
  54. if (oldTime.getSeconds() == 59 && oldTime.getMinutes() == 59 && oldTime.getHours() == 23) {//更新星期X
  55. switch ($(control).find('span').eq(1).html()) {
  56. case '星期一':
  57. $(control).find('span').eq(1).html('星期二');
  58. break;
  59. case '星期二':
  60. $(control).find('span').eq(1).html('星期三');
  61. break;
  62. case '星期三':
  63. $(control).find('span').eq(1).html('星期四');
  64. break;
  65. case '星期四':
  66. $(control).find('span').eq(1).html('星期五');
  67. break;
  68. case '星期五':
  69. $(control).find('span').eq(1).html('星期六');
  70. break;
  71. case '星期六':
  72. $(control).find('span').eq(1).html('星期日');
  73. break;
  74. case '星期日':
  75. $(control).find('span').eq(1).html('星期一');
  76. break;
  77. }
  78. }
  79. var newTime = new Date(oldTime.setSeconds(oldTime.getSeconds() + 1)); //秒数+1
  80. var Str = newTime.format("yyyy年MM月dd日 HH:mm:ss"); //时间
  81. $(control).find('span').eq(0).html(Str);
  82. },
  83. Combobox: {
  84. OnSelect: function (record, callBack) {
  85. var target = $(this);
  86. if (target.attr("isOnload") == 1) {
  87. target.attr("isOnload", 0);
  88. return;
  89. }
  90. var options = target.combobox("options");
  91. var defaultValue = options.value;
  92. if (options.multiple) {
  93. var o = false;
  94. for (var i = 0; i < options.data.length; i++) {
  95. if (options.data[i].Value == defaultValue) {
  96. o = true;
  97. break;
  98. }
  99. }
  100. if (defaultValue && o) {
  101. if (record.Value == defaultValue) {
  102. target.combobox("setValue", defaultValue);
  103. target.siblings("span.combo").find("span").find("span.combo-arrow").click();
  104. }
  105. else {
  106. var values = target.combobox("getValues");
  107. for (var i = 0; i < values.length; i++) {
  108. if (values[i] == defaultValue) {
  109. target.combobox("unselect", defaultValue);
  110. break;
  111. }
  112. }
  113. }
  114. }
  115. }
  116. if (callBack) {
  117. callBack.call(this, record);
  118. }
  119. },
  120. OnUnselect: function (record, callBack) {
  121. var target = $(this);
  122. var options = target.combobox("options");
  123. var defaultValue = options.value;
  124. if (options.multiple) {
  125. var o = false;
  126. for (var i = 0; i < options.data.length; i++) {
  127. if (options.data[i].Value == defaultValue) {
  128. o = true;
  129. break;
  130. }
  131. }
  132. if (defaultValue && o) {
  133. var values = target.combobox("getValues");
  134. if (values.length == 0) {
  135. target.combobox("setValue", defaultValue);
  136. target.siblings("span.combo").find("span").find("span.combo-arrow").click();
  137. }
  138. }
  139. }
  140. if (callBack) {
  141. callBack.call(this, record);
  142. }
  143. },
  144. OnChange: function (newValue, oldValue, callBack) {
  145. if ("undefined" != typeof EasyUIValidate) {
  146. if (EasyUIValidate.Events.ComboboxOnChange) {
  147. EasyUIValidate.Events.ComboboxOnChange.call(this, newValue, oldValue);
  148. }
  149. }
  150. if (callBack) {
  151. callBack.call(this, newValue, oldValue);
  152. }
  153. },
  154. OnLoadSuccess: function (callBack) {
  155. var target = $(this);
  156. var data = target.combobox('getData');
  157. var options = target.combobox('options');
  158. if (data.length > 0) {
  159. target.attr("isOnload", 1);
  160. if (!(options.value && options.value != "-1")) {
  161. if ($.grep(data, function (x) { return x[options.valueField] == "-1"; }).length > 0) {
  162. target.combobox('select', "-1");
  163. } else {
  164. target.combobox('select', data[0][options.valueField]);
  165. }
  166. } else if ($.grep(data, function (x) { return x[options.valueField] == options.value; }).length == 0) {
  167. target.combobox('select', data[0][options.valueField]);
  168. } else {
  169. target.attr("isOnload", 0);
  170. // target.combobox('select', options.value);
  171. }
  172. var datavalList = $.data(this, "combobox-dataval");
  173. if (datavalList) {
  174. if (datavalList.length > 0) {
  175. $.each(datavalList, function (i, x) {
  176. $('[name=' + target.attr("comboname") + ']').attr(x.name, x.value);
  177. target.removeAttr(x.name);
  178. });
  179. target.removeAttr("data-val");
  180. }
  181. }
  182. if ($.grep(data, function (x) {
  183. return x[options.textField] == "<";
  184. }).length > 0) {
  185. $(".combobox-item[value='<']").html('&lt;');
  186. }
  187. }
  188. // if (options.data.length == 1 && options.data[0][options.valueField] == -1) {
  189. // target.parent().find('select').append("<option value='" + options.data[0][options.valueField] + "'>" + options.data[0][options.textField] + "</option>");
  190. // }
  191. if (callBack) {
  192. callBack.call(this, data);
  193. }
  194. },
  195. ChangeHidden: function (record) {
  196. $('[name="' + $(this).attr("id") + '"]').val(record.Value);
  197. }
  198. },
  199. DataGrid: {
  200. /// <summary>
  201. /// <para>本对象专门用于操作jQueryEasyUI框架的DataGrid</para>
  202. /// </summary>
  203. OnLoadSuccessFunction: function (data, callBack) {
  204. var target = $(this);
  205. if (callBack) {
  206. callBack.call(this, data);
  207. }
  208. },
  209. CorssRowsStylerFunction: function (value, row, index) {
  210. if (index % 2 != 0) {//偶数行
  211. return 'background-color:#DAEEE1;';
  212. }
  213. else {//奇数行
  214. }
  215. },
  216. ColumnFormatterFunction: function (value, row, index, formatType, formatString, customFormatFun) {
  217. if (formatType == FormatType.None) {
  218. if (!value && value != 0) {
  219. value = "";
  220. }
  221. }
  222. else if (formatType == FormatType.DateTime) {
  223. if (!value) {
  224. value = "";
  225. }
  226. else {
  227. value = value.toDateString(formatString);
  228. }
  229. }
  230. if (customFormatFun) {
  231. return customFormatFun.call(this, index, row, value);
  232. }
  233. return value;
  234. },
  235. OperaterColumnFormatterFunction: function (value, row, index, buttonArrayString) {
  236. var htmlString = "&nbsp;";
  237. buttonArrayString = buttonArrayString.replace(/\^\^/g, "\"");
  238. var buttonArray = $.parseJSON(buttonArrayString);
  239. for (var i = 0; i < buttonArray.length; i++) {
  240. htmlString += buttonArray[i][i] + "&nbsp;";
  241. }
  242. return htmlString;
  243. },
  244. LinkButtonColumnFormatterFunction: function (value, row, index, text, handleScript, formatType, formatString) {
  245. var html = "<a title=\"" + (text ? text : (!value && value != 0 ? "" : value)) + "\" href=\"javascript:void(0);\" class=\"easyui-linkbutton\" onclick=\"return " + handleScript + "(" + index + ",$(this).closest('div.datagrid-view').find('table.easyui-datagrid').datagrid('getRows')[" + index + "]);\" >" + (text ? text : (!value && value != 0 ? "" : value)) + "</a>";
  246. return html;
  247. },
  248. GetRowData: function (table) {
  249. /// <summary>
  250. /// <para>获取table中所有被选中的数据(最后返回的是数据是JSON格式的String类型数据)</para>
  251. /// <param name="table">jQuery对象,不传则默认为当前选项卡中的第一个DataGrid</param>
  252. /// </summary>
  253. var $table = null;
  254. if (table == undefined || table == null) {
  255. var $tabs = $('#index_center').tabs();
  256. $table = $tabs.tabs('getSelected').find("table.easyui-datagrid").eq(0);
  257. }
  258. else {
  259. $table = $(table);
  260. }
  261. if ($table == null || $table == undefined) { return "" };
  262. var rowsData = $table.datagrid('getSelections');
  263. if (rowsData.length > 0) {
  264. for (var i = 0; i < rowsData.length; i++) {
  265. var data = rowsData[i];
  266. data = BowinFunction.Untility.ConvertObjectDateFormat(data);
  267. }
  268. }
  269. // return rowsData == null ? "" : rowsData.length > 1 ? JSON.stringify(rowsData) : "[" + JSON.stringify(rowsData) + "]";
  270. return rowsData == null ? "" : JSON.stringify(rowsData);
  271. },
  272. GetCurrentRowData: function (obj) {
  273. /// <summary>
  274. /// <para>获取ojb对象所在行的数据(最后返回的是数据是JSON格式的String类型数据)</para>
  275. /// </summary>
  276. var $table = $(obj).closest('.datagrid-view').find('table.easyui-datagrid').eq(0);
  277. var RowsData = $table.datagrid("getRows");
  278. var rowIndex = $(obj).closest('tr').attr("datagrid-row-index");
  279. var data = BowinFunction.Untility.ConvertObjectDateFormat(RowsData[rowIndex]);
  280. return "[" + JSON.stringify(data) + "]";
  281. },
  282. OrderColumn: function (src, field) {
  283. var table = $(src).closest('.easyui-cmsXDataTable');
  284. var opts = $.data(table[0], "cmsXDataTable").options;
  285. if (opts.pagerType == 0) {
  286. var ascStr = $(src).attr("asc");
  287. table.cmsXDataTable("clearOrderByAsc");
  288. if (!ascStr) {
  289. $(src).attr("asc", "1");
  290. } else if (ascStr == "1") {
  291. $(src).attr("asc", "0");
  292. } else {
  293. $(src).attr("asc", "1");
  294. }
  295. var isAsc = ascStr == "1";
  296. table.cmsXDataTable("orderLoad", { field: field, isAsc: isAsc });
  297. }
  298. }
  299. },
  300. EditerTable: {
  301. Editer: {
  302. ComboBox: {
  303. OptionOverride: function (tbTarget, comboBoxTarget, rowIndex, itemSourceField, itemData, rowField, editerModel, editerHandleUrl) {
  304. var columnOption = $(tbTarget).datagrid("getColumnOption", rowField);
  305. var rowData = $(tbTarget).datagrid("getRows")[rowIndex];
  306. var options = $(comboBoxTarget).combobox("options");
  307. options.width = columnOption.width;
  308. options.panelWidth = columnOption.width;
  309. options.onSelect = function (record) { BowinFunction.EditerTable.Editer.ComboBox.OnSelectEvents.call(this, tbTarget, rowIndex, itemSourceField, itemData, record, editerModel, editerHandleUrl) };
  310. if (itemSourceField) {
  311. options.data = rowData[itemSourceField];
  312. }
  313. else {
  314. options.data = $.parseJSON(itemData.replace(/\'/g, "\""));
  315. }
  316. options.panelHeight = "auto";
  317. options.valueField = "Value";
  318. options.textField = "Text";
  319. var rowFieldArray = rowField.split('.');
  320. var objValue;
  321. if (rowFieldArray.length > 1) {
  322. objValue = new Object(rowData[rowFieldArray[0]]);
  323. for (var i = 1; i < rowFieldArray.length; i++) {
  324. var objName = rowFieldArray[i];
  325. objValue = new Object(objValue)[objName];
  326. }
  327. options.value = objValue;
  328. }
  329. else {
  330. options.value = rowData[rowField];
  331. }
  332. $(comboBoxTarget).combobox(options);
  333. },
  334. OnSelectEvents: function (tbTarget, rowIndex, itemSourceField, itemData, record, editerModel, editerHandleUrl) {
  335. var originalKey = ($(tbTarget).datagrid("options").pageNumber * rowIndex) + (($(tbTarget).datagrid("options").pageNumber - 1) * $(tbTarget).datagrid("options").pageSize);
  336. var originalValue = $(tbTarget).datagrid("getRows")[rowIndex];
  337. var superData = $(tbTarget).data("superData");
  338. if (!superData) {
  339. superData = {};
  340. }
  341. if (!superData.editerData) {
  342. superData.editerData = {};
  343. }
  344. if (!superData.originalData) {
  345. superData.originalData = {};
  346. }
  347. if (!superData.originalData[originalKey]) {
  348. superData.originalData[originalKey] = {};
  349. $.extend(superData.originalData[originalKey], originalValue);
  350. }
  351. var editors = $(tbTarget).datagrid("endEdit", rowIndex).datagrid("beginEdit", rowIndex).datagrid("getEditors", rowIndex);
  352. var editerKey = ($(tbTarget).datagrid("options").pageNumber * rowIndex) + (($(tbTarget).datagrid("options").pageNumber - 1) * $(tbTarget).datagrid("options").pageSize);
  353. var editerValue = $(tbTarget).datagrid("getRows")[rowIndex];
  354. superData.editerData[editerKey] = editerValue;
  355. $(tbTarget).data("superData", superData);
  356. var s1 = $(tbTarget).datagrid("getModifyData");
  357. var s2 = $(tbTarget).datagrid("getModifyData", rowIndex);
  358. if (editerModel == EditerModel.Forthwith) {
  359. var ops = {
  360. URL: editerHandleUrl,
  361. Data: { source: "[" + JSON.stringify(editerValue) + "]" },
  362. CallBack: function (result) {
  363. if (result.HandleResult == HandleResult.Failure) {
  364. $.exceptionThrow(result, null);
  365. }
  366. else {
  367. $.messager.show({
  368. title: '设置成功',
  369. msg: '数据更新成功',
  370. timeout: 3000,
  371. showType: 'slide'
  372. });
  373. }
  374. }
  375. };
  376. BowinFunction.Request.AJAX(ops);
  377. }
  378. for (var i = 0; i < editors.length; i++) {
  379. if (editors[i].type == "combobox") {//下拉菜单类编辑器
  380. BowinFunction.EditerTable.Editer.ComboBox.OptionOverride(tbTarget, editors[i].target, rowIndex, itemSourceField, itemData, editors[i].field, editerModel, editerHandleUrl);
  381. }
  382. }
  383. },
  384. FormatterFunction: function (value, row, index, formatType, formatString, itemSourceField, itemData) {
  385. value = BowinFunction.DataGrid.ColumnFormatterFunction(value, row, index, formatType, formatString);
  386. var itemSource;
  387. if (itemSourceField) {
  388. itemSource = new Object(row[itemSourceField]);
  389. }
  390. else {
  391. itemSource = $.parseJSON(itemData.replace(/\'/g, "\""));
  392. }
  393. for (var i = 0; i < itemSource.length; i++) {
  394. if (itemSource[i].Value == value) {
  395. return itemSource[i].Text;
  396. }
  397. }
  398. }
  399. }
  400. },
  401. Rows: {
  402. OnDoubleClickEvents: function (rowIndex, rowData, itemSourceField, itemData, editerModel, editerHandleUrl) {
  403. var tbTarget = this;
  404. var editors = $(tbTarget).datagrid("getEditors", rowIndex); //获取行内所有编辑器
  405. if (editors.length > 0) {//已经进入编辑模式
  406. $(tbTarget).datagrid("cancelEdit", rowIndex); //撤销编辑
  407. var superData = $(tbTarget).data("superData");
  408. var originalData = null;
  409. if (superData && superData.originalData) {//获取原始数据
  410. var keyNumber = ($(tbTarget).datagrid("options").pageNumber * rowIndex) + (($(tbTarget).datagrid("options").pageNumber - 1) * $(tbTarget).datagrid("options").pageSize);
  411. originalData = superData.originalData[keyNumber];
  412. if (originalData) {
  413. $(tbTarget).datagrid("updateRow", { index: rowIndex, row: originalData });
  414. if (editerModel == EditerModel.Forthwith) {//回滚用户提交的更改
  415. var ops = {
  416. URL: editerHandleUrl,
  417. Data: { source: "[" + JSON.stringify(originalData) + "]" },
  418. CallBack: function (result) {
  419. if (result.HandleResult == HandleResult.Failure) {
  420. $.exceptionThrow(result, null);
  421. }
  422. else {
  423. $(tbTarget).data("superData").originalData[keyNumber] = null;
  424. $(tbTarget).data("superData").editerData[keyNumber] = null;
  425. $.messager.show({
  426. title: '撤销成功',
  427. msg: '数据回滚至编辑器启动前状态',
  428. timeout: 3000,
  429. showType: 'slide'
  430. });
  431. }
  432. }
  433. };
  434. BowinFunction.Request.AJAX(ops);
  435. }
  436. }
  437. }
  438. }
  439. else {
  440. $(this).datagrid("beginEdit", rowIndex); //启动编辑
  441. editors = $(tbTarget).datagrid("getEditors", rowIndex); //获取行内所有编辑器
  442. for (var i = 0; i < editors.length; i++) {
  443. if (editors[i].type == "combobox") {//下拉菜单类编辑器
  444. BowinFunction.EditerTable.Editer.ComboBox.OptionOverride(tbTarget, editors[i].target, rowIndex, itemSourceField, itemData, editors[i].field, editerModel, editerHandleUrl);
  445. }
  446. }
  447. }
  448. }
  449. }
  450. },
  451. Request: {
  452. Settings: {
  453. url: "",
  454. data: {},
  455. datatype: "",
  456. showProgress: true,
  457. progressTitle: "等待服务器返回处理结果",
  458. beforeSend: function () {
  459. /// <summary>
  460. /// <para>ajax请求发送前执行的函数</para>
  461. /// <para>例: function BowinBeforeFun(rowData)</para>
  462. /// <para>默认内置函数$BowinFunction.AjaxBefore,使用自定义函数请勿重名</para>
  463. /// <para>内置函数作用:弹出Loading条</para>
  464. /// <para>rowData==当前行数据(JSON格式)</para>
  465. /// </summary>
  466. var title = this.progressTitle;
  467. if (this.showProgress) {
  468. //$.messager.progress({ msg: title, autoClose: true, interval: 600 });
  469. $.cmsLoading.show(title);
  470. }
  471. },
  472. complete: function (XHR, TS) {
  473. //if (this.showProgress) {
  474. // var progressbar = $.messager.progress('bar');
  475. // if (progressbar.progressbar('getValue') < 100) {
  476. // progressbar.progressbar('setValue', 100);
  477. // }
  478. //}
  479. $.cmsLoading.hide();
  480. },
  481. success: function (result) {
  482. /// <summary>
  483. /// <para>后台返回处理结果后执行的函数</para>
  484. /// <para>例: function BowinCallBackFun(result)</para>
  485. /// <para>默认内置函数$BowinFunction.AjaxCallBack,使用自定义函数请勿重名</para>
  486. /// <para>内置函数处理逻辑:result==""?alert("处理成功"):alert(result)</para>
  487. /// </summary>
  488. if (result.HandleResult == HandleResult.Failure) {
  489. $.exceptionThrow(result, null);
  490. }
  491. else if (result.HandleResult == HandleResult.Defects) {
  492. var detailError = "";
  493. for (var i = 0; i < result.DetailError.length; i++) {
  494. detailError += (result.DetailError[i][0] + "<br />");
  495. }
  496. $.messager.alert("部分数据处理失败", detailError, function () { });
  497. }
  498. else if (result.HandleResult == HandleResult.Succeed) {
  499. $.messager.show({
  500. title: '成功',
  501. msg: '处理成功',
  502. timeout: 5000,
  503. showType: 'slide'
  504. });
  505. }
  506. },
  507. error: function (response) {
  508. /// <summary>
  509. /// <para>ajax请求发送失败时执行的函数</para>
  510. /// <para>例: function BowinErrorFun(response)</para>
  511. /// <para>默认内置函数$BowinFunction.AjaxError,使用自定义函数请勿重名</para>
  512. /// </summary>
  513. if (this.showProgress) {
  514. //$.messager.CloseProgress();
  515. $.cmsLoading.hide();
  516. }
  517. // $.messager.alert('请求失败 状态码:' + errorMsg.status, '错误信息:<br />' + errorMsg.statusText, 'error');
  518. var errorObj = $.parseJSON($(response.responseText)[1].innerHTML);
  519. $.exceptionThrow(errorObj, null);
  520. }
  521. },
  522. AJAX: function (settings) {
  523. var ajaxOptions = {};
  524. $.extend(ajaxOptions, this.Settings);
  525. if (settings.ProgressTitle != null && settings.ProgressTitle != undefined) {
  526. ajaxOptions.progressTitle = settings.ProgressTitle;
  527. }
  528. if (settings.ShowProgress != null && settings.ShowProgress != undefined) {
  529. ajaxOptions.showProgress = settings.ShowProgress;
  530. }
  531. if (settings.URL == null || settings.URL == "" || settings.URL == undefined) {
  532. $.messager.alert('请求失败', 'Action地址不能为空', 'error');
  533. return false;
  534. }
  535. else
  536. ajaxOptions.url = ("/" + CMS_SystemConfig.VirtualDirectoryPath + settings.URL.replace(CMS_SystemConfig.VirtualDirectoryPath, "")).replaceDoubleSlashesToSingle();
  537. if (settings.CallBack) {
  538. ajaxOptions.success = function (result) {
  539. settings.CallBack(result);
  540. }
  541. }
  542. if (settings.Error != null && settings.Error != undefined) { ajaxOptions.error = settings.Error; }
  543. if (settings.Data != null && settings.Data != undefined) { ajaxOptions.data = settings.Data; }
  544. if (settings.Before != null && settings.Before != undefined) {
  545. ajaxOptions.beforeSend = function () {
  546. if (ajaxOptions.showProgress) {
  547. //$.messager.progress({ msg: ajaxOptions.progressTitle, autoClose: true, interval: 600 });
  548. $.cmsLoading.show(ajaxOptions.progressTitle);
  549. }
  550. return settings.Before(ajaxOptions.data);
  551. }
  552. }
  553. $.ajax(ajaxOptions);
  554. }
  555. },
  556. Submit: function (obj) {
  557. var includedDataArray = ($(obj).attr('bowin-includeddata') == null || $(obj).attr('bowin-includeddata') == "" || $(obj).attr('bowin-includeddata') == undefined) ? null : ($(obj).attr('bowin-includeddata')).split(',');
  558. var includedDataFun = includedDataArray != null ? includedDataArray[0] : null;
  559. var $includedDataParm = (includedDataArray != null && includedDataArray[1] != undefined) ? $(includedDataArray[1]) : null;
  560. if (includedDataFun != null && includedDataFun.indexOf('GetCurrentRowData') > -1) {
  561. $includedDataParm = obj;
  562. }
  563. var dataFun = includedDataFun == null ? null : new Function('obj', "return " + includedDataFun + "(obj)");
  564. var ops = {
  565. URL: $(obj).attr("bowin-action"),
  566. Before: $(obj).attr("bowin-beforefun") ? new Function('obj', "return " + $(obj).attr("bowin-beforefun") + "(obj)") : null,
  567. CallBack: $(obj).attr("bowin-callbackfun") ? new Function('obj', "return " + $(obj).attr("bowin-callbackfun") + "(obj)") : null,
  568. Error: $(obj).attr("bowin-errorfun") ? new Function('obj', "return " + $(obj).attr("bowin-errorfun") + "(obj)") : null
  569. }
  570. if (dataFun != null) {
  571. ops.Data = {
  572. "BowinJsonData": dataFun($includedDataParm)
  573. }
  574. }
  575. if ($(obj).attr("customdata")) {
  576. $(obj).attr("customdata");
  577. }
  578. BowinFunction.Request.AJAX(ops);
  579. }
  580. };
  581. $(function () {
  582. $(':checkbox[controltype="bowin"]').live("click", function () {
  583. if ($(this).attr("checked") == undefined) {
  584. $(this).attr("value", "false");
  585. }
  586. else {
  587. $(this).attr("value", "true");
  588. }
  589. });
  590. top.$("div[data-tab]:visible").hide();
  591. $('.easyui-combobox').combo({
  592. onShowPanel: function () {
  593. var panelLeft = $(this).combo('panel').offset().left;
  594. var panelHeight = $(this).combo('panel').height();
  595. var textboxTop = $(this).combo('textbox').offset().top;
  596. var textboxHeight = $(this).combo('textbox').height();
  597. var panelTop = textboxTop + textboxHeight;
  598. var documentHeight = $(window).height() - 5;
  599. if (panelTop + panelHeight > documentHeight) {
  600. if (panelHeight < textboxTop) {
  601. $(this).combo('panel').parent().position({
  602. top: textboxTop - panelHeight
  603. });
  604. $(this).combo('panel').parent().offset({
  605. left: panelLeft
  606. });
  607. } else if (textboxTop > (documentHeight - panelTop)) {
  608. $(this).combo('panel').height(textboxTop - 5);
  609. $(this).combo('panel').parent().position({
  610. top: 5,
  611. });
  612. $(this).combo('panel').parent().offset({
  613. left: panelLeft
  614. });
  615. } else {
  616. $(this).combo('panel').height(documentHeight - panelTop);
  617. }
  618. }
  619. }
  620. });
  621. MVC_EasyUI_ValidateEntity();
  622. });
  623. $.extend($.fn.datagrid.methods, {
  624. getModifyData: function (tbTarget, rowIndex) {
  625. var editerData = $(tbTarget).data("superData").editerData;
  626. if (rowIndex) {
  627. var index = ($(tbTarget).datagrid("options").pageNumber * rowIndex) + (($(tbTarget).datagrid("options").pageNumber - 1) * $(tbTarget).datagrid("options").pageSize);
  628. return editerData[index];
  629. }
  630. else {
  631. var arr = [];
  632. for (var item in editerData) {
  633. arr.push(editerData[item]);
  634. }
  635. return arr;
  636. }
  637. },
  638. clearSuperData: function (tbTarget) {
  639. $(tbTarget).removeData("superData");
  640. }
  641. });
  642. function MVC_EasyUI_ValidateEntity() {
  643. if (location.href.indexOf("/Account/") <= 0) {
  644. //判断不能为空
  645. $("form [data-val-required]:visible,form [data-val-required][comboname]:hidden").each(function (i, n) {
  646. var jn = $(n);
  647. if (n.type != "checkbox") {
  648. var $td = jn.parent();
  649. if (!$td.is("td")) {
  650. $td = $td.parent();
  651. }
  652. if (jn.parent().find("span.ValidateEntityrequired").length == 0) {
  653. $td.append("<span class='ValidateEntityrequired'>*</span>");
  654. }
  655. }
  656. });
  657. $('form .easyui-datebox[validtype="daterequired"],form .easyui-datetimebox[validtype="daterequired"]').each(function (i, n) {
  658. var jn = $(n);
  659. var $td = jn.parent();
  660. if (!$td.is("td")) {
  661. $td = $td.parent();
  662. }
  663. if (jn.parent().find("span.ValidateEntityrequired").length == 0) {
  664. $td.append("<span class='ValidateEntityrequired'>*</span>");
  665. }
  666. });
  667. }
  668. move_dataVal();
  669. }
  670. function move_dataVal() {
  671. $("[comboname]").each(function (i) {
  672. var $this = $(this);
  673. var $easyUI = $("[name='" + $this.attr("comboname") + "']");
  674. if ($this.attr("data-val")) {
  675. var datavalList = new Array();
  676. for (var j = this.attributes.length - 1; j >= 0; j--) {
  677. if (this.attributes[j].name.indexOf("data-val") >= 0) {
  678. if (this.attributes[j].name == "data-val-required") {
  679. if ($this.hasClass("easyui-combobox") || $this.hasClass("easyui-combogridX")) {
  680. datavalList.push({ name: "data-val-dropdownlistrequired", value: this.attributes[j].value });
  681. $easyUI.attr("data-val-dropdownlistrequired", this.attributes[j].value);
  682. }
  683. // else if ($this.hasClass("easyui-datebox")) {
  684. // $easyUI.parent().find(".combo-text").attr("data-val-daterequired", this.attributes[j].value);
  685. // }
  686. else {
  687. datavalList.push({ name: "data-val-required", value: this.attributes[j].value });
  688. $easyUI.attr("data-val-required", this.attributes[j].value);
  689. }
  690. }
  691. else {
  692. // if ($this.hasClass("easyui-datebox")) {
  693. // $easyUI.parent().find(".combo-text").attr(this.attributes[j].name, this.attributes[j].value);
  694. // } else {
  695. // $easyUI.attr(this.attributes[j].name, this.attributes[j].value);
  696. // }
  697. datavalList.push({ name: this.attributes[j].name, value: this.attributes[j].value });
  698. $easyUI.attr(this.attributes[j].name, this.attributes[j].value);
  699. }
  700. $this.removeAttr(this.attributes[j].name);
  701. }
  702. }
  703. $.data(this, "combobox-dataval", datavalList);
  704. $this.removeAttr("data-val");
  705. }
  706. });
  707. }
  708. //start uploader
  709. function uploader_winName(name) {
  710. return "uploader_" + name;
  711. }
  712. function uploader_showFileDialog(name) {
  713. // var upname = uploader_winName(name);
  714. // if (!window[upname]) {
  715. // var j_uploader = $("fieldset[name='" + name + "']");
  716. // //var dialogdiv=$("<div><iframe src='" + j_uploader.attr("data-rooturl") + "Common/Uploader?n=" + name + "&v=" + j_uploader.attr("data-value") + "' frameborder=\"0\" style=\"border:0;width:100%;height:99%;\"></iframe></div>");
  717. // var dialogdiv = $("<div></div>");
  718. // dialogdiv.appendTo("body");
  719. // dialogdiv.window({ width: 600, height: 350, title: "附件上传", collapsible: false, minimizable: false, maximizable: false, modal: true });
  720. // dialogdiv.append("<iframe src='" + j_uploader.attr("data-rooturl") + "Common/Uploader?n=" + name + "&t=" + j_uploader.attr("data-type") + "&v=" + j_uploader.attr("data-value") + "' frameborder=\"0\" style=\"border:0;width:100%;height:99%;\"></iframe>");
  721. // window[upname] = dialogdiv;
  722. // }
  723. // else {
  724. // window[upname].window("open");
  725. // }
  726. var j_uploader = $("fieldset[name='" + name + "']");
  727. var uploader_url = j_uploader.attr("data-rooturl") + "Common/Uploader?n=" + name + "&t=" + j_uploader.attr("data-type") + "&v=" + j_uploader.attr("data-value");
  728. if (j_uploader.attr("maxFileSize")) {
  729. uploader_url += "&m=" + j_uploader.attr("maxFileSize");
  730. }
  731. $.popupTopWindow("附件上传", uploader_url, 480, 380, null, window);
  732. }
  733. function uploader_delTableRow(own, name) {
  734. $.messager.confirm("选择提示", "是否要删除当前文件?", function (r) {
  735. if (r) {
  736. var a_li = $(own).parent();
  737. var j_uploader = $("fieldset[name='" + name + "']");
  738. var formID = j_uploader.attr("data-value");
  739. $.post(j_uploader.attr("data-rooturl") + "Common/UploaderDel/" + formID + "?fileid=" + $(own).val(), function (msg) {
  740. if (msg.length == 0) {
  741. $.messager.alert("删除结果", "删除成功!", "", function () {
  742. a_li.remove();
  743. });
  744. }
  745. else {
  746. $.messager.alert("删除结果", msg);
  747. }
  748. });
  749. }
  750. });
  751. }
  752. function uploader_addli(name, tb_file) {
  753. var j_uploader = $("fieldset[name='" + name + "']");
  754. var isDisabled = j_uploader.find("[name='uploader_btn_add']").attr("disabled") == "disabled";
  755. var rooturl = j_uploader.attr("data-rooturl");
  756. var uploader_ul = j_uploader.find("[name='uploader_ul']");
  757. var uploader_li = "<li>" +
  758. "<a href='" + tb_file.FileUrl.replace('~/', rooturl) + "' target=\"_blank\">" + tb_file.FileName + "</a>";
  759. if (!isDisabled) {
  760. uploader_li += "<input style=\"border: 0;\" onclick=\"uploader_delTableRow(this,'" + name + "');return false;\" type=\"image\" src='" + rooturl + "Scripts/Bowin.Control.Core/Plugins/uploadifyFile/delfile.gif' value='" + tb_file.FileID + "' />";
  761. }
  762. uploader_li += "</li>";
  763. uploader_ul.append(uploader_li);
  764. }
  765. function uploader_init() {
  766. var j_uploader = $("fieldset[data-uploader]");
  767. var up_load;
  768. for (var i = 0; i < j_uploader.length; i++) {
  769. up_load = j_uploader.eq(i);
  770. $.getJSON(up_load.attr("data-rooturl") + "Common/UploaderInit/" + up_load.attr("data-value") + "?n=" + up_load.attr("name"), function (json) {
  771. $.each(json, function (j, n) {
  772. uploader_addli(j_uploader.attr("name"), n);
  773. });
  774. });
  775. }
  776. }
  777. $(function () {
  778. uploader_init();
  779. });
  780. //end uploader