PageRenderTime 85ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/ExtAspNet/js/X/X.js

#
JavaScript | 2513 lines | 1562 code | 361 blank | 590 comment | 336 complexity | 76714ace84a2c6c05acf69ff4ddf0e5b MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. // ExtAspNet应用程序域
  2. var X = function (cmpName) {
  3. return Ext.getCmp(cmpName);
  4. };
  5. X.state = function (cmp, state) {
  6. X.util.setXState(cmp, state);
  7. };
  8. X.enable = function (id) {
  9. X.util.enableSubmitControl(id);
  10. };
  11. X.disable = function (id) {
  12. X.util.disableSubmitControl(id);
  13. };
  14. X.target = function (target) {
  15. return X.util.getTargetWindow(target);
  16. };
  17. X.alert = function () {
  18. X.util.alert.apply(window, arguments);
  19. };
  20. X.init = function () {
  21. if (typeof (onInit) == 'function') {
  22. onInit();
  23. }
  24. };
  25. X.ready = function () {
  26. if (typeof (onReady) == 'function') {
  27. onReady();
  28. }
  29. };
  30. X.ajaxReady = function () {
  31. if (typeof (onAjaxReady) == 'function') {
  32. onAjaxReady();
  33. }
  34. };
  35. (function () {
  36. // ExtAspNet常用函数域(Utility)
  37. X.util = {
  38. alertTitle: "Alert Dialog",
  39. confirmTitle: "Confirm Dialog",
  40. formAlertMsg: "Please provide valid value for {0}!",
  41. formAlertTitle: "Form Invalid",
  42. loading: "Loading...",
  43. // 生成加载过程中的时间信息
  44. /*
  45. getTimeInfo: function () {
  46. var str = String.format("Total time:\t\t{0}\r\n", x_render_end_time - x_start_time);
  47. str += String.format("-Download time:\t\t{0} [ExtJS:{1}]\r\n", x_end_time - x_start_time, x_end_javascript_time - x_start_javascript_time);
  48. str += String.format("-Wait time:\t\t{0}\r\n", x_render_start_time - x_end_time);
  49. str += String.format("-Render time:\t\t{0}", x_render_end_time - x_render_start_time);
  50. return str;
  51. },
  52. */
  53. init: function (msgTarget, labelWidth, labelSeparator, enableBigFont,
  54. blankImageUrl, enableAspnetSubmitButtonAjax, enableAjaxLoading, ajaxLoadingType, enableAjax) {
  55. // Ext.QuickTips.init(true); 在原生的IE7(非IE8下的IE7模式)会有问题
  56. // 表现为iframe中的页面出现滚动条时,页面上的所有按钮都不能点击了。
  57. // 测试例子在:aspnet/test.aspx
  58. Ext.QuickTips.init(false);
  59. X.ajax.hookPostBack();
  60. if (enableAspnetSubmitButtonAjax) {
  61. //X.util.makeAspnetSubmitButtonAjax();
  62. }
  63. X.global_enable_ajax = enableAjax;
  64. X.global_enable_ajax_loading = enableAjaxLoading;
  65. X.global_ajax_loading_type = ajaxLoadingType;
  66. // 添加Ajax Loading提示节点
  67. X.ajaxLoadingDefault = Ext.get(X.util.appendLoadingNode());
  68. X.ajaxLoadingMask = new Ext.LoadMask(Ext.getBody(), { msg: X.util.loading });
  69. X.form_upload_file = false;
  70. X.global_disable_ajax = false;
  71. X.window_default_group = new Ext.WindowGroup();
  72. X.window_default_group.zseed = 6000;
  73. X.util.setHiddenFieldValue('X_CHANGED', 'false');
  74. document.forms[0].autocomplete = 'off';
  75. if (Ext.form.Field) {
  76. // Form cofiguration
  77. var fieldPro = Ext.form.Field.prototype;
  78. // editorPro = Ext.form.HtmlEditor.prototype;
  79. fieldPro.msgTarget = msgTarget;
  80. fieldPro.labelWidth = labelWidth;
  81. fieldPro.labelSeparator = labelSeparator;
  82. fieldPro.autoFitErrors = false;
  83. }
  84. if (enableBigFont) {
  85. Ext.getBody().addClass('bigfont');
  86. }
  87. // Default empty image
  88. if (Ext.isIE6 || Ext.isIE7) {
  89. Ext.BLANK_IMAGE_URL = blankImageUrl;
  90. }
  91. // // 页面缩放时改变页面上所有Window控件的容器大小
  92. // Ext.EventManager.onWindowResize(function(w, h){
  93. // var viewSize = window.Ext.getBody().getViewSize();
  94. // Ext.select('.x-window-wrapper').setWidth(viewSize.width).setHeight(viewSize.height);
  95. // });
  96. },
  97. setXState: function (cmp, state) {
  98. if (!cmp || !cmp['x_state']) {
  99. return;
  100. }
  101. var oldValue, newValue, el;
  102. // 如果state中包含CssClass,也就是在服务器端修改了CssClass属性,则需要首先删除原来的CssClass属性。
  103. if (typeof (state['CssClass']) !== 'undefined') {
  104. newValue = state['CssClass'];
  105. oldValue = cmp['x_state']['CssClass'];
  106. if (!oldValue) {
  107. oldValue = cmp.initialConfig.cls;
  108. }
  109. el = cmp.el;
  110. el.removeClass(oldValue);
  111. el.addClass(newValue);
  112. }
  113. if (typeof (state['FormItemClass']) !== 'undefined') {
  114. newValue = state['FormItemClass'];
  115. oldValue = cmp['x_state']['FormItemClass'];
  116. if (!oldValue) {
  117. oldValue = cmp.initialConfig.itemCls;
  118. }
  119. // Search for max 10 depth.
  120. el = cmp.el.findParent('.x-form-item', 10, true);
  121. el.removeClass(oldValue);
  122. el.addClass(newValue);
  123. }
  124. Ext.apply(cmp['x_state'], state);
  125. },
  126. stopEventPropagation: function (event) {
  127. event = event || window.event;
  128. if (typeof (event.cancelBubble) === 'boolean') {
  129. event.cancelBubble = true;
  130. } else {
  131. event.stopPropagation();
  132. }
  133. },
  134. // 绑定函数的上下文
  135. bind: function (fn, scope) {
  136. return function () {
  137. return fn.apply(scope, arguments);
  138. };
  139. },
  140. // 在页面上查找id为findId的节点,替换成replaceHtml
  141. replace: function (findId, replaceHtml) {
  142. // 在findId外面添加一个DIV层,然后更新此wrapper的InnerHTML
  143. var findedControl = Ext.get(findId);
  144. if (findedControl) {
  145. var wrapper = findedControl.wrap().update(replaceHtml);
  146. // 将新增的节点移到wrapper上面
  147. wrapper.first().insertBefore(wrapper);
  148. // 然后删除wrapper
  149. wrapper.remove();
  150. }
  151. },
  152. // 去除PageLoading节点
  153. removePageLoading: function (fadeOut) {
  154. if (fadeOut) {
  155. Ext.get("loading").remove();
  156. Ext.get("loading-mask").fadeOut({ remove: true });
  157. }
  158. else {
  159. Ext.get("loading").remove();
  160. Ext.get("loading-mask").remove();
  161. }
  162. },
  163. // 去掉字符串中的html标签
  164. stripHtmlTags: function (str) {
  165. return str.replace(/<[^>]*>/g, "");
  166. },
  167. // 弹出Alert对话框
  168. alert: function (msg, title, icon, okscript) {
  169. title = title || X.util.alertTitle;
  170. icon = icon || Ext.MessageBox.INFO;
  171. Ext.MessageBox.show({
  172. title: title,
  173. msg: msg,
  174. buttons: Ext.MessageBox.OK,
  175. icon: icon,
  176. fn: function (buttonId) {
  177. if (buttonId === "ok") {
  178. if (typeof (okscript) === "function") {
  179. okscript.call(window);
  180. }
  181. }
  182. }
  183. });
  184. },
  185. // 向页面添加Loading...节点
  186. appendLoadingNode: function () {
  187. return X.util.appendFormNode({ tag: "div", cls: "x-ajax-loading", html: X.util.loading });
  188. },
  189. // 向页面的 form 节点最后添加新的节点
  190. appendFormNode: function (htmlOrObj) {
  191. return Ext.DomHelper.append(document.forms[0], htmlOrObj);
  192. },
  193. // 向页面添加一个隐藏字段,如果已经存在则更新值
  194. setHiddenFieldValue: function (fieldId, fieldValue) {
  195. var itemNode = Ext.get(fieldId);
  196. if (itemNode == null) {
  197. // Ext.DomHelper.append 有问题,例如下面这个例子得到的结果是错的;变通一下,先插入节点,在设置节点的值。
  198. // Ext.DomHelper.append(document.forms[0], { tag: "input", type: "hidden", value: '{"X_Items":[["Value1","选项 1",1],["Value2","选项 2(不可选择)",0],["Value3","选项 3(不可选择)",0],["Value4","选项 4",1],["Value5","选项 5",1],["Value6","选项 6",1],["Value7","选项 7",1],["Value8","选项 8",1],["Value9","选项 9",1]],"SelectedValue":"Value1"}'});
  199. // 上面的这个字符串,在IETest的IE8模式下会变成:
  200. // {"DropDownList1":{"X_Items":[["Value1","\u9009\u9879 1",1],["Value2","\u9009\u9879 2\uff08\u4e0d\u53ef\u9009\u62e9\uff09",0],["Value3","\u9009\u9879 3\uff08\u4e0d\u53ef\u9009\u62e9\uff09",0],["Value4","\u9009\u9879 4",1],["Value5","\u9009\u9879 5",1],["Value6","\u9009\u9879 6",1],["Value7","\u9009\u9879 7",1],["Value8","\u9009\u9879 8",1],["Value9","\u9009\u9879 9",1]],"SelectedValue":"Value1"}}
  201. X.util.appendFormNode({ tag: "input", type: "hidden", id: fieldId, name: fieldId });
  202. Ext.get(fieldId).dom.value = fieldValue;
  203. }
  204. else {
  205. itemNode.dom.value = fieldValue;
  206. }
  207. },
  208. // 获取页面中一个隐藏字段的值
  209. getHiddenFieldValue: function (fieldId) {
  210. var itemNode = Ext.get(fieldId);
  211. if (itemNode) {
  212. return itemNode.getValue();
  213. }
  214. return null;
  215. },
  216. // 禁用提交按钮(在回发之前禁用以防止重复提交)
  217. disableSubmitControl: function (controlClientID) {
  218. X(controlClientID).disable();
  219. X.util.setHiddenFieldValue('X_TARGET', controlClientID);
  220. },
  221. // 启用提交按钮(在回发之后启用提交按钮)
  222. enableSubmitControl: function (controlClientID) {
  223. X(controlClientID).enable();
  224. X.util.setHiddenFieldValue('X_TARGET', '');
  225. },
  226. // 更新ViewState的值
  227. updateViewState: function (newValue, startIndex) {
  228. var oldValue = X.util.getHiddenFieldValue("__VIEWSTATE");
  229. if (Ext.type(startIndex) == "number") {
  230. if (startIndex < oldValue.length) {
  231. oldValue = oldValue.substr(0, startIndex);
  232. }
  233. } else {
  234. // Added on 2011-5-2, this is a horrible mistake.
  235. oldValue = '';
  236. }
  237. X.util.setHiddenFieldValue("__VIEWSTATE", oldValue + newValue);
  238. },
  239. // 更新EventValidation的值
  240. updateEventValidation: function (newValue) {
  241. X.util.setHiddenFieldValue("__EVENTVALIDATION", newValue);
  242. },
  243. // 设置页面状态是否改变
  244. setPageStateChanged: function () {
  245. var pageState = Ext.get("X_CHANGED");
  246. if (pageState && pageState.getValue() == "false") {
  247. pageState.dom.value = "true";
  248. }
  249. },
  250. // 页面状态是否改变
  251. isPageStateChanged: function () {
  252. var pageState = Ext.get("X_CHANGED");
  253. if (pageState && pageState.getValue() == "true") {
  254. return true;
  255. }
  256. return false;
  257. },
  258. // 验证多个表单,返回数组[是否验证通过,第一个不通过的表单字段]
  259. validForms: function (forms, targetName, showBox) {
  260. var target = X.util.getTargetWindow(targetName);
  261. var valid = true;
  262. var firstInvalidField = null;
  263. for (var i = 0; i < forms.length; i++) {
  264. var result = X(forms[i]).isValid();
  265. if (!result[0]) {
  266. valid = false;
  267. if (firstInvalidField == null) {
  268. firstInvalidField = result[1];
  269. }
  270. }
  271. }
  272. if (!valid) {
  273. if (showBox) {
  274. var alertMsg = String.format(X.util.formAlertMsg, firstInvalidField.fieldLabel);
  275. target.X.util.alert(alertMsg, X.util.formAlertTitle, Ext.MessageBox.INFO);
  276. }
  277. return false;
  278. }
  279. return true;
  280. },
  281. // 判断隐藏字段值(数组)是否包含value
  282. isHiddenFieldContains: function (domId, testValue) {
  283. testValue += "";
  284. var domValue = Ext.get(domId).dom.value;
  285. if (domValue === "") {
  286. //console.log(domId);
  287. return false;
  288. }
  289. else {
  290. var sourceArray = domValue.split(",");
  291. return sourceArray.indexOf(testValue) >= 0 ? true : false;
  292. }
  293. },
  294. // 将一个字符添加到字符列表中,将2添加到[5,3,4]
  295. addValueToHiddenField: function (domId, addValue) {
  296. addValue += "";
  297. var domValue = Ext.get(domId).dom.value;
  298. if (domValue == "") {
  299. Ext.get(domId).dom.value = addValue + "";
  300. }
  301. else {
  302. var sourceArray = domValue.split(",");
  303. if (sourceArray.indexOf(addValue) < 0) {
  304. sourceArray.push(addValue);
  305. Ext.get(domId).dom.value = sourceArray.join(",");
  306. }
  307. }
  308. },
  309. // 从字符列表中移除一个字符,将2从dom的值"5,3,4,2"移除
  310. removeValueFromHiddenField: function (domId, addValue) {
  311. addValue += "";
  312. var domValue = Ext.get(domId).dom.value;
  313. if (domValue != "") {
  314. var sourceArray = domValue.split(",");
  315. if (sourceArray.indexOf(addValue) >= 0) {
  316. sourceArray = sourceArray.remove(addValue);
  317. Ext.get(domId).dom.value = sourceArray.join(",");
  318. }
  319. }
  320. },
  321. // 取得隐藏字段的值
  322. getHiddenFieldValue: function (fieldId) {
  323. var itemNode = Ext.get(fieldId);
  324. if (itemNode == null) {
  325. return "";
  326. }
  327. else {
  328. return itemNode.dom.value;
  329. }
  330. },
  331. // 取得表单字段的值,日期字段的值类似"2008-07-08"
  332. getFormFieldValue: function (cmp) {
  333. if (cmp.getXType() == "datefield") {
  334. return cmp.value;
  335. }
  336. else {
  337. return cmp.getValue();
  338. }
  339. },
  340. // 由target获取window对象
  341. getTargetWindow: function (target) {
  342. var wnd = null;
  343. if (target === '_self') {
  344. wnd = window;
  345. } else if (target === '_parent') {
  346. wnd = parent;
  347. } else if (target === '_top') {
  348. wnd = top;
  349. }
  350. return wnd;
  351. },
  352. // 预加载图片
  353. preloadImages: function (images) {
  354. var imageInstance = [];
  355. for (var i = 0; i < images.length; i++) {
  356. imageInstance[i] = new Image();
  357. imageInstance[i].src = images[i];
  358. }
  359. },
  360. hasCSS: function (id) {
  361. return !!Ext.get(id);
  362. },
  363. addCSS: function (id, content) {
  364. // // 下面的代码在IE下不对,不能将style标签添加到head中
  365. // // 如果这个样式还没有添加到页面中
  366. // if (!Ext.get(id)) {
  367. // Ext.DomHelper.append(Ext.DomQuery.selectNode("head"), {
  368. // tag: "style",
  369. // type: "text/css",
  370. // id: id,
  371. // html: content
  372. // });
  373. // }
  374. if (!Ext.get(id)) {
  375. // Tricks From: http://www.phpied.com/dynamic-script-and-style-elements-in-ie/
  376. var ss1 = document.createElement("style");
  377. var def = content;
  378. ss1.setAttribute("type", "text/css");
  379. ss1.setAttribute("id", id);
  380. if (ss1.styleSheet) { // IE
  381. ss1.styleSheet.cssText = def;
  382. } else { // the world
  383. var tt1 = document.createTextNode(def);
  384. ss1.appendChild(tt1);
  385. }
  386. var hh1 = document.getElementsByTagName("head")[0];
  387. hh1.appendChild(ss1);
  388. }
  389. },
  390. // 在启用AJAX的情况下,使所有的Asp.net的提交按钮(type="submit")不要响应默认的submit行为,而是自定义的AJAX
  391. makeAspnetSubmitButtonAjax: function (buttonId) {
  392. /*
  393. function clickEvent(e, el) {
  394. __doPostBack(el.getAttribute("name"), "");
  395. e.stopEvent();
  396. }
  397. if (typeof (buttonId) === "undefined") {
  398. Ext.each(Ext.DomQuery.select("input[type=submit], input[type=images]"), function (item, index) {
  399. Ext.get(item).addListener("click", clickEvent);
  400. });
  401. } else {
  402. var button = Ext.get(buttonId);
  403. if (button.getAttribute("type") === "submit") {
  404. button.addListener("click", clickEvent);
  405. }
  406. }
  407. */
  408. function resetButton(button) {
  409. //button.set({ "type": "button" });
  410. button.addListener("click", function (event, el) {
  411. __doPostBack(el.getAttribute("name"), "");
  412. event.stopEvent();
  413. });
  414. }
  415. if (typeof (buttonId) === "undefined") {
  416. Ext.each(Ext.DomQuery.select("input[type=submit]"), function (item, index) {
  417. resetButton(Ext.get(item));
  418. });
  419. } else {
  420. var button = Ext.get(buttonId);
  421. if (button.getAttribute("type") === "submit") {
  422. resetButton(button);
  423. }
  424. }
  425. },
  426. // Whether a object is empty (With no property) or not.
  427. isObjectEmpty: function (obj) {
  428. for (var prop in obj) {
  429. if (obj.hasOwnProperty(prop)) {
  430. return false;
  431. }
  432. }
  433. return true;
  434. },
  435. // Convert an array to object.
  436. // ['Text', 'Icon'] -> {'Text':true, 'Icon': true}
  437. arrayToObject: function (arr) {
  438. var obj = {};
  439. Ext.each(arr, function (item, index) {
  440. obj[item] = true;
  441. });
  442. return obj;
  443. },
  444. hideScrollbar: function () {
  445. if (Ext.isIE) {
  446. window.document.body.scroll = 'no';
  447. } else {
  448. window.document.body.style.overflow = 'hidden';
  449. }
  450. },
  451. // 动态添加一个标签页
  452. // addExampleTab(node) or addExampleTab(id, url, text)
  453. addMainTab: function (mainTabStrip, id, url, text, icon, tbarCallback) {
  454. var iconId, iconCss, tabId, currentTab, tabConfig;
  455. if (typeof (id) !== 'string') {
  456. tbarCallback = url;
  457. url = id.attributes.href;
  458. icon = id.attributes.icon;
  459. text = id.text;
  460. id = id.id;
  461. }
  462. //var href = node.attributes.href;
  463. if (icon) {
  464. iconId = icon.replace(/\W/ig, '_');
  465. if (!X.util.hasCSS(iconId)) {
  466. iconCss = [];
  467. iconCss.push('.');
  468. iconCss.push(iconId);
  469. iconCss.push('{background-image:url("');
  470. iconCss.push(icon);
  471. iconCss.push('")}');
  472. X.util.addCSS(iconId, iconCss.join(''));
  473. }
  474. }
  475. // 动态添加一个带工具栏的标签页
  476. tabId = 'dynamic_added_tab' + id.replace('__', '-');
  477. currentTab = mainTabStrip.getTab(tabId);
  478. if (!currentTab) {
  479. tabConfig = {
  480. 'id': tabId,
  481. 'url': url,
  482. 'title': text,
  483. 'closable': true,
  484. 'bodyStyle': 'padding:0px;'
  485. };
  486. if (icon) {
  487. tabConfig['iconCls'] = iconId;
  488. }
  489. if (tbarCallback) {
  490. tabConfig['tbar'] = tbarCallback.call(window);
  491. }
  492. mainTabStrip.addTab(tabConfig);
  493. } else {
  494. mainTabStrip.setActiveTab(currentTab);
  495. }
  496. },
  497. initTreeTabStrip: function (treeMenu, mainTabStrip, tbarCallback) {
  498. // 注册树的节点点击事件
  499. function registerTreeClickEvent(treeInstance) {
  500. treeInstance.on('click', function (node, event) {
  501. if (node.isLeaf()) {
  502. // 阻止事件传播
  503. event.stopEvent();
  504. var href = node.attributes.href;
  505. // 修改地址栏
  506. window.location.hash = '#' + href;
  507. // 新增Tab节点
  508. X.util.addMainTab(mainTabStrip, node, tbarCallback);
  509. }
  510. });
  511. }
  512. // treeMenu可能是Accordion或者Tree
  513. if (treeMenu.getXType() === 'panel') {
  514. treeMenu.items.each(function (item) {
  515. var tree = item.items.itemAt(0);
  516. if (tree && tree.getXType() === 'treepanel') {
  517. registerTreeClickEvent(tree);
  518. }
  519. });
  520. } else if (treeMenu.getXType() === 'treepanel') {
  521. registerTreeClickEvent(treeMenu);
  522. }
  523. // 切换主窗口的Tab
  524. mainTabStrip.on('tabchange', function (tabStrip, tab) {
  525. if (tab.url) {
  526. //window.location.href = '#' + tab.url;
  527. window.location.hash = '#' + tab.url;
  528. } else {
  529. window.location.hash = '#';
  530. }
  531. });
  532. // 页面第一次加载时,根据URL地址在主窗口加载页面
  533. var HASH = window.location.hash.substr(1);
  534. var FOUND = false;
  535. function initTreeMenu(treeInstance, node) {
  536. var i, currentNode, nodes, node, path;
  537. if (!FOUND && node.hasChildNodes()) {
  538. nodes = node.childNodes;
  539. for (i = 0; i < nodes.length; i++) {
  540. currentNode = nodes[i];
  541. if (currentNode.isLeaf()) {
  542. if (currentNode.attributes.href === HASH) {
  543. path = currentNode.getPath();
  544. treeInstance.expandPath(path); //node.expand();
  545. treeInstance.selectPath(path); // currentNode.select();
  546. X.util.addMainTab(mainTabStrip, currentNode, tbarCallback);
  547. FOUND = true;
  548. return;
  549. }
  550. } else {
  551. arguments.callee(treeInstance, currentNode);
  552. }
  553. }
  554. }
  555. }
  556. if (treeMenu.getXType() === 'panel') {
  557. treeMenu.items.each(function (item) {
  558. var tree = item.items.itemAt(0);
  559. if (tree && tree.getXType() === 'treepanel') {
  560. initTreeMenu(tree, tree.getRootNode());
  561. // 找到树节点
  562. if (FOUND) {
  563. item.expand();
  564. return false;
  565. }
  566. }
  567. });
  568. } else if (treeMenu.getXType() === 'treepanel') {
  569. initTreeMenu(treeMenu, treeMenu.getRootNode());
  570. }
  571. },
  572. resolveCheckBoxGroup: function (name, xstateContainer, isradiogroup) {
  573. var items = [], i, count, xitem, xitemvalue, xitems, xselectedarray, xselected, xchecked, xitemname;
  574. xitems = xstateContainer.X_Items;
  575. xselectedarray = xstateContainer.SelectedValueArray;
  576. xselected = xstateContainer.SelectedValue;
  577. if (xitems && xitems.length > 0) {
  578. for (i = 0, count = xitems.length; i < count; i++) {
  579. xitem = xitems[i];
  580. xitemvalue = xitem[1];
  581. xchecked = false;
  582. if (!isradiogroup) {
  583. // xselectedarray 可能是undefined, [], ["value1", "value2"]
  584. if(xselectedarray){
  585. xchecked = (xselectedarray.indexOf(xitemvalue) >= 0) ? true : false;
  586. }
  587. xitemname = name + '_' + i;
  588. } else {
  589. xchecked = (xselected === xitemvalue) ? true : false;
  590. xitemname = name;
  591. }
  592. items.push({
  593. 'inputValue': xitemvalue,
  594. 'boxLabel': xitem[0],
  595. 'name': xitemname,
  596. 'checked': xchecked
  597. });
  598. }
  599. } else {
  600. items.push({
  601. 'inputValue': "tobedeleted",
  602. 'boxLabel': "&nbsp;",
  603. 'name': "tobedeleted"
  604. });
  605. }
  606. return items;
  607. }
  608. };
  609. })();
  610. (function () {
  611. X.ajax = {
  612. errorMsg: "Error! {0} ({1})",
  613. hookPostBack: function () {
  614. if (typeof (__doPostBack) != 'undefined') {
  615. __doPostBack = x__doPostBack;
  616. }
  617. }
  618. };
  619. function enableAjax() {
  620. if (typeof (X.control_enable_ajax) === 'undefined') {
  621. return X.global_enable_ajax;
  622. }
  623. return X.control_enable_ajax;
  624. }
  625. function enableAjaxLoading() {
  626. if (typeof (X.control_enable_ajax_loading) === 'undefined') {
  627. return X.global_enable_ajax_loading;
  628. }
  629. return X.control_enable_ajax_loading;
  630. }
  631. function ajaxLoadingType() {
  632. if (typeof (X.control_ajax_loading_type) === 'undefined') {
  633. return X.global_ajax_loading_type;
  634. }
  635. return X.control_ajax_loading_type;
  636. }
  637. function x__doPostBack_internal() {
  638. if (typeof (X.util.beforeAjaxPostBackScript) === 'function') {
  639. X.util.beforeAjaxPostBackScript();
  640. }
  641. // Ext.encode will convert Chinese characters. Ext.encode({a:"你好"}) => '{"a":"\u4f60\u597d"}'
  642. // We will include the official JSON object from http://json.org/
  643. // 现在还是用的 Ext.encode,在 IETester的 IE8下 JSON.stringify 生成的中文是\u9009\u9879形式。
  644. //X.util.setHiddenFieldValue('X_STATE', encodeURIComponent(JSON.stringify(getXState())));
  645. var xstate = Ext.encode(getXState());
  646. if (Ext.isIE6 || Ext.isIE7) {
  647. X.util.setHiddenFieldValue('X_STATE_URI', 'true');
  648. xstate = encodeURIComponent(xstate);
  649. } else {
  650. xstate = Base64.encode(xstate);
  651. }
  652. X.util.setHiddenFieldValue('X_STATE', xstate);
  653. //X.util.setHiddenFieldValue('X_STATE', encodeURIComponent(Ext.encode(getXState())));
  654. if (!enableAjax()) {
  655. // 当前请求结束后必须重置 X.control_enable_ajax
  656. X.control_enable_ajax = undefined;
  657. X.util.setHiddenFieldValue('X_AJAX', 'false');
  658. theForm.submit();
  659. } else {
  660. // 当前请求结束后必须重置 X.control_enable_ajax
  661. X.control_enable_ajax = undefined;
  662. X.util.setHiddenFieldValue('X_AJAX', 'true');
  663. var url = document.location.href;
  664. var urlHashIndex = url.indexOf('#');
  665. if (urlHashIndex >= 0) {
  666. url = url.substring(0, urlHashIndex);
  667. }
  668. Ext.Ajax.request({
  669. form: theForm.id,
  670. url: url,
  671. isUpload: X.form_upload_file,
  672. //params: serializeForm(theForm) + '&X_AJAX=true',
  673. success: function (data) {
  674. // see: http://extjs.com/forum/showthread.php?t=8129
  675. // 如果页面中有FileUpload,responseObj.responseText会包含于 <pre>标签。
  676. var scripts = data.responseText;
  677. if (scripts) {
  678. // 已经经过encodeURIComponent编码了,在ResponseFilter中的Close函数中
  679. var prefix = scripts.substr(0, 4);
  680. if (prefix.toLowerCase() === '<pre') {
  681. //scripts = scripts.substr(5, scripts.length - 11);
  682. //scripts = decodeURIComponent(scripts.replace(/<\/?pre>/ig, ''));
  683. scripts = scripts.replace(/<\/?pre[^>]*>/ig, '');
  684. scripts = decodeURIComponent(scripts);
  685. }
  686. //eval(scripts);
  687. new Function(scripts)();
  688. }
  689. X.ajaxReady();
  690. },
  691. failure: function (data) {
  692. var lastDisabledButtonId = X.util.getHiddenFieldValue('X_TARGET');
  693. if (lastDisabledButtonId) {
  694. X.enable(lastDisabledButtonId);
  695. }
  696. //X.util.alert(String.format(X.ajax.errorMsg, data.statusText, data.status));
  697. if (!X.ajax.errorWindow) {
  698. initErrorWindow();
  699. }
  700. X.ajax.errorWindow.show();
  701. X.ajax.errorWindow.body.dom.innerHTML = X.wnd.createIFrameHtml('about:blank', 'EXTASPNET_ERROR');
  702. X.ajax.errorWindow.setTitle(String.format(X.ajax.errorMsg, data.statusText, data.status));
  703. writeContentToIFrame(X.ajax.errorWindow.body.query('iframe')[0], data.responseText);
  704. //writeContentToIFrame(Ext.DomQuery.selectNode('iframe', X.ajax.errorWindow.body), data.responseText);
  705. }
  706. });
  707. }
  708. }
  709. // 如果启用 Ajax,则所有对 __doPostBack 的调用都会到这里来
  710. function x__doPostBack(eventTarget, eventArgument) {
  711. // 回发页面之前延时 100 毫秒,确保页面上的操作完成(比如选中复选框的动作)
  712. window.setTimeout(function () {
  713. // theForm variable will always exist, because we invoke the GetPostBackEventReference in PageManager.
  714. if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
  715. theForm.__EVENTTARGET.value = eventTarget;
  716. theForm.__EVENTARGUMENT.value = eventArgument;
  717. x__doPostBack_internal();
  718. }
  719. }, 100);
  720. }
  721. function writeContentToIFrame(iframe, content) {
  722. // http://stackoverflow.com/questions/1477547/getelementbyid-contentdocument-error-in-ie
  723. // contentWindow is always there.
  724. if (iframe) {
  725. var doc = iframe.contentWindow.document;
  726. // if (iframe.contentDocument) {
  727. // doc = iframe.contentDocument;
  728. // } else if (iframe.contentWindow) {
  729. // doc = iframe.contentWindow.document;
  730. // }
  731. if (doc) {
  732. doc.open();
  733. doc.write(content);
  734. doc.close();
  735. }
  736. }
  737. }
  738. function initErrorWindow() {
  739. X.ajax.errorWindow = new Ext.Window({
  740. id: "EXTASPNET_ERROR",
  741. renderTo: window.body,
  742. width: 550,
  743. height: 350,
  744. border: true,
  745. animCollapse: true,
  746. collapsible: false,
  747. collapsed: false,
  748. closeAction: "hide",
  749. plain: false,
  750. modal: true,
  751. draggable: true,
  752. minimizable: false,
  753. minHeight: 100,
  754. minWidth: 200,
  755. resizable: false,
  756. maximizable: false,
  757. closable: true
  758. });
  759. }
  760. // Ext.Ajax.serializeForm has a fault. The result will include type="submit" section, which is not always right.
  761. /*
  762. function serializeForm(form) {
  763. var originalStr = Ext.Ajax.serializeForm(form);
  764. for (var i = 0; i < form.elements.length; i++) {
  765. el = form.elements[i];
  766. if (el.type === 'submit') {
  767. var submitStr = encodeURIComponent(el.name) + '=' + encodeURIComponent(el.value);
  768. if (originalStr.indexOf(submitStr) == 0) {
  769. originalStr = originalStr.replace(submitStr, '');
  770. } else {
  771. originalStr = originalStr.replace('&' + submitStr, '');
  772. }
  773. }
  774. }
  775. return originalStr;
  776. }
  777. */
  778. // 序列化表单为 URL 编码字符串,除去 <input type="submit" /> 的按钮
  779. /*
  780. var extjsSerializeForm = Ext.lib.Ajax.serializeForm;
  781. Ext.lib.Ajax.serializeForm = function (form) {
  782. var el, originalStr = extjsSerializeForm(form);
  783. for (var i = 0; i < form.elements.length; i++) {
  784. el = form.elements[i];
  785. if (el.type === 'submit') {
  786. var submitStr = encodeURIComponent(el.name) + '=' + encodeURIComponent(el.value);
  787. if (originalStr.indexOf(submitStr) == 0) {
  788. originalStr = originalStr.replace(submitStr, '');
  789. } else {
  790. originalStr = originalStr.replace('&' + submitStr, '');
  791. }
  792. }
  793. }
  794. return originalStr;
  795. };
  796. */
  797. function getXState() {
  798. var state = {};
  799. Ext.ComponentMgr.all.each(function (cmp, index) {
  800. if (cmp.isXType) {
  801. // x_props store the properties which has been changed on server-side or client-side.
  802. // Every ExtAspNet control should has this property.
  803. var xstate = cmp['x_state'];
  804. if (xstate && Ext.isObject(xstate)) {
  805. var cmpState = getXStateViaCmp(cmp, xstate);
  806. if (!X.util.isObjectEmpty(cmpState)) {
  807. state[cmp.id] = cmpState;
  808. }
  809. }
  810. }
  811. });
  812. return state;
  813. }
  814. X.ajax.getXState = getXState;
  815. function getXStateViaCmp(cmp, xstate) {
  816. var state = {};
  817. Ext.apply(state, xstate);
  818. function saveInHiddenField(property, currentValue) {
  819. // Save this client-changed property in a form hidden field.
  820. X.util.setHiddenFieldValue(cmp.id + '_' + property, currentValue);
  821. }
  822. // 有些属性可以在客户端改变,因此需要在每个请求之前计算
  823. if (cmp.isXType('panel')) {
  824. saveInHiddenField('Collapsed', cmp.collapsed);
  825. }
  826. if (cmp.isXType('datepicker')) {
  827. saveInHiddenField('SelectedDate', cmp.getValue().format(cmp.initialConfig.format));
  828. }
  829. if (cmp.isXType('button')) {
  830. if (cmp.initialConfig.enableToggle) {
  831. saveInHiddenField('Pressed', cmp.pressed);
  832. }
  833. }
  834. if (cmp.isXType('grid')) {
  835. saveInHiddenField('SelectedRowIndexArray', cmp.x_getSelectedRows().join(','));
  836. saveInHiddenField('HiddenColumnIndexArray', cmp.x_getHiddenColumns().join(','));
  837. saveInHiddenField('RowStates', Ext.encode(cmp.x_getRowStates()));
  838. }
  839. if (cmp.isXType('treepanel')) {
  840. saveInHiddenField('ExpandedNodes', cmp.x_getExpandedNodes(cmp.getRootNode().childNodes).join(','));
  841. saveInHiddenField('CheckedNodes', cmp.x_getCheckedNodes().join(','));
  842. saveInHiddenField('SelectedNodeIDArray', cmp.x_getSelectedNodes().join(','));
  843. }
  844. if (cmp.isXType('tabpanel')) {
  845. saveInHiddenField('ActiveTabIndex', cmp.x_getActiveTabIndex());
  846. }
  847. if (cmp['x_type']) {
  848. if (cmp['x_type'] === 'tab') {
  849. saveInHiddenField('Hidden', cmp.tabEl.style.display === 'none');
  850. }
  851. }
  852. // if (cmp.isXType('combo')) {
  853. // saveInHiddenField('SelectedValue', cmp.getValue());
  854. // }
  855. return state;
  856. // function clientChangableProperty(property, currentValue, saveInHiddenField) {
  857. // if (saveInHiddenField) {
  858. // // Save this client-changed property in a form hidden field.
  859. // X.util.setHiddenFieldValue(cmp.id + '_' + property, currentValue);
  860. // }
  861. // // xstate is changed in server-side.
  862. // // var lastValue = xstate[property];
  863. // // // If lastValue is not exist or it has been changed, then save the new value.
  864. // // if (!lastValue || lastValue.toString() !== currentValue.toString()) {
  865. // // xstate[property] = currentValue;
  866. // // }
  867. // }
  868. // var xType = cmp.getXType();
  869. // switch (xType) {
  870. // case 'button':
  871. // // The EnablePress property has been enabled for this button.
  872. // if (cmp.initialConfig.enableToggle) {
  873. // saveInHiddenField('Pressed', cmp.pressed);
  874. // }
  875. // break;
  876. // case 'checkbox':
  877. // case 'radio':
  878. // // Although the 'Checked' property can be changed in client-side.
  879. // // But we don't save it in X_STATE, because it will be exist in form (input type="checkbox").
  880. // clientChangableProperty('Checked', cmp.getValue());
  881. // break;
  882. // case 'radiogroup':
  883. // // Although the 'Checked' property can be changed in client-side.
  884. // // But we don't save it in X_STATE, because it will be exist in form (input type="checkbox").
  885. // clientChangableProperty('SelectedValue', cmp.getValue());
  886. // break;
  887. // case 'combo':
  888. // clientChangableProperty('X_SelectedValue', cmp.getValue());
  889. // break;
  890. // case 'textfield':
  891. // // Although the 'Text' property can be changed in client-side.
  892. // // But we don't save it in X_STATE, because it will be exist in form.
  893. // clientChangableProperty('Text', cmp.getValue());
  894. // break;
  895. // case 'window':
  896. // // Although the 'Hidden' property can be changed in client-side.
  897. // // But we don't save it in X_STATE, because it will be exist in form - HiddenHiddenFieldID.
  898. // clientChangableProperty("Hidden", X.util.getHiddenFieldValue(cmp.id + '_Hidden') === 'true' ? true : false);
  899. // break;
  900. // case 'grid':
  901. // // X('Grid1').getStore().indexOfId(X('Grid1').getSelectionModel().getSelections()[0].id)
  902. // clientChangableProperty('SelectedRowIndexArray', cmp.x_getSelectedRows(), true);
  903. // break;
  904. // case 'tabpanel':
  905. // clientChangableProperty('ActiveTabIndex', cmp.items.indexOf(cmp.getActiveTab()), true);
  906. // break;
  907. // }
  908. }
  909. // 显示“正在载入...”的提示信息
  910. function _showAjaxLoading(ajaxLoadingType) {
  911. if (_requestCount > 0) {
  912. if (ajaxLoadingType === "default") {
  913. X.ajaxLoadingDefault.setStyle('left', (Ext.getBody().getWidth() - X.ajaxLoadingDefault.getWidth()) / 2 + 'px');
  914. X.ajaxLoadingDefault.show();
  915. } else {
  916. X.ajaxLoadingMask.show();
  917. }
  918. }
  919. }
  920. // 隐藏“正在载入...”的提示信息
  921. function _hideAjaxLoading(ajaxLoadingType) {
  922. if (_requestCount <= 0) {
  923. _requestCount = 0;
  924. if (ajaxLoadingType === "default") {
  925. X.ajaxLoadingDefault.hide();
  926. } else {
  927. X.ajaxLoadingMask.hide();
  928. }
  929. }
  930. }
  931. // 当前 Ajax 的并发请求数
  932. var _requestCount = 0;
  933. // 发起 Ajax 请求之前事件处理
  934. Ext.Ajax.on('beforerequest', function (conn, options) {
  935. _requestCount++;
  936. if (!enableAjaxLoading()) {
  937. // Do nothing
  938. } else {
  939. Ext.defer(_showAjaxLoading, 100, window, [ajaxLoadingType()]);
  940. }
  941. });
  942. // Ajax 请求结束
  943. Ext.Ajax.on('requestcomplete', function (conn, options) {
  944. _requestCount--;
  945. if (!enableAjaxLoading()) {
  946. // ...
  947. } else {
  948. Ext.defer(_hideAjaxLoading, 80, window, [ajaxLoadingType()]);
  949. }
  950. X.control_enable_ajax_loading = undefined;
  951. X.control_ajax_loading_type = undefined;
  952. });
  953. // Ajax 请求发生异常
  954. Ext.Ajax.on('requestexception', function (conn, options) {
  955. _requestCount--;
  956. if (!enableAjaxLoading()) {
  957. // ...
  958. } else {
  959. Ext.defer(_hideAjaxLoading, 100);
  960. }
  961. X.control_enable_ajax_loading = undefined;
  962. X.control_ajax_loading_type = undefined;
  963. });
  964. // // 不适用于所有Extjs控件(比如Toolbar中放置按钮,这个按钮就没有ownerCt对象)
  965. // // 更新一个Javascript对象
  966. // updateObject: function(obj, newObjFunction, renderImmediately) {
  967. // var id = obj.id;
  968. // if (Ext.type(renderImmediately) == 'boolean' && !renderImmediately) {
  969. // // 1.取得父容器
  970. // var owner = obj.ownerCt;
  971. // // 2.本控件在父容器的位置
  972. // var insertIndex = owner.items.indexOf(obj);
  973. // // 3.从父容器中销毁此控件
  974. // owner.remove(obj);
  975. // // 4.创建新的控件
  976. // newObjFunction();
  977. // // 5.将新的控件添加到删除的位置
  978. // owner.insert(insertIndex, Ext.getCmp(id));
  979. // // 6.父容器重新布局
  980. // owner.doLayout();
  981. // }
  982. // else {
  983. // // 1.销毁此控件
  984. // obj.destroy();
  985. // // 2.新建此控件
  986. // newObjFunction();
  987. // }
  988. // }
  989. })();
  990. (function () {
  991. // 计算黄金分割点的位置
  992. // bodySize : 整个页面的Body的大小
  993. // windowSize : 窗口的大小
  994. function _calculateGoldenPosition(bodySize, windowSize) {
  995. var top = (bodySize.height - (bodySize.height / 1.618)) - windowSize.height / 2;
  996. if (top < 0) {
  997. top = 0;
  998. }
  999. var left = (bodySize.width - windowSize.width) / 2;
  1000. if (left < 0) {
  1001. left = 0;
  1002. }
  1003. return { left: left, top: top };
  1004. }
  1005. // 计算中间的位置
  1006. // bodySize : 整个页面的Body的大小
  1007. // windowSize : 窗口的大小
  1008. function _calculateCenterPosition(bodySize, windowSize) {
  1009. var top = (bodySize.height - windowSize.height) / 2;
  1010. if (top < 0) {
  1011. top = 0;
  1012. }
  1013. var left = (bodySize.width - windowSize.width) / 2;
  1014. if (left < 0) {
  1015. left = 0;
  1016. }
  1017. return { left: left, top: top };
  1018. }
  1019. // 创建IFrame节点片段
  1020. function _createIFrameHtml(iframeUrl, iframeName) {
  1021. return '<iframe frameborder="0" style="overflow:auto;height:100%;width:100%;" name="' + iframeName + '" src="' + iframeUrl + '"></iframe>';
  1022. }
  1023. // 获取窗体的外部容器
  1024. function _getWrapperNode(panel) {
  1025. return Ext.get(panel.el.findParentNode('.x-window-wrapper'));
  1026. }
  1027. // ExtAspNet窗口域(Window)
  1028. X.wnd = {
  1029. closeButtonTooltip: "Close this window",
  1030. formModifiedConfirmTitle: "Close Confrim",
  1031. formModifiedConfirmMsg: "Current form has been modified.<br/><br/>Abandon changes?",
  1032. createIFrameHtml: function (iframeUrl, iframeName) {
  1033. return _createIFrameHtml(iframeUrl, iframeName);
  1034. },
  1035. // 显示一个弹出窗体
  1036. // 在 panel 实例中,定义了几个自定义属性,用于标示此实例的状态(在PanelBase中定义)
  1037. // 属性 - x_iframe/x_iframe_url/x_iframe_name/x_iframe_loaded
  1038. // panel : 当前弹出的窗体(Ext-Window)
  1039. // iframeUrl : 弹出窗体中包含的IFrame的地址
  1040. // windowTitle : 弹出窗体的标题
  1041. // left/top : 弹出窗体的左上角坐标(如果为空字符串,则使用中间位置或黄金分隔位置)
  1042. // isGoldenSection : 弹出窗体位于页面的黄金分隔位置
  1043. // hiddenHiddenFieldID : 在页面中放置表单字段记录此窗体是否弹出,也页面回发时保持状态用
  1044. show: function (panel, iframeUrl, windowTitle, left, top, isGoldenSection, hiddenHiddenFieldID) {
  1045. var target = X.util.getTargetWindow(panel['box_property_target']);
  1046. var guid = panel['box_property_guid'];
  1047. if (window.frameElement && target !== window) {
  1048. // 当前页面在IFrame中(也即时 window.frameElement 存在)
  1049. // 此弹出窗体需要在父窗口中弹出
  1050. if (!target.X[guid]) {
  1051. // 父窗口中已经创建了这个Ext-Window对象
  1052. var wrapper = guid + '_wrapper';
  1053. if (!target.Ext.get(wrapper)) {
  1054. target.X.util.appendFormNode('<div class="x-window-wrapper" id="' + wrapper + '"></div>');
  1055. } else {
  1056. target.Ext.get(wrapper).dom.innerHTML = '';
  1057. }
  1058. // Ext.apply 的第三个参数是default obejct
  1059. var config = Ext.apply({}, {
  1060. 'renderTo': wrapper,
  1061. 'manager': target.X.window_default_group,
  1062. 'id': guid,
  1063. 'box_hide': null,
  1064. 'box_hide_refresh': null,
  1065. 'box_hide_postback': null,
  1066. 'box_show': null,
  1067. // 在 X.wnd.getActiveWindow 中需要用到这个参数
  1068. //'box_property_frame_element_name': window.frameElement.name,
  1069. //'box_property_client_id': panel.getId(),
  1070. 'box_property_window': window,
  1071. 'box_property_ext_window': panel
  1072. }, panel.initialConfig);
  1073. // 在父页面中创建一个Ext-Window的幻影(拷贝)
  1074. // 在这个幻影中,通过“box_property_frame_element_name”属性标示这是一个幻影
  1075. // box_property_frame_element_name: 并且真正的Ext-Window在当前页面中的哪个IFrame中
  1076. // box_property_client_id: 并且真正的Ext-Window在所在页面中的客户端ID
  1077. target.X[guid] = new target.Ext.Window(config);
  1078. }
  1079. panel = target.X[guid];
  1080. }
  1081. if (iframeUrl !== '') {
  1082. X.wnd.updateIFrameNode(panel, iframeUrl);
  1083. }
  1084. if (windowTitle != '') {
  1085. panel.setTitle(windowTitle);
  1086. }
  1087. var bodySize = target.window.Ext.getBody().getViewSize();
  1088. // // Update container's width and height
  1089. // var wrapperNode = _getWrapperNode(panel);
  1090. // wrapperNode.setWidth(bodySize.width).setHeight(bodySize.height);
  1091. //
  1092. // // 显示窗体之前,记着显示外部的容器
  1093. // …

Large files files are truncated, but you can click here to view the full file