IndentityList.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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. _close: function(){
  263. if(this.formMarkNode)this.formMarkNode.destroy()
  264. },
  265. createTopNode: function () {
  266. if (!this.formTopNode) {
  267. this.formTopNode = new Element("div.formTopNode", {
  268. "styles": this.css.formTopNode
  269. }).inject(this.formNode);
  270. this.formTopIconNode = new Element("div", {
  271. "styles": this.css.formTopIconNode
  272. }).inject(this.formTopNode);
  273. this.formTopTextNode = new Element("div", {
  274. "styles": this.css.formTopTextNode,
  275. "text": this.options.title
  276. }).inject(this.formTopNode);
  277. if (this.options.closeAction) {
  278. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  279. this.formTopCloseActionNode.addEvent("click", function () {
  280. this.close()
  281. }.bind(this))
  282. }
  283. this.formTopContentNode = new Element("div", {
  284. "styles": this.css.formTopContentNode
  285. }).inject(this.formTopNode);
  286. this._createTopContent();
  287. }
  288. },
  289. _createTopContent: function () {
  290. },
  291. _createTableContent: function () {
  292. if(this.formTableArea) this.formTableArea.empty();
  293. this.modifyDiv = new Element("div.modifyDiv",{"styles":this.css.modifyDiv}).inject(this.formTableArea);
  294. this.oldIdentitySpan = new Element("span.oldIdentitySpan",{"styles":this.css.oldIdentitySpan,"text":this.lp.oldIdentity+": "+this.data.identity}).inject(this.modifyDiv);
  295. this.newIdentitySpan = new Element("span.newIdentitySpan",{"styles":this.css.newIdentitySpan,"text":this.lp.newIdentity+": "}).inject(this.modifyDiv);
  296. this.newIdentityInput = new Element("input.newIdentityInput",{
  297. "styles":this.css.newIdentityInput,
  298. "readonly":true,
  299. "type":"text"
  300. }).inject(this.modifyDiv);
  301. this.newIdentityInput.addEvents({
  302. "click":function(){
  303. this.selectPerson(this.newIdentityInput,"identity");
  304. }.bind(this)
  305. });
  306. this.modifyBottonDiv = new Element("div.modifyBottonDiv",{
  307. "styles":this.css.modifyBottonDiv,
  308. "text":this.lp.modify
  309. }).inject(this.modifyDiv);
  310. this.modifyBottonDiv.addEvents({
  311. "click":function(e){
  312. if(this.newIdentityInput.get("value") == ""){
  313. this.app.notice(this.lp.newIdentityEmpty,"error");
  314. }else{
  315. this.replaceIdentity(e);
  316. }
  317. }.bind(this)
  318. });
  319. this.contentDiv = new Element("div.contentDiv",{"styles":this.css.contentDiv}).inject(this.formTableArea);
  320. this.naviTabDiv = new Element("div.naviTabDiv",{"styles":this.css.naviTabDiv}).inject(this.contentDiv);
  321. if(this.detailsData){
  322. var _self = this;
  323. this.detailsData.each(function(d){
  324. var categoryLi = new Element("li.categoryLi",{
  325. "styles" : this.css.categoryLi,
  326. "text": d.recordType
  327. }).inject(this.naviTabDiv);
  328. categoryLi.addEvents({
  329. "click":function(){
  330. _self.loadList(this);
  331. }
  332. });
  333. }.bind(_self));
  334. _self.naviTabDiv.getElements("li")[0].click();
  335. }
  336. },
  337. _createBottomContent: function () {
  338. this.cancelActionNode = new Element("div.formCancelActionNode", {
  339. "styles": this.css.formCancelActionNode,
  340. "text": this.lp.close
  341. }).inject(this.formBottomNode);
  342. this.cancelActionNode.addEvent("click", function (e) {
  343. this.cancel(e);
  344. }.bind(this));
  345. },
  346. loadList:function(o){
  347. this.naviTabDiv.getElements("li").setStyles({"border-bottom":""});
  348. o.setStyles({"border-bottom":"2px solid #124c93"});
  349. if(this.contentList) this.contentList.destroy();
  350. this.contentList = new Element("div.contentList",{"styles":this.css.contentList}).inject(this.formTableArea);
  351. if(this.table) this.table.destroy();
  352. this.table = new Element("table.table",{"styles":{"width":"100%"}}).inject(this.contentList);
  353. var tr = new Element("tr.tr").inject(this.table);
  354. var td = new Element("td.td",{"text":this.lp.tableTitle,"align":"left","styles":{"padding-left":"200px","font-weight":"bold"}}).inject(tr);
  355. this.detailsData.each(function(d){
  356. if(d.recordType == o.get("text")){
  357. this.listData = d.errorRecords;
  358. }
  359. }.bind(this));
  360. this.listData.each(function(d,i){
  361. tr = new Element("tr.tr").inject(this.table);
  362. var color = i%2 == 0?"#f1f1f1":"#fff";
  363. tr.setStyles({"background-color":color});
  364. td = new Element("td.td",{
  365. "styles":this.css.tableTd,
  366. "text": d.title
  367. }).inject(tr)
  368. }.bind(this))
  369. },
  370. replaceIdentity:function(e){
  371. var _self = this;
  372. this.app.confirm("warn",e,this.lp.warn.warnTitle,this.lp.warn.warnContent,300,120,function(){
  373. var submitData = {
  374. oldIdentity:_self.data.identity,
  375. newIdentity :_self.newIdentityInput.get("value"),
  376. recordType:"all",
  377. recordId:"all",
  378. tableName:"all"
  379. };
  380. _self.app.createShade();
  381. _self.actions.replaceErrorIdentity(submitData, function(json){
  382. _self.app.notice(_self.lp.modifySuccess,"success");
  383. _self.app.destroyShade();
  384. _self.close();
  385. _self.fireEvent("reloadView");
  386. }.bind(_self),function(xhr,text,error){
  387. _self.app.showErrorMessage(xhr,text,error);
  388. _self.app.destroyShade();
  389. }.bind(_self));
  390. this.close();
  391. },function(){
  392. this.close();
  393. })
  394. },
  395. selectPerson: function( item, type ){
  396. MWF.xDesktop.requireApp("Organization", "Selector.package",null, false);
  397. this.fireEvent("querySelect", this);
  398. var value = item.get("value").split( this.valSeparator );
  399. var options = {
  400. "type": type,
  401. "title": "select",
  402. "count" : 1,
  403. "names": value || [],
  404. //"departments" : this.options.departments,
  405. //"companys" : this.options.companys,
  406. "onComplete": function(items){
  407. var arr = [];
  408. items.each(function(item){
  409. arr.push(item.data.name);
  410. }.bind(this));
  411. item.set("value",arr.join(","));
  412. //this.items[0].fireEvent("change");
  413. }.bind(this)
  414. };
  415. var selector = new MWF.OrgSelector(this.app.content, options);
  416. }
  417. });