IndentityList.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. MWF.xApplication.ExeManager = MWF.xApplication.ExeManager || {};
  2. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  3. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  4. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  5. MWF.xDesktop.requireApp("ExeManager","Attachment",null,false);
  6. MWF.require("MWF.widget.Identity", null,false);
  7. MWF.xApplication.ExeManager.IndentityList = new Class({
  8. Extends: MWF.widget.Common,
  9. Implements: [Options, Events],
  10. options: {
  11. "style": "default"
  12. },
  13. initialize: function (node, app, actions, options) {
  14. this.setOptions(options);
  15. this.app = app;
  16. this.lp = app.lp;
  17. this.path = "/x_component_ExeManager/$IndentityList/";
  18. this.loadCss();
  19. this.actions = actions;
  20. this.node = $(node);
  21. },
  22. loadCss: function () {
  23. this.cssPath = "/x_component_ExeManager/$IndentityList/" + this.options.style + "/css.wcss";
  24. this._loadCss();
  25. },
  26. load: function () {
  27. this.middleContent = this.app.middleContent;
  28. this.middleContent.setStyles({"margin-top":"0px","border":"0px solid #f00","background-color":"#ffffff"});
  29. this.createToolBarContent();
  30. this.createContentDiv();
  31. this.resizeWindow();
  32. this.app.addEvent("resize", function(){
  33. this.resizeWindow();
  34. }.bind(this));
  35. },
  36. reload: function(){
  37. this.createToolBarContent();
  38. this.createContentDiv();
  39. },
  40. resizeWindow: function(){
  41. var size = this.app.middleContent.getSize();
  42. this.contentDiv.setStyles({"height":(size.y-110)+"px"});
  43. },
  44. createToolBarContent: function(){
  45. if(this.toolBarDiv) this.toolBarDiv.destroy();
  46. this.toolBarDiv = new Element("div.toolBarDiv",{"styles":this.css.toolBarDiv}).inject(this.middleContent);
  47. this.toolBarActionDiv = new Element("div.toolBarActionDiv",{"styles":this.css.toolBarActionDiv}).inject(this.toolBarDiv);
  48. this.toolBarSearchDiv = new Element("div.toolBarSearchDiv",{"styles":this.css.toolBarSearchDiv}).inject(this.toolBarDiv);
  49. this.toolBarSearchInput = new Element("input.toolBarSearchInput",{
  50. "styles":this.css.toolBarSearchInput
  51. }).inject(this.toolBarSearchDiv);
  52. this.toolBarSearchInput.addEvents({
  53. "keyup":function(e){
  54. if(e.code == 13){
  55. this.searchView(this.toolBarSearchInput.get("value"))
  56. }
  57. }.bind(this)
  58. });
  59. this.toolBarSearchActionBtn = new Element("div.toolBarSearchBtn",{
  60. "styles":this.css.toolBarSearchBtn,
  61. "text": this.lp.IndentityList.searchAction
  62. }).inject(this.toolBarSearchDiv);
  63. this.toolBarSearchActionBtn.addEvents({
  64. "click":function(){
  65. this.searchView(this.toolBarSearchInput.get("value"))
  66. }.bind(this)
  67. });
  68. //this.toolBarSearchResetBtn = new Element("div.toolBarSearchBtn",{
  69. // "styles":this.css.toolBarSearchBtn,
  70. // "text":"重置"
  71. //}).inject(this.toolBarSearchDiv);
  72. this.toolBarStatusDiv = new Element("div.toolBarStatusDiv",{
  73. "styles":this.css.toolBarStatusDiv
  74. }).inject(this.toolBarDiv);
  75. this.toolBarStatusDiv.setStyle("display","none");
  76. this.toolBarStatusAllDiv = new Element("div.toolBarStatusAllDiv",{styles:this.css.toolBarStatusAllDiv}).inject(this.toolBarStatusDiv);
  77. this.toolBarStatusPercentDiv = new Element("div.toolBarStatusPercentDiv",{styles:this.css.toolBarStatusPercentDiv}).inject(this.toolBarStatusDiv);
  78. },
  79. createContentDiv: function(key){
  80. if(this.contentDiv) this.contentDiv.destroy();
  81. this.contentDiv = new Element("div.contentDiv",{"styles":this.css.contentDiv}).inject(this.middleContent);
  82. if(this.scrollBar && this.scrollBar.scrollVAreaNode){
  83. this.scrollBar.scrollVAreaNode.destroy();
  84. }
  85. MWF.require("MWF.widget.ScrollBar", function () {
  86. this.scrollBar = new MWF.widget.ScrollBar(this.contentDiv, {
  87. "indent": false,
  88. "style": "xApp_TaskList",
  89. "where": "before",
  90. "distance": 30,
  91. "friction": 4,
  92. "axis": {"x": false, "y": true},
  93. "onScroll": function (y) {
  94. var scrollSize = this.contentDiv.getScrollSize();
  95. var clientSize = this.contentDiv.getSize();
  96. var scrollHeight = scrollSize.y - clientSize.y;
  97. var view = this.view;
  98. if (y + 200 > scrollHeight && view && view.loadElementList) {
  99. if (! view.isItemsLoaded) view.loadElementList();
  100. }
  101. }.bind(this)
  102. });
  103. }.bind(this),false);
  104. var templateUrl = this.path+"listItem.json";
  105. var filter = {
  106. identity:key
  107. };
  108. if(this.view) delete this.view;
  109. this.view = new MWF.xApplication.ExeManager.IndentityList.View(this.contentDiv, this.app, {explorer:this,lp : this.lp.IndentityList, css : this.css, actions : this.actions }, { templateUrl : templateUrl,category:"",filterData:filter } );
  110. this.view.load();
  111. },
  112. searchView: function(key){
  113. this.createContentDiv(key);
  114. this.resizeWindow();
  115. },
  116. showErrorMsg: function(xhr,text,error){
  117. var errorText = error;
  118. var errorMessage;
  119. if (xhr) errorMessage = xhr.responseText;
  120. try{
  121. var e = JSON.parse(errorMessage);
  122. if (e && e.message) {
  123. this.app.notice(e.message, "error");
  124. } else {
  125. this.app.notice(errorText, "error");
  126. }
  127. }catch(e){
  128. this.app.notice("failure", "error");
  129. }
  130. }
  131. });
  132. MWF.xApplication.ExeManager.IndentityList.View = new Class({
  133. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  134. _createDocument: function(data){
  135. return new MWF.xApplication.ExeManager.IndentityList.Document(this.viewNode, data, this.explorer, this);
  136. },
  137. _getCurrentPageData: function(callback, count){
  138. if (!count)count = 20;
  139. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  140. var filter = this.options.filterData || {};
  141. if(id=="(0)")this.app.createShade();
  142. this.actions.getErrorIndentitytNext(id, count, filter, function (json) {
  143. if (callback)callback(json);
  144. this.app.destroyShade();
  145. }.bind(this),function(xhr,error,text){
  146. this.explorer.explorer.showErrorMsg(xhr,error,text)
  147. }.bind(this))
  148. },
  149. _create: function(){
  150. },
  151. _openDocument: function( documentData ){
  152. this.indentityForm = new MWF.xApplication.ExeManager.IndentityList.IndentityForm(this.explorer.explorer, this.actions, documentData, {
  153. "isNew": false,
  154. "isEdited": false,
  155. "onReloadView" : function( data ){
  156. this.app.topBarContent.getElements(".topBarLi").each(function(d){
  157. if(d.get("id") == "topIndentity"){
  158. d.click()
  159. }
  160. }.bind(this));
  161. }.bind(this)
  162. });
  163. this.indentityForm.load();
  164. },
  165. _queryCreateViewNode: function(){
  166. },
  167. _postCreateViewNode: function( viewNode ){
  168. },
  169. _queryCreateViewHead:function(){
  170. },
  171. _postCreateViewHead: function( headNode ){
  172. }
  173. });
  174. MWF.xApplication.ExeManager.IndentityList.Document = new Class({
  175. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  176. action_open: function(e){
  177. }
  178. });
  179. MWF.xApplication.ExeManager.IndentityList.IndentityForm = new Class({
  180. Extends: MPopupForm,
  181. Implements: [Options, Events],
  182. options: {
  183. "style": "default",
  184. "width": "90%",
  185. "height": "100%",
  186. "top" : 0,
  187. "left" : 0,
  188. "hasTop": true,
  189. "hasIcon": false,
  190. "hasBottom": true,
  191. "title": "",
  192. "draggable": false,
  193. "closeAction": true,
  194. "isNew": false,
  195. "isEdited": false
  196. },
  197. initialize: function (explorer, actions, data, options) {
  198. this.setOptions(options);
  199. this.explorer = explorer;
  200. this.app = explorer.app;
  201. this.lp = this.app.lp.indentityForm;
  202. this.actions = this.app.restActions;
  203. this.path = "/x_component_ExeManager/$IndentityList/";
  204. this.cssPath = this.path + this.options.style + "/indentityForm.wcss";
  205. this._loadCss();
  206. this.options.title = this.lp.title;
  207. this.data = data || {};
  208. this.actions = actions;
  209. },
  210. load: function () {
  211. if(this.data.id){
  212. //var data = {identity:"史敬(市场部)"}
  213. var data = {identity:this.data.identity};
  214. this.actions.getErrorIdentityDetail(data,function(json){
  215. if(json.data) this.detailsData = json.data;
  216. }.bind(this),null,false)
  217. }
  218. if (this.options.isNew) {
  219. this.create();
  220. } else if (this.options.isEdited) {
  221. this.edit();
  222. } else {
  223. this.open();
  224. }
  225. },
  226. _open: function () {
  227. this.formMarkNode = new Element("div.formMarkNode", {
  228. "styles": this.css.formMarkNode,
  229. "events": {
  230. "mouseover": function (e) {
  231. e.stopPropagation();
  232. },
  233. "mouseout": function (e) {
  234. e.stopPropagation();
  235. },
  236. "click": function (e) {
  237. e.stopPropagation();
  238. }
  239. }
  240. }).inject(this.app.content);
  241. this.formAreaNode = new Element("div.formAreaNode", {
  242. "styles": this.css.formAreaNode
  243. });
  244. this.createFormNode();
  245. this.formAreaNode.inject(this.formMarkNode, "after");
  246. this.formAreaNode.fade("in");
  247. this.setFormNodeSize();
  248. this.setFormNodeSizeFun = this.setFormNodeSize.bind(this);
  249. this.app.addEvent("resize", this.setFormNodeSizeFun);
  250. if (this.options.draggable && this.formTopNode) {
  251. var size = this.app.content.getSize();
  252. var nodeSize = this.formAreaNode.getSize();
  253. this.formAreaNode.makeDraggable({
  254. "handle": this.formTopNode,
  255. "limit": {
  256. "x": [0, size.x - nodeSize.x],
  257. "y": [0, size.y - nodeSize.y]
  258. }
  259. });
  260. }
  261. },
  262. createTopNode: function () {
  263. if (!this.formTopNode) {
  264. this.formTopNode = new Element("div.formTopNode", {
  265. "styles": this.css.formTopNode
  266. }).inject(this.formNode);
  267. this.formTopIconNode = new Element("div", {
  268. "styles": this.css.formTopIconNode
  269. }).inject(this.formTopNode);
  270. this.formTopTextNode = new Element("div", {
  271. "styles": this.css.formTopTextNode,
  272. "text": this.options.title
  273. }).inject(this.formTopNode);
  274. if (this.options.closeAction) {
  275. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  276. this.formTopCloseActionNode.addEvent("click", function () {
  277. this.close()
  278. }.bind(this))
  279. }
  280. this.formTopContentNode = new Element("div", {
  281. "styles": this.css.formTopContentNode
  282. }).inject(this.formTopNode);
  283. this._createTopContent();
  284. }
  285. },
  286. _createTopContent: function () {
  287. },
  288. _createTableContent: function () {
  289. if(this.formTableArea) this.formTableArea.empty();
  290. this.modifyDiv = new Element("div.modifyDiv",{"styles":this.css.modifyDiv}).inject(this.formTableArea);
  291. this.oldIdentitySpan = new Element("span.oldIdentitySpan",{"styles":this.css.oldIdentitySpan,"text":this.lp.oldIdentity+": "+this.data.identity}).inject(this.modifyDiv);
  292. this.newIdentitySpan = new Element("span.newIdentitySpan",{"styles":this.css.newIdentitySpan,"text":this.lp.newIdentity+": "}).inject(this.modifyDiv);
  293. this.newIdentityInput = new Element("input.newIdentityInput",{
  294. "styles":this.css.newIdentityInput,
  295. "readonly":true,
  296. "type":"text"
  297. }).inject(this.modifyDiv);
  298. this.newIdentityInput.addEvents({
  299. "click":function(){
  300. this.selectPerson(this.newIdentityInput,"identity");
  301. }.bind(this)
  302. });
  303. this.modifyBottonDiv = new Element("div.modifyBottonDiv",{
  304. "styles":this.css.modifyBottonDiv,
  305. "text":this.lp.modify
  306. }).inject(this.modifyDiv);
  307. this.modifyBottonDiv.addEvents({
  308. "click":function(e){
  309. if(this.newIdentityInput.get("value") == ""){
  310. this.app.notice(this.lp.newIdentityEmpty,"error");
  311. }else{
  312. this.replaceIdentity(e);
  313. }
  314. }.bind(this)
  315. })
  316. this.contentDiv = new Element("div.contentDiv",{"styles":this.css.contentDiv}).inject(this.formTableArea);
  317. this.naviTabDiv = new Element("div.naviTabDiv",{"styles":this.css.naviTabDiv}).inject(this.contentDiv);
  318. if(this.detailsData){
  319. var _self = this;
  320. this.detailsData.each(function(d){
  321. var categoryLi = new Element("li.categoryLi",{
  322. "styles" : this.css.categoryLi,
  323. "text": d.recordType
  324. }).inject(this.naviTabDiv);
  325. categoryLi.addEvents({
  326. "click":function(){
  327. _self.loadList(this);
  328. }
  329. });
  330. }.bind(_self));
  331. _self.naviTabDiv.getElements("li")[0].click();
  332. }
  333. },
  334. _createBottomContent: function () {
  335. this.cancelActionNode = new Element("div.formCancelActionNode", {
  336. "styles": this.css.formCancelActionNode,
  337. "text": this.lp.close
  338. }).inject(this.formBottomNode);
  339. this.cancelActionNode.addEvent("click", function (e) {
  340. this.cancel(e);
  341. }.bind(this));
  342. },
  343. loadList:function(o){
  344. this.naviTabDiv.getElements("li").setStyles({"border-bottom":""});
  345. o.setStyles({"border-bottom":"2px solid #124c93"});
  346. if(this.contentList) this.contentList.destroy();
  347. this.contentList = new Element("div.contentList",{"styles":this.css.contentList}).inject(this.formTableArea);
  348. if(this.table) this.table.destroy();
  349. this.table = new Element("table.table",{"styles":{"width":"100%"}}).inject(this.contentList);
  350. var tr = new Element("tr.tr").inject(this.table);
  351. var td = new Element("td.td",{"text":this.lp.tableTitle,"align":"left","styles":{"padding-left":"200px","font-weight":"bold"}}).inject(tr);
  352. this.detailsData.each(function(d){
  353. if(d.recordType == o.get("text")){
  354. this.listData = d.errorRecords;
  355. }
  356. }.bind(this));
  357. this.listData.each(function(d,i){
  358. tr = new Element("tr.tr").inject(this.table);
  359. var color = i%2 == 0?"#f1f1f1":"#fff";
  360. tr.setStyles({"background-color":color});
  361. td = new Element("td.td",{
  362. "styles":this.css.tableTd,
  363. "text": d.title
  364. }).inject(tr)
  365. }.bind(this))
  366. },
  367. replaceIdentity:function(e){
  368. var _self = this;
  369. this.app.confirm("warn",e,this.lp.warn.warnTitle,this.lp.warn.warnContent,300,120,function(){
  370. var submitData = {
  371. oldIdentity:_self.data.identity,
  372. newIdentity :_self.newIdentityInput.get("value"),
  373. recordType:"all",
  374. recordId:"all",
  375. tableName:"all"
  376. };
  377. _self.app.createShade();
  378. _self.actions.replaceErrorIdentity(submitData, function(json){
  379. _self.app.notice(_self.lp.modifySuccess,"success");
  380. _self.app.destroyShade();
  381. _self.close();
  382. _self.fireEvent("reloadView");
  383. }.bind(_self),function(xhr,text,error){
  384. _self.app.showErrorMessage(xhr,text,error);
  385. _self.app.destroyShade();
  386. }.bind(_self));
  387. this.close();
  388. },function(){
  389. this.close();
  390. })
  391. },
  392. selectPerson: function( item, type ){
  393. MWF.xDesktop.requireApp("Organization", "Selector.package",null, false);
  394. this.fireEvent("querySelect", this);
  395. var value = item.get("value").split( this.valSeparator );
  396. var options = {
  397. "type": type,
  398. "title": "select",
  399. "count" : 1,
  400. "names": value || [],
  401. //"departments" : this.options.departments,
  402. //"companys" : this.options.companys,
  403. "onComplete": function(items){
  404. var arr = [];
  405. items.each(function(item){
  406. arr.push(item.data.name);
  407. }.bind(this));
  408. item.set("value",arr.join(","));
  409. //this.items[0].fireEvent("change");
  410. }.bind(this)
  411. };
  412. var selector = new MWF.OrgSelector(this.app.content, options);
  413. }
  414. });