Importer.js 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947
  1. MWF.xApplication.query = MWF.xApplication.query || {};
  2. MWF.xApplication.query.Query = MWF.xApplication.query.Query || {};
  3. MWF.require("MWF.widget.Common", null, false);
  4. MWF.require("MWF.xScript.Macro", null, false);
  5. MWF.require("o2.widget.Dialog", null, false);
  6. MWF.xDesktop.requireApp("query.Query", "lp."+o2.language, null, false);
  7. /** @classdesc Importer 数据中心的导入模型。
  8. * @class
  9. * @o2cn 导入模型
  10. * @o2category QueryImporter
  11. * @o2range {QueryImporter}
  12. * @hideconstructor
  13. * @example
  14. * //在导入模型的事件中获取该类
  15. * var view = this.target;
  16. * */
  17. MWF.xApplication.query.Query.Importer = MWF.QImporter = new Class(
  18. /** @lends MWF.xApplication.query.Query.Importer# */
  19. {
  20. Implements: [Options, Events],
  21. Extends: MWF.widget.Common,
  22. options: {
  23. "style": "default",
  24. "moduleEvents": [
  25. /**
  26. * 加载importer(导入模型对象)的时候执行。可通过this.target获取当前对象。
  27. * @event MWF.xApplication.query.Query.Importer#queryLoad
  28. */
  29. "queryLoad",
  30. /**
  31. * 导入前触发,this.event指向导入的数据,您可以通过修改this.event来修改数据。
  32. * @event MWF.xApplication.query.Query.Importer#beforeImport
  33. * @example
  34. * <caption>this.event数据格式如下:</caption>
  35. *[
  36. * [ "标题一","张三","男","大学本科","计算机","2001-1-2","2019-9-2" ], //第一行数据
  37. * [ "标题二","李四","男","大学专科","数学","1998-1-2","2018-9-2" ] //第二行数据
  38. *]
  39. */
  40. "beforeImport",
  41. /**
  42. * 前台校验成功,并且后台执行完导入后触发,this.event指向后台返回的导入结果。
  43. * @event MWF.xApplication.query.Query.Importer#afterImport
  44. * @example
  45. * <caption>this.event格式如下:</caption>
  46. * {
  47. * "status": "导入成功", //导入结果:状态有 "导入成功","部分成功","导入失败"
  48. * "data": {}, //前台组织好的需要导入的数据
  49. * "rowList": [], //前台组织的行对象数组
  50. * "count" : 10, //导入总数量
  51. * "failCount": 0, //失败数量
  52. * "distribution": "" //导入时候时的错误信息
  53. * }
  54. */
  55. "afterImport",
  56. /**
  57. * 数据已经生成,前台进行数据校验时触发,this.event指向导入的数据。
  58. * @event MWF.xApplication.query.Query.Importer#validImport
  59. * @example
  60. * <caption>this.event数据格式如下:</caption>
  61. * {
  62. * "data" : [
  63. * [ "标题一","张三","男","大学本科","计算机","2001-1-2","2019-9-2" ], //第一行数据
  64. * [ "标题二","李四","男","大学专科","数学","1998-1-2","2018-9-2" ] //第二行数据
  65. * ],
  66. * "rowList": [], //导入的行对象,数据格式常见本章API的afterCreateRowData说明。
  67. * "validted" : true //是否校验通过,可以在本事件中修改该参数,确定是否强制导入
  68. * }
  69. */
  70. "validImport",
  71. /**
  72. * 创建每行需要导入的数据前触发,this.event指向当前行对象,您可以通过修改this.event.importData来修改数据。
  73. * @event MWF.xApplication.query.Query.Importer#beforeCreateRowData
  74. */
  75. "beforeCreateRowData",
  76. /**
  77. * 创建每行需要导入的数据后触发,this.event指向当前行对象。
  78. * @event MWF.xApplication.query.Query.Importer#afterCreateRowData
  79. * @example
  80. * <caption>this.event格式如下:</caption>
  81. * {
  82. * "importedData": [ "标题一","张三","男","大学本科","计算机","2001-1-2","2019-9-2" ], //导入的数据
  83. * "data" : {//根据导入模型生成的业务数据
  84. * {
  85. * "subject", "标题一", //subject为导入模型列配置的路径
  86. * "name" : "张三",
  87. * ...
  88. * },
  89. * "document": { //如果导入目标是内容管理,则包含document对象
  90. * "title": "标题一"
  91. * "identity": "xxx@xxx@I"
  92. * ...
  93. * },
  94. * "work": { //如果导入目标是流程管理,则包含work对象
  95. * "title": "标题一"
  96. * "identity": "xxx@xxx@I"
  97. * ...
  98. * },
  99. * "errorTextList" : [], //错误信息
  100. * "errorTextListExcel": [] //在出错界面导出Excel时的错误信息
  101. * }
  102. */
  103. "afterCreateRowData"
  104. ]
  105. },
  106. initialize: function(container, json, options, app, parentMacro){
  107. this.setOptions(options);
  108. this.path = "../x_component_query_Query/$Importer/";
  109. this.cssPath = "../x_component_query_Query/$Importer/"+this.options.style+"/css.wcss";
  110. this._loadCss();
  111. this.lp = MWF.xApplication.query.Query.LP;
  112. this.app = app;
  113. this.json = json;
  114. this.container = container;
  115. this.parentMacro = parentMacro;
  116. this.lookupAction = MWF.Actions.get("x_query_assemble_surface");
  117. },
  118. load: function(){
  119. this.excelUtils = new MWF.xApplication.query.Query.Importer.ExcelUtils();
  120. this.getImporterJSON( function () {
  121. this.loadMacro( function () {
  122. this._loadModuleEvents();
  123. this.fireEvent("queryLoad");
  124. this.importFromExcel();
  125. }.bind(this));
  126. }.bind(this));
  127. },
  128. loadMacro: function (callback) {
  129. MWF.require("MWF.xScript.Macro", function () {
  130. this.Macro = new MWF.Macro.ViewContext(this);
  131. if (callback) callback();
  132. }.bind(this));
  133. },
  134. createLoadding: function(){
  135. this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.contentAreaNode);
  136. new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
  137. var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
  138. new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
  139. var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
  140. loadingTextNode.set("text", "loading...");
  141. },
  142. getImporterJSON: function(callback){
  143. if( this.importerJson && this.json ){
  144. if (callback) callback();
  145. }else{
  146. if (this.json.name){
  147. this.lookupAction.getImportModel(this.json.name, this.json.application, function(json){
  148. this.importerId = json.data.id;
  149. this.importerJson = JSON.decode(json.data.data);
  150. json.data.data = this.importerJson;
  151. this.json = Object.merge(this.json, json.data);
  152. if (callback) callback();
  153. }.bind(this));
  154. }else{
  155. this.lookupAction.getImportModelById(this.json.id, function(json){
  156. this.importerId = json.data.id;
  157. this.importerJson = JSON.decode(json.data.data);
  158. json.data.data = this.importerJson;
  159. this.json.application = json.data.query;
  160. this.json = Object.merge(this.json, json.data);
  161. if (callback) callback();
  162. }.bind(this));
  163. }
  164. }
  165. },
  166. _loadModuleEvents : function(){
  167. Object.each(this.json.data.events, function(e, key){
  168. if (e.code){
  169. if (this.options.moduleEvents.indexOf(key)!==-1){
  170. this.addEvent(key, function(event, target){
  171. return this.Macro.fire(e.code, target || this, event);
  172. }.bind(this));
  173. }
  174. }
  175. }.bind(this));
  176. },
  177. getDateColIndexArray: function(){
  178. var dateColIndexArray = [];
  179. this.json.data.columnList.each(function(columnJson, index){
  180. var dataType = this.json.type === "dynamicTable" ? columnJson.dataType_Querytable : columnJson.dataType_CMSProcess;
  181. if( ["date","dateTime"].contains(dataType) )dateColIndexArray.push( index );
  182. }.bind(this));
  183. return dateColIndexArray;
  184. },
  185. getOrgColIndexArray : function(){
  186. var orgColIndexArray = [];
  187. this.json.data.columnList.each(function(columnJson, index){
  188. if( columnJson.isName ) {
  189. orgColIndexArray.push(index);
  190. }
  191. // }else if( this.json.type === "cms" ){
  192. // if( columnJson.isPublisher || columnJson.isAuthor || columnJson.isReader ){
  193. // orgColIndexArray.push( index );
  194. // }
  195. // }
  196. }.bind(this));
  197. return orgColIndexArray;
  198. },
  199. importFromExcel : function(){
  200. this.rowList = [];
  201. this.identityMapImported = {};
  202. this.personMapImported = {};
  203. this.unitMapImported = {};
  204. this.groupMapImported = {};
  205. this.lookupAction.getUUID( function (json){
  206. this.recordId = json.data;
  207. }.bind(this), null, false);
  208. this.excelUtils.upload( this.getDateColIndexArray(), function (importedData) {
  209. importedData = importedData.filter(function (array) {
  210. for( var i=0; i<array.length; i++ ){
  211. if(array[i])return true;
  212. }
  213. return false;
  214. });
  215. if( !importedData.length )return;
  216. var titleLength = importedData[0].length;
  217. importedData.each(function (array) {
  218. for( var i=0; i<titleLength; i++){
  219. if( typeOf(array[i]) === "null" )array[i] = "";
  220. }
  221. })
  222. this.progressBar = new MWF.xApplication.query.Query.Importer.ProgressBar( this, {
  223. "onPostShow": function(){
  224. this.progressBar.showCheckData();
  225. debugger;
  226. this.importedData = importedData;
  227. if( this.importedData.length > 0 )this.importedData.shift();
  228. this.fireEvent("beforeImport", [this.importedData]);
  229. Promise.resolve( this.importedData.promise ).then(function () {
  230. this.listOrgDataFromDb(
  231. this.getImportedOrgData(),
  232. function () {
  233. this.importedData.each( function( lineData, lineIndex ){
  234. this.rowList.push( new MWF.xApplication.query.Query.Importer.Row( this, lineData, lineIndex ) )
  235. }.bind(this));
  236. var isValid = this.json.enableValid ? this.checkImportedData() : this.checkNecessaryImportedData();
  237. Promise.resolve(isValid).then(function ( isValid1 ) {
  238. if( isValid1 ){
  239. this.doImportData();
  240. }else{
  241. this.openImportedErrorDlg();
  242. }
  243. }.bind(this));
  244. }.bind(this)
  245. );
  246. }.bind(this));
  247. }.bind(this)
  248. });
  249. this.progressBar.importerId = this.importerId;
  250. }.bind(this));
  251. },
  252. getData : function(){
  253. var data = ( this.rowList || [] ).map( function(row){
  254. return row.getResult();
  255. });
  256. return data;
  257. },
  258. doImportData: function(){
  259. //创建数据
  260. // this.rowList.each( function( row, i ){
  261. // row.createData();
  262. // }.bind(this));
  263. //再次校验数据(计算的内容)
  264. var date = new Date();
  265. //var flag = true;
  266. // this.rowList.each( function(row, index){
  267. // if( row.errorTextList.length )flag = false;
  268. // }.bind(this));
  269. // var arg = {
  270. // validted : flag,
  271. // data : this.importedData,
  272. // rowList : this.rowList
  273. // };
  274. // this.fireEvent( "import", [arg] );
  275. // Promise.resolve( arg.promise ).then(function(){
  276. // flag = arg.validted;
  277. //
  278. // if( !flag ){
  279. // this.openImportedErrorDlg();
  280. // return;
  281. // }
  282. var data = this.getData();
  283. // this.lookupAction.getUUID(function(json){
  284. // this.recordId = json.data;
  285. this.lookupAction.executImportModel(this.json.id, {
  286. "recordId": this.recordId,
  287. "data" : data
  288. }, function () {
  289. //this.showImportingStatus( data, date )
  290. this.progressBar.showImporting( this.recordId, function( data ){
  291. data.data = data;
  292. data.rowList = this.rowList;
  293. this.fireEvent("afterImport", data);
  294. return data;
  295. }.bind(this), date);
  296. }.bind(this), function (xhr) {
  297. var requestJson = JSON.parse(xhr.responseText);
  298. this.app.notice(requestJson.message, "error");
  299. this.progressBar.close();
  300. }.bind(this))
  301. // }.bind(this))
  302. // }.bind(this))
  303. },
  304. objectToString: function (obj, type) {
  305. if(!obj)return "";
  306. var arr = [];
  307. Object.each(obj, function (value, key) {
  308. if( type === "style" ){
  309. arr.push( key + ":"+ value +";" );
  310. }else{
  311. arr.push( key + "='"+ value +"'" );
  312. }
  313. })
  314. return arr.join( " " )
  315. },
  316. openImportedErrorDlg : function(){
  317. if(this.progressBar)this.progressBar.close();
  318. var _self = this;
  319. var div = new Element("div", { style : "padding:10px;" });
  320. var dlg = o2.DL.open({
  321. "style" : "user",
  322. "title": this.lp.importFail,
  323. "content": div,
  324. "offset": {"y": 0},
  325. "isMax": true,
  326. "width": 1000,
  327. "height": 700,
  328. "buttonList": [
  329. {
  330. "type": "exportWithError",
  331. "text": this.lp.exportExcel,
  332. "action": function () { _self.exportWithImportDataToExcel(); }
  333. },
  334. {
  335. "type": "cancel",
  336. "text": this.lp.cancel,
  337. "action": function () { dlg.close(); }
  338. }
  339. ],
  340. "onPostShow": function () {
  341. var htmlArray = ["<table "+ this.objectToString( this.css.properties ) +" style='"+this.objectToString( this.css.tableStyles, "style" )+"'>"];
  342. var titleStyle = this.objectToString( this.css.titleStyles, "style" );
  343. var vaildTitleStyles = this.objectToString( this.css.vaildTitleStyles, "style" );
  344. htmlArray.push( "<tr>" );
  345. this.json.data.columnList.each( function (columnJson, i) {
  346. htmlArray.push( "<th style='"+titleStyle+"'>"+columnJson.displayName+"</th>" );
  347. });
  348. htmlArray.push( "<th style='"+vaildTitleStyles+"'> "+this.lp.validationInfor +"</th>" );
  349. htmlArray.push( "</tr>" );
  350. var contentStyles = Object.clone( this.css.contentStyles );
  351. if( !contentStyles[ "border-bottom" ] && !contentStyles[ "border" ] )contentStyles[ "border-bottom" ] = "1px solid #eee";
  352. var contentStyle = this.objectToString( Object.merge( contentStyles, {"text-align":"left"}) , "style" );
  353. var validContentStyles = this.objectToString( this.css.validContentStyles, "style" );
  354. this.rowList.each( function( row, lineIndex ){
  355. var lineData = row.importedData;
  356. htmlArray.push( "<tr>" );
  357. this.json.data.columnList.each( function (columnJson, i) {
  358. var d = lineData[ i ];
  359. var text = typeOf(d) === "string" ? ( d || '' ).replace(/&#10;/g,"<br/>") : d;
  360. htmlArray.push( "<td style='"+contentStyle+"'>"+ text +"</td>" ); //换行符&#10;
  361. });
  362. htmlArray.push( "<td style='"+validContentStyles+"'>"+( row.errorTextList ? row.errorTextList.join("<br/>") : "" )+"</td>" );
  363. htmlArray.push( "</tr>" );
  364. }.bind(this));
  365. htmlArray.push( "</table>" );
  366. div.set("html" , htmlArray.join(""));
  367. }.bind(this),
  368. "onPostClose": function(){
  369. dlg = null;
  370. }.bind(this)
  371. });
  372. },
  373. //必须校验的数据
  374. checkNecessaryImportedData: function(){
  375. var flag = true;
  376. var ps = this.rowList.each( function(row, index){
  377. return row.checkNecessary();
  378. }.bind(this));
  379. return Promise.all( ps ).then(function (arr) {
  380. for( var i=0; i<arr.length; i++ ){
  381. if( arr[i] === false )flag = false;
  382. }
  383. var arg = {
  384. validted : flag,
  385. data : this.importedData,
  386. rowList : this.rowList
  387. };
  388. this.fireEvent( "validImport", [arg] );
  389. return Promise.resolve( arg.promise ).then(function () {
  390. return arg.validted;
  391. });
  392. })
  393. },
  394. //校验Excel中的数据
  395. checkImportedData : function(){
  396. var flag = true;
  397. var ps = this.rowList.map( function(row, index){
  398. return row.checkValid();
  399. }.bind(this));
  400. return Promise.all(ps).then(function (arr) {
  401. for( var i=0; i<arr.length; i++ ){
  402. if( arr[i] === false )flag = false
  403. }
  404. var arg = {
  405. validted : flag,
  406. data : this.importedData,
  407. rowList : this.rowList
  408. };
  409. this.fireEvent( "validImport", [arg] );
  410. return Promise.resolve( arg.promise ).then(function () {
  411. return arg.validted;
  412. });
  413. }.bind(this));
  414. },
  415. getOrgData : function( str, ignoreNone, isParse ){
  416. str = str.trim();
  417. var flag = str.substr(str.length-2, 2);
  418. var d;
  419. switch (flag.toLowerCase()){
  420. case "@i":
  421. d = this.identityMapImported[str];
  422. break;
  423. case "@p":
  424. d = this.personMapImported[str];
  425. break;
  426. case "@u":
  427. d = this.unitMapImported[str];
  428. break;
  429. case "@g":
  430. d = this.groupMapImported[str];
  431. break;
  432. default:
  433. d = this.identityMapImported[str] ||
  434. this.personMapImported[str] ||
  435. this.unitMapImported[str] ||
  436. this.groupMapImported[str];
  437. break;
  438. }
  439. if( d )return isParse ? MWF.org.parseOrgData(d, true, true) : d;
  440. if( ignoreNone ) {
  441. return null;
  442. }else{
  443. return {"errorText": str + this.lp.notExistInSystem };
  444. }
  445. },
  446. getOrgExtendData: function( orgList ){
  447. var identityList = [], personList = [], unitList = [], groupList = [];
  448. orgList.each(function (org) {
  449. var a;
  450. switch (typeOf( org )) {
  451. case "string":
  452. a = org; break;
  453. case "object":
  454. a = org.distinguishedName || org.unique || org.employee; break;
  455. }
  456. if( !a )return;
  457. var d = this.getOrgData(a, true, false);
  458. if( d )return;
  459. var flag = a.substr(a.length - 2, 2);
  460. switch (flag.toLowerCase()) {
  461. case "@i":
  462. identityList.push(a);
  463. break;
  464. case "@p":
  465. personList.push(a);
  466. break;
  467. case "@u":
  468. unitList.push(a);
  469. break;
  470. case "@g":
  471. groupList.push(a);
  472. break;
  473. default:
  474. identityList.push(a);
  475. personList.push(a);
  476. unitList.push(a);
  477. groupList.push(a);
  478. break;
  479. }
  480. }.bind(this));
  481. return this.listOrgDataFromDb({
  482. identityList: identityList,
  483. personList: personList,
  484. unitList: unitList,
  485. groupList: groupList
  486. });
  487. },
  488. stringToArray: function(string){
  489. return string.replace(/[\n\r]/g,",").replace(/&#10;/g,",").split(/\s*,\s*/g ).filter(function(s){
  490. return !!s;
  491. });
  492. },
  493. getImportedOrgData: function() {
  494. var orgColIndexArray = this.getOrgColIndexArray();
  495. var identityList = [], personList = [], unitList = [], groupList = [];
  496. if( orgColIndexArray.length > 0 ) {
  497. this.importedData.each(function (lineData, lineIndex) {
  498. // if( lineIndex === 0 )return;
  499. orgColIndexArray.each(function (colIndex, i) {
  500. if (!lineData[colIndex]) return;
  501. var arr = this.stringToArray(lineData[colIndex]);
  502. arr.each(function (a) {
  503. a = a.trim();
  504. var flag = a.substr(a.length - 2, 2);
  505. switch (flag.toLowerCase()) {
  506. case "@i":
  507. identityList.push(a);
  508. break;
  509. case "@p":
  510. personList.push(a);
  511. break;
  512. case "@u":
  513. unitList.push(a);
  514. break;
  515. case "@g":
  516. groupList.push(a);
  517. break;
  518. default:
  519. identityList.push(a);
  520. personList.push(a);
  521. unitList.push(a);
  522. groupList.push(a);
  523. break;
  524. }
  525. })
  526. }.bind(this))
  527. }.bind(this));
  528. };
  529. return {
  530. identityList: identityList,
  531. personList: personList,
  532. unitList: unitList,
  533. groupList: groupList
  534. };
  535. },
  536. listOrgDataFromDb : function (importedOrgData, callback ) {
  537. var identityList = importedOrgData.identityList;
  538. var personList = importedOrgData.personList;
  539. var unitList = importedOrgData.unitList;
  540. var groupList = importedOrgData.groupList;
  541. var pIdentity;
  542. if( identityList && identityList.length ){
  543. pIdentity = o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({ identityList : identityList.unique() });
  544. }
  545. var pPerson;
  546. if( personList && personList.length ){
  547. pPerson = o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({ personList : personList.unique() });
  548. }
  549. var pUnit;
  550. if( unitList && unitList.length ){
  551. pUnit = o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({ unitList : unitList.unique() });
  552. }
  553. var pGroup;
  554. if( groupList && groupList.length ){
  555. pGroup = o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({ groupList : groupList.unique() });
  556. }
  557. return Promise.all( [pIdentity, pPerson, pUnit, pGroup] ).then(function (arr) {
  558. if( arr[0] && arr[0].data && arr[0].data.length ){
  559. arr[0].data.each( function (d) { if(d)this.identityMapImported[ d.matchKey ] = d; }.bind(this));
  560. }
  561. if( arr[1] && arr[1].data && arr[1].data.length ){
  562. arr[1].data.each( function (d) { if(d)this.personMapImported[ d.matchKey ] = d; }.bind(this));
  563. }
  564. if( arr[2] && arr[2].data && arr[2].data.length ){
  565. arr[2].data.each( function (d) { if(d)this.unitMapImported[ d.matchKey ] = d; }.bind(this));
  566. }
  567. if( arr[3] && arr[3].data && arr[3].data.length ){
  568. arr[3].data.each( function (d) { if(d)this.groupMapImported[ d.matchKey ] = d; }.bind(this));
  569. }
  570. if( callback )callback();
  571. return;
  572. }.bind(this))
  573. },
  574. // listOrgDataFromDb : function (importedOrgData, callback ) {
  575. //
  576. // var identityList = importedOrgData.identityList;
  577. // var personList = importedOrgData.personList;
  578. // var unitList = importedOrgData.unitList;
  579. // var groupList = importedOrgData.groupList;
  580. //
  581. // var identityLoaded, personLoaded, unitLoaded, groupLoaded;
  582. // var check = function () {
  583. // if( identityLoaded && personLoaded && unitLoaded && groupLoaded ){
  584. // if(callback)callback();
  585. // }
  586. // };
  587. //
  588. // if( identityList && identityList.length ){
  589. // identityList = identityList.unique();
  590. // o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({ identityList : identityList }, function (json) {
  591. // json.data.each( function (d) { if(d)this.identityMapImported[ d.matchKey ] = d; }.bind(this));
  592. // identityLoaded = true;
  593. // check();
  594. // }.bind(this))
  595. // }else{
  596. // identityLoaded = true;
  597. // check();
  598. // }
  599. //
  600. // if( personList && personList.length ){
  601. // personList = personList.unique();
  602. // o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({ personList : personList }, function (json) {
  603. // json.data.each( function (d) { if(d)this.personMapImported[ d.matchKey ] = d; }.bind(this));
  604. // personLoaded = true;
  605. // check();
  606. // }.bind(this))
  607. // }else{
  608. // personLoaded = true;
  609. // check();
  610. // }
  611. //
  612. // if( unitList && unitList.length ){
  613. // unitList = unitList.unique();
  614. // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({ unitList : unitList }, function (json) {
  615. // json.data.each( function (d) { if(d)this.unitMapImported[ d.matchKey ] = d; }.bind(this));
  616. // unitLoaded = true;
  617. // check();
  618. // }.bind(this))
  619. // }else{
  620. // unitLoaded = true;
  621. // check();
  622. // }
  623. //
  624. // if( groupList && groupList.length ){
  625. // groupList = groupList.unique();
  626. // o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({ groupList : groupList }, function (json) {
  627. // json.data.each( function (d) { if(d)this.groupMapImported[ d.matchKey ] = d; }.bind(this));
  628. // groupLoaded = true;
  629. // check();
  630. // }.bind(this))
  631. // }else{
  632. // groupLoaded = true;
  633. // check();
  634. // }
  635. // },
  636. // showImportingStatus: function( improtedData, date ){
  637. // this.progressBar.showImporting( this.recordId, function( data ){
  638. // data.data = improtedData;
  639. // data.rowList = this.rowList;
  640. // this.fireEvent("afterImport", data)
  641. // }.bind(this), date);
  642. // },
  643. exportWithImportDataToExcel : function ( importData ) {
  644. if( !this.excelUtils ){
  645. this.excelUtils = new MWF.xApplication.query.Query.Importer.ExcelUtils();
  646. }
  647. var exportTo = function () {
  648. var resultArr = [];
  649. var titleArr = this.getTitleArray();
  650. titleArr.push( this.lp.validationInfor );
  651. resultArr.push( titleArr );
  652. if( importData ){
  653. importData.each( function (lineData, lineIndex) {
  654. var array = [];
  655. if( o2.typeOf(lineData)==="array" ) {
  656. lineData.each(function (d, i) {
  657. array.push((d || '').replace(/&#10;/g, "\n"));
  658. });
  659. }else if(o2.typeOf(lineData)==="object"){
  660. this.json.data.columnList.each( function (columnJson, i) {
  661. array.push( lineData[columnJson.path] || "" )
  662. }.bind(this));
  663. if( lineData["o2ErrorText"] ){
  664. array.push( lineData["o2ErrorText"] );
  665. }
  666. }
  667. resultArr.push( array );
  668. }.bind(this));
  669. }else{
  670. this.rowList.each( function( row, lineIndex ){
  671. var lineData = row.importedData;
  672. var array = [];
  673. for( var i=0; i<lineData.length; i++ ){
  674. var d = ( lineData[i] || '' ).replace(/&#10;/g, "\n");
  675. array.push( d );
  676. }
  677. // lineData.each( function (d, i) {
  678. // array.push( ( d || '' ).replace(/&#10;/g, "\n") );
  679. // });
  680. array.push( row.errorTextListExcel ? row.errorTextListExcel.join("\n") : "" );
  681. resultArr.push( array );
  682. }.bind(this));
  683. }
  684. var colWidthArray = this.getColWidthArray();
  685. colWidthArray.push(260);
  686. var arg = {
  687. data : resultArr,
  688. colWidthArray : colWidthArray,
  689. title : this.getFileName()
  690. };
  691. this.fireEvent("export", [arg]);
  692. this.excelUtils.exportToExcel(
  693. arg.data,
  694. arg.title,
  695. arg.colWidthArray,
  696. this.getDateIndexArray()
  697. )
  698. }.bind(this);
  699. if( !this.importerJson ){
  700. this.getImporterJSON( function () {
  701. exportTo();
  702. }.bind(this))
  703. }else{
  704. exportTo();
  705. }
  706. },
  707. downloadTemplate: function(fileName, callback){
  708. if( this.Macro ){
  709. this._downloadTemplate(fileName, callback);
  710. }else{
  711. this.loadMacro(function (){
  712. this._downloadTemplate(fileName, callback);
  713. }.bind(this));
  714. }
  715. },
  716. _downloadTemplate: function(fileName, callback){
  717. if( !this.excelUtils ){
  718. this.excelUtils = new MWF.xApplication.query.Query.Importer.ExcelUtils({
  719. isTemplate: true
  720. });
  721. }
  722. var doExport = function () {
  723. var arg = {
  724. data : [this.getTitleArray()],
  725. colWidthArray : this.getColWidthArray(),
  726. title : this.getFileName(fileName)
  727. };
  728. if(callback)callback(arg);
  729. this.excelUtils.exportToExcel(
  730. arg.data,
  731. arg.title,
  732. arg.colWidthArray,
  733. this.getDateIndexArray()
  734. )
  735. }.bind(this)
  736. if( !this.importerJson ){
  737. this.getImporterJSON( function () {
  738. doExport()
  739. }.bind(this))
  740. }else{
  741. doExport();
  742. }
  743. },
  744. getFileName: function(fileName){
  745. var title = fileName || this.json.name;
  746. var titleA = title.split(".");
  747. if( ["xls","xlst"].contains( titleA[titleA.length-1].toLowerCase() ) ){
  748. titleA.splice( titleA.length-1 );
  749. }
  750. title = titleA.join(".");
  751. return title;
  752. },
  753. getTitleArray: function(){
  754. return this.json.data.columnList.map( function (columnJson, i) {
  755. var obj = {
  756. text: columnJson.displayName
  757. };
  758. if( columnJson.optionScript ){
  759. obj.options = this.Macro.exec(columnJson.optionScript, this);
  760. }
  761. return obj;
  762. }.bind(this));
  763. },
  764. getColWidthArray : function(){
  765. var colWidthArr = [];
  766. this.json.data.columnList.each( function (columnJson, i) {
  767. var dataType = this.json.type === "dynamicTable" ? columnJson.dataType_Querytable : columnJson.dataType_CMSProcess;
  768. switch ( dataType ) {
  769. case "string":
  770. case "stringList":
  771. if( columnJson.isName ){
  772. colWidthArr.push( 340 );
  773. }else if( columnJson.isSummary ){
  774. colWidthArr.push( 260 );
  775. }else{
  776. colWidthArr.push( 150 );
  777. }
  778. break;
  779. case "number":
  780. case "integer":
  781. case "long":
  782. case "double":
  783. case "numberList":
  784. case "integerList":
  785. case "longList":
  786. case "doubleList":
  787. colWidthArr.push(150);
  788. break;
  789. case "date":
  790. case "dateTime":
  791. case "dateList":
  792. case "dateTimeList":
  793. colWidthArr.push(150);
  794. break;
  795. default:
  796. colWidthArr.push(150);
  797. break;
  798. }
  799. }.bind(this));
  800. return colWidthArr;
  801. },
  802. getDateIndexArray : function(){
  803. var dateIndexArr = []; //日期格式列下标
  804. this.json.data.columnList.each( function (columnJson, i) {
  805. var dataType = this.json.type === "dynamicTable" ? columnJson.dataType_Querytable : columnJson.dataType_CMSProcess;
  806. switch ( dataType ) {
  807. case "date":
  808. case "dateTime":
  809. case "dateList":
  810. case "dateTimeList":
  811. dateIndexArr.push(i);
  812. break;
  813. default:
  814. break;
  815. }
  816. }.bind(this));
  817. return dateIndexArr;
  818. },
  819. //api 使用 开始
  820. confirm: function (type, e, title, text, width, height, ok, cancel, callback, mask, style) {
  821. this.app.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style)
  822. },
  823. alert: function (type, title, text, width, height) {
  824. this.app.alert(type, "center", title, text, width, height);
  825. },
  826. notice: function (content, type, target, where, offset, option) {
  827. this.app.notice(content, type, target, where, offset, option)
  828. }
  829. //api 使用 结束
  830. });
  831. MWF.xApplication.query.Query.Importer.Row = new Class({
  832. initialize: function(importer, importedData, rowIndex){
  833. this.importer = importer;
  834. this.importedData = importedData;
  835. this.clazzType = "row";
  836. this.lp = this.importer.lp;
  837. this.data = {};
  838. this.errorTextList = [];
  839. this.errorTextListExcel = [];
  840. this.calculateFieldDataMap = {};
  841. },
  842. checkValid : function(){
  843. var lp = this.lp;
  844. var columnText = lp.importValidationColumnText;
  845. var columnTextExcel = lp.importValidationColumnTextExcel;
  846. var errorTextList = [];
  847. var errorTextListExcel = [];
  848. this.importer.json.data.columnList.each( function (columnJson, i) {
  849. var colName = this.importer.excelUtils.index2ColName( i );
  850. var colInfor = columnText.replace( "{n}", (i+1)+"("+colName+")" );
  851. var colInforExcel = columnTextExcel.replace( "{n}", colName );
  852. var value = this.importedData[i] || "";
  853. var dataType = this.importer.json.type === "dynamicTable" ? columnJson.dataType_Querytable : columnJson.dataType_CMSProcess;
  854. if( !columnJson.allowEmpty && !value ){
  855. errorTextList.push( colInfor + lp.canNotBeEmpty + lp.fullstop );
  856. errorTextListExcel.push( colInforExcel + lp.canNotBeEmpty + lp.fullstop );
  857. }
  858. if( columnJson.validInOption && columnJson.optionScript && value ){
  859. var options = this.importer.Macro.exec(columnJson.optionScript, this);
  860. if( !options.contains(value) ){
  861. errorTextList.push( colInfor + lp.notInOptions +":"+ options.join(",") + lp.fullstop );
  862. errorTextListExcel.push( colInforExcel + lp.notInOptions +":"+ options.join(",") + lp.fullstop );
  863. }
  864. }
  865. if( columnJson.validFieldType !== false && value ){
  866. switch ( dataType ) {
  867. case "string":
  868. case "stringList":
  869. if( columnJson.isName ){
  870. var arr = this.stringToArray(value);
  871. arr.each( function(d, idx){
  872. var obj = this.importer.getOrgData( d );
  873. if( obj.errorText ){
  874. errorTextList.push( colInfor + obj.errorText + lp.fullstop );
  875. errorTextListExcel.push( colInforExcel + obj.errorText + lp.fullstop );
  876. }
  877. }.bind(this));
  878. }
  879. break;
  880. case "number":
  881. case "integer":
  882. case "long":
  883. case "double":
  884. value = value.replace(/&#10;/g,"");
  885. if (isNaN(value)){
  886. errorTextList.push( colInfor + value + lp.notValidNumber + lp.fullstop );
  887. errorTextListExcel.push( colInforExcel + value + lp.notValidNumber + lp.fullstop );
  888. }
  889. break;
  890. case "numberList":
  891. case "integerList":
  892. case "longList":
  893. case "doubleList":
  894. var arr = this.stringToArray(value);
  895. arr.each( function(d, idx){
  896. if (isNaN(d)){
  897. errorTextList.push( colInfor + d + lp.notValidNumber + lp.fullstop );
  898. errorTextListExcel.push( colInforExcel + d + lp.notValidNumber + lp.fullstop );
  899. }
  900. }.bind(this));
  901. break;
  902. case "date":
  903. case "dateTime":
  904. value = value.replace(/&#10;/g,"");
  905. if( !( new Date(value).isValid() )){
  906. errorTextList.push(colInfor + value + lp.notValidDate + lp.fullstop );
  907. errorTextListExcel.push( colInforExcel + value + lp.notValidDate + lp.fullstop );
  908. }
  909. break;
  910. case "dateList":
  911. case "dateTimeList":
  912. var arr = this.stringToArray(value);
  913. arr.each( function(d, idx){
  914. if( !( new Date(d).isValid() )){
  915. errorTextList.push(colInfor + d + lp.notValidDate + lp.fullstop );
  916. errorTextListExcel.push( colInforExcel + d + lp.notValidDate + lp.fullstop );
  917. }
  918. }.bind(this));
  919. break;
  920. case "boolean":
  921. value = value.replace(/&#10;/g,"");
  922. if( !["true","false"].contains(value.trim().toLowerCase()) ){
  923. errorTextList.push(colInfor + value + lp.notValidBoolean + lp.fullstop );
  924. errorTextListExcel.push( colInforExcel + value + lp.notValidBoolean + lp.fullstop );
  925. }
  926. break;
  927. case "booleanList":
  928. var arr = this.stringToArray(value);
  929. arr.each( function(d, idx){
  930. if( !["true","false"].contains(d.trim().toLowerCase())){
  931. errorTextList.push(colInfor + d + lp.notValidBoolean + lp.fullstop );
  932. errorTextListExcel.push( colInforExcel + d + lp.notValidBoolean + lp.fullstop );
  933. }
  934. }.bind(this));
  935. break;
  936. case "json":
  937. case "stringMap":
  938. value = value.replace(/&#10;/g,"");
  939. try{
  940. var d = JSON.parse(value);
  941. }catch (e) {
  942. errorTextList.push(colInfor + value + lp.notValidJson + lp.fullstop );
  943. errorTextListExcel.push( colInforExcel + value + lp.notValidJson + lp.fullstop );
  944. }
  945. break;
  946. default:
  947. break;
  948. }
  949. }
  950. }.bind(this));
  951. this.errorTextList = this.errorTextList.concat( errorTextList );
  952. this.errorTextListExcel = this.errorTextListExcel.concat( errorTextListExcel );
  953. if(this.errorTextList.length>0){
  954. return false;
  955. }
  956. var p = this.createData();
  957. return Promise.resolve( p ).then(function (flag) {
  958. this.importer.json.data.calculateFieldList.each( function (fieldJson, i) {
  959. if( !fieldJson.path )return;
  960. if( fieldJson.isName ){
  961. var sourceData = this.calculateFieldDataMap[fieldJson.path];
  962. var arr = typeOf( sourceData ) === "array" ? sourceData : [sourceData];
  963. arr = typeOf( arr ) === "array" ? arr : [arr];
  964. arr.each(function (d, idx) {
  965. if( !d )return d;
  966. var a;
  967. switch (typeOf( d )) {
  968. case "string":
  969. a = d; break;
  970. case "object":
  971. a = d.distinguishedName || d.unique || d.employee; break;
  972. }
  973. if( !a )return d;
  974. var obj = this.importer.getOrgData( a );
  975. if( obj.errorText ){
  976. var errorText = (fieldJson.displayName || fieldJson.path) + ":" + obj.errorText + lp.fullstop;
  977. errorTextList.push( errorText );
  978. errorTextListExcel.push( errorText );
  979. }
  980. }.bind(this));
  981. }
  982. }.bind(this));
  983. this.errorTextList = this.errorTextList.concat( errorTextList );
  984. this.errorTextListExcel = this.errorTextListExcel.concat( errorTextListExcel );
  985. if( this.errorTextList.length > 0 )return false;
  986. if( this.importer.json.type === "cms" ){
  987. this.checkCMS( true );
  988. }else if( this.importer.json.type === "process" ){
  989. this.checkProcess( true );
  990. }
  991. if(this.errorTextList.length>0){
  992. return false;
  993. }
  994. return true;
  995. }.bind(this));
  996. },
  997. checkNecessary: function(){
  998. var lp = this.lp;
  999. var columnText = lp.importValidationColumnText;
  1000. var columnTextExcel = lp.importValidationColumnTextExcel;
  1001. var errorTextList = [];
  1002. var errorTextListExcel = [];
  1003. this.importer.json.data.columnList.each( function (columnJson, i) {
  1004. var colName = this.importer.excelUtils.index2ColName( i );
  1005. var colInfor = columnText.replace( "{n}", (i+1)+"("+colName+")" );
  1006. var colInforExcel = columnTextExcel.replace( "{n}", colName );
  1007. var value = this.importedData[i] || "";
  1008. var dataType = this.importer.json.type === "dynamicTable" ? columnJson.dataType_Querytable : columnJson.dataType_CMSProcess;
  1009. if( columnJson.validFieldType !== false && value ){
  1010. switch ( dataType ) {
  1011. case "json":
  1012. case "stringMap":
  1013. value = value.replace(/&#10;/g,"");
  1014. try{
  1015. var d = JSON.parse(value);
  1016. }catch (e) {
  1017. errorTextList.push(colInfor + value + lp.notValidJson + lp.fullstop );
  1018. errorTextListExcel.push( colInforExcel + value + lp.notValidJson + lp.fullstop );
  1019. }
  1020. break;
  1021. default:
  1022. break;
  1023. }
  1024. }
  1025. }.bind(this));
  1026. this.errorTextList = this.errorTextList.concat( errorTextList );
  1027. this.errorTextListExcel = this.errorTextListExcel.concat( errorTextListExcel );
  1028. if(this.errorTextList.length>0){
  1029. return false;
  1030. }
  1031. var p = this.createData();
  1032. return Promise.resolve(p).then(function () {
  1033. if( this.importer.json.type === "cms" ){
  1034. this.checkCMS();
  1035. }else if( this.importer.json.type === "process" ){
  1036. this.checkProcess();
  1037. }
  1038. if(this.errorTextList.length>0){
  1039. return false;
  1040. }
  1041. return true;
  1042. }.bind(this))
  1043. },
  1044. getCol: function(key, isExcel){
  1045. var text, lp = this.lp;
  1046. if( this.pathIndexMap && typeOf(this.pathIndexMap[key]) === "number"){
  1047. var i = this.pathIndexMap[key];
  1048. if( isExcel ){
  1049. text = lp.importValidationColumnTextExcel;
  1050. return text.replace( "{n}", this.importer.excelUtils.index2ColName( i ) );
  1051. }else{
  1052. text = lp.importValidationColumnText;
  1053. return text.replace( "{n}", i+1 );
  1054. }
  1055. }
  1056. return "";
  1057. },
  1058. checkCMS : function( notCheckName ){
  1059. var lp = this.lp;
  1060. var errorTextList = [];
  1061. var errorTextListExcel = [];
  1062. var data = this.document.identity;
  1063. if(!data){
  1064. errorTextList.push( this.getCol("identity", false) + lp.noDrafter + lp.fullstop );
  1065. errorTextListExcel.push( this.getCol("identity", true) + lp.noDrafter + lp.fullstop );
  1066. }else if(data.split("@").getLast().toLowerCase() !== "i"){
  1067. errorTextList.push( this.getCol("identity", false) + '"'+ data +'"'+ lp.drafterIsNotIdentity + lp.fullstop );
  1068. errorTextListExcel.push( this.getCol("identity", true) + '"'+ data +'"'+ lp.drafterIsNotIdentity + lp.fullstop );
  1069. }
  1070. data = this.document.publishTime;
  1071. if(!data){
  1072. errorTextList.push(this.getCol("publishTime", false) + lp.noPublishTime + lp.fullstop );
  1073. errorTextListExcel.push(this.getCol("publishTime", false) + lp.noPublishTime + lp.fullstop );
  1074. }else if( ! new Date(data).isValid() ){
  1075. errorTextList.push(this.getCol("publishTime", false) + '"'+ data +'"'+ lp.publishTimeFormatError + lp.fullstop );
  1076. errorTextListExcel.push(this.getCol("publishTime", false) + '"'+ data +'"'+ lp.publishTimeFormatError + lp.fullstop );
  1077. }
  1078. data = this.document.title;
  1079. if( data && data.length > 70){
  1080. errorTextList.push(this.getCol("title", false) + '"'+ data +'"'+ lp.cmsTitleLengthInfor + lp.fullstop );
  1081. errorTextListExcel.push(this.getCol("title", false) + '"'+ data +'"'+ + lp.cmsTitleLengthInfor + lp.fullstop );
  1082. }
  1083. data = this.document.summary;
  1084. if( data && data.length > 70 ){
  1085. errorTextList.push(this.getCol("summary", false) + '"'+ data +'"'+ lp.cmsSummaryLengthInfor + lp.fullstop );
  1086. errorTextListExcel.push( this.getCol("summary", false) + '"'+ data +'"'+ lp.cmsSummaryLengthInfor + lp.fullstop );
  1087. }
  1088. this.errorTextList = this.errorTextList.concat( errorTextList );
  1089. this.errorTextListExcel = this.errorTextListExcel.concat( errorTextListExcel );
  1090. if(errorTextList.length > 0){
  1091. return false;
  1092. }
  1093. return true;
  1094. },
  1095. checkProcess : function( notCheckName ){
  1096. var lp = this.lp;
  1097. var json = this.importer.json;
  1098. var columnText = lp.importValidationColumnText;
  1099. var columnTextExcel = lp.importValidationColumnTextExcel;
  1100. var errorTextList = [];
  1101. var errorTextListExcel = [];
  1102. var data = this.work.identity;
  1103. if(!data){
  1104. errorTextList.push( this.getCol("identity", false) + lp.noDrafter + lp.fullstop );
  1105. errorTextListExcel.push( this.getCol("identity", true) + lp.noDrafter + lp.fullstop );
  1106. }else if(data.split("@").getLast().toLowerCase() !== "i"){
  1107. errorTextList.push( this.getCol("identity", false) + '"'+ data +'"'+ lp.drafterIsNotIdentity + lp.fullstop );
  1108. errorTextListExcel.push( this.getCol("identity", true) + '"'+ data +'"'+ lp.drafterIsNotIdentity + lp.fullstop );
  1109. }
  1110. if( json.data.processStatus === "completed" ){
  1111. if(!this.work.form){
  1112. errorTextList.push( lp.noForm + lp.fullstop );
  1113. errorTextListExcel.push( lp.noForm + lp.fullstop );
  1114. }
  1115. data = this.work.startTime;
  1116. if(!data){
  1117. errorTextList.push(this.getCol("startTime", false) + lp.noStartTime + lp.fullstop );
  1118. errorTextListExcel.push(this.getCol("startTime", false) + lp.noStartTime + lp.fullstop );
  1119. }else if( ! new Date(data).isValid() ){
  1120. errorTextList.push(this.getCol("startTime", false) + '"'+ data +'"'+ lp.startTimeFormatError + lp.fullstop );
  1121. errorTextListExcel.push(this.getCol("startTime", false) + '"'+ data +'"'+ lp.startTimeFormatError + lp.fullstop );
  1122. }
  1123. data = this.work.completeTime;
  1124. if(!data){
  1125. errorTextList.push(this.getCol("completeTime", false) + lp.noEndTime + lp.fullstop );
  1126. errorTextListExcel.push(this.getCol("completeTime", false) + lp.noEndTime + lp.fullstop );
  1127. }else if( ! new Date(data).isValid() ){
  1128. errorTextList.push(this.getCol("completeTime", false) + '"'+ data +'"'+ lp.endTimeFormatError + lp.fullstop );
  1129. errorTextListExcel.push(this.getCol("completeTime", false) + '"'+ data +'"'+ lp.endTimeFormatError + lp.fullstop );
  1130. }
  1131. }
  1132. this.errorTextList = this.errorTextList.concat( errorTextList );
  1133. this.errorTextListExcel = this.errorTextListExcel.concat( errorTextListExcel );
  1134. if(errorTextList.length > 0){
  1135. return false;
  1136. }
  1137. return true;
  1138. },
  1139. createData : function(){
  1140. var json = this.importer.json;
  1141. if( json.type === "cms" ){
  1142. this.document = {
  1143. categoryId : json.data.category.id,
  1144. readerList : [],
  1145. authorList : [],
  1146. docData : this.data
  1147. };
  1148. }else if( json.type === "process" ){
  1149. this.work = {
  1150. processFlag : json.data.process.id,
  1151. data: this.data
  1152. };
  1153. }
  1154. this.importer.fireEvent("beforeCreateRowData", [this]);
  1155. json.data.columnList.each( function (columnJson, i) {
  1156. if(!columnJson.path)return;
  1157. var value = this.importedData[i] || "";
  1158. if( !value && columnJson.defaultValueScript ){
  1159. value = this.importer.Macro.exec(columnJson.defaultValueScript, this);
  1160. }
  1161. var dataType = (json.type === "dynamicTable" ? columnJson.dataType_Querytable : columnJson.dataType_CMSProcess);
  1162. if( !value && ["number","double","integer","long"].contains(dataType) ){
  1163. value = 0;
  1164. }
  1165. if( !value && (typeOf(value) === "null" || value === "") )return;
  1166. var data = this.parseData(value, dataType, columnJson);
  1167. if( !data && data !== 0 && data !== false )return;
  1168. if( json.type === "dynamicTable" ){
  1169. this.data[ columnJson.path ] = data;
  1170. }else{
  1171. this.setDataWithPath(this.data, columnJson.path, data);
  1172. }
  1173. var array;
  1174. if( json.type === "cms" ){
  1175. if( columnJson.isName ) {
  1176. if (columnJson.isAuthor) {
  1177. array = this.parseCMSReadAndAuthor(data, "作者");
  1178. this.document.authorList = this.document.authorList.concat(array)
  1179. }
  1180. if (columnJson.isReader) {
  1181. array = this.parseCMSReadAndAuthor(data, "阅读");
  1182. this.document.readerList = this.document.readerList.concat(array)
  1183. }
  1184. }
  1185. }
  1186. }.bind(this));
  1187. var calculateOrgData = [], caculateMap = {};
  1188. json.data.calculateFieldList.each( function (fieldJson, i) {
  1189. if( !fieldJson.path )return;
  1190. if( !fieldJson.valueScript )return;
  1191. var data = this.importer.Macro.exec(fieldJson.valueScript, this);
  1192. this.calculateFieldDataMap[fieldJson.path] = data;
  1193. caculateMap[fieldJson.path] = data;
  1194. if( fieldJson.isName && data ){
  1195. switch (o2.typeOf(data)) {
  1196. case "array":
  1197. if(data.length)calculateOrgData = calculateOrgData.concat(data); break;
  1198. default:
  1199. calculateOrgData.push(data); break;
  1200. }
  1201. }
  1202. }.bind(this));
  1203. var p = this.importer.getOrgExtendData( calculateOrgData );
  1204. return Promise.resolve(p).then(function () {
  1205. json.data.calculateFieldList.each( function (fieldJson, i) {
  1206. if( !fieldJson.path )return;
  1207. if( !fieldJson.valueScript )return;
  1208. var data;
  1209. if( fieldJson.isName ){
  1210. var arr = caculateMap[fieldJson.path];
  1211. arr = typeOf( arr ) === "array" ? arr : [arr];
  1212. data = arr.map(function (d, idx) {
  1213. if( !d )return d;
  1214. var a;
  1215. switch (typeOf( d )) {
  1216. case "string":
  1217. a = d; break;
  1218. case "object":
  1219. a = d.distinguishedName || d.unique || d.employee; break;
  1220. }
  1221. if( !a )return d;
  1222. return this.importer.getOrgData( a, true, true );
  1223. }.bind(this));
  1224. data = data.clean();
  1225. }else{
  1226. data = caculateMap[fieldJson.path];
  1227. }
  1228. if( o2.typeOf(data) === "null" )return;
  1229. if( json.type === "dynamicTable" ){
  1230. this.data[ fieldJson.path ] = data;
  1231. }else{
  1232. this.setDataWithPath(this.data, fieldJson.path, data);
  1233. }
  1234. if( json.type === "cms" ){
  1235. if( fieldJson.isAuthor ){
  1236. var array = this.parseCMSReadAndAuthor( data, "作者" );
  1237. this.document.authorList = this.document.authorList.concat( array )
  1238. }
  1239. if( fieldJson.isReader ){
  1240. var array = this.parseCMSReadAndAuthor( data, "阅读" );
  1241. this.document.readerList = this.document.readerList.concat( array )
  1242. }
  1243. }
  1244. }.bind(this));
  1245. var array;
  1246. if( json.type === "cms" ){
  1247. this.document.docData = this.data;
  1248. if( json.data.documentPublisher === "importer" ){
  1249. array = layout.session.user.identityList;
  1250. if( array && array.length ){
  1251. this.document.identity = array[0].distinguishedName;
  1252. }
  1253. }else{
  1254. this.setDataWithField(this.document, "documentPublisherField", "identity", true);
  1255. }
  1256. if( json.data.documentPublishTime === "importer" ){
  1257. this.document.publishTime = new Date().format("db");
  1258. }else{
  1259. this.setDataWithField(this.document, "documentPublisherTimeField", "publishTime", false);
  1260. }
  1261. this.setDataWithField(this.document, "documentTitleField", "title", false);
  1262. if( !this.document.title )this.document.title = "无标题";
  1263. this.setDataWithField(this.document, "documentSummaryField", "summary", false);
  1264. }else if( json.type === "process" ){
  1265. this.work.data = this.data;
  1266. if( json.data.processDrafter === "importer" ){
  1267. array = layout.session.user.identityList;
  1268. if( array && array.length ){
  1269. this.work.identity = array[0].distinguishedName
  1270. }
  1271. }else{
  1272. this.setDataWithField(this.work, "processDrafterField", "identity", true);
  1273. }
  1274. this.setDataWithField(this.work, "processTitleField", "title", false);
  1275. if( !this.work.title )this.work.title = "无标题";
  1276. if( json.data.processStatus === "completed" ){
  1277. this.work.form = json.data.processForm || "";
  1278. this.setDataWithField(this.work, "processSerialField", "serial", false);
  1279. this.setDataWithField(this.work, "processStartTimeField", "startTime", false);
  1280. this.setDataWithField(this.work, "processCompleteTimeField", "completeTime", false);
  1281. }
  1282. }
  1283. this.importer.fireEvent("afterCreateRowData", [ this]);
  1284. }.bind(this));
  1285. },
  1286. parseData: function(value, dataType, json){
  1287. var data;
  1288. var type = this.importer.json.type;
  1289. switch ( dataType ) {
  1290. case "string":
  1291. case "stringList":
  1292. if( json.isName ){
  1293. var arr = this.stringToArray(value);
  1294. if( type === "dynamicTable" ){
  1295. data = arr
  1296. }else{
  1297. data = arr.map( function(d, idx){
  1298. return this.importer.getOrgData( d, true, true ) || d;
  1299. }.bind(this)).clean();
  1300. }
  1301. }else{
  1302. if( dataType === "string" ){
  1303. var linebreak = type === "dynamicTable" ? json.lineBreak_Querytable : json.lineBreak_CMSProcess;
  1304. if( typeOf(value) !== 'string' ){
  1305. data = value.toString ? value.toString() : (value || "");
  1306. }else{
  1307. data = value.replace(/&#10;/g, linebreak || "" );
  1308. }
  1309. }else{
  1310. data = this.stringToArray(value);
  1311. }
  1312. }
  1313. break;
  1314. case "number":
  1315. case "double":
  1316. debugger;
  1317. if( value === 0 ){
  1318. data = 0;
  1319. }else{
  1320. value = value.replace(/&#10;/g,"");
  1321. data = parseFloat(value);
  1322. }
  1323. break;
  1324. case "integer":
  1325. case "long":
  1326. if( value === 0 ){
  1327. data = 0;
  1328. }else {
  1329. value = value.replace(/&#10;/g, "");
  1330. data = parseInt(value);
  1331. }
  1332. break;
  1333. case "numberList":
  1334. case "doubleList":
  1335. data = this.stringToArray(value).map( function(d, idx){ return parseFloat( d ); }.bind(this)).clean();
  1336. break;
  1337. case "integerList":
  1338. case "longList":
  1339. data = this.stringToArray(value).map( function(d, idx){ return parseInt( d ); }.bind(this)).clean();
  1340. break;
  1341. case "date":
  1342. value = value.replace(/&#10;/g,"");
  1343. data = Date.parse(value).format( "%Y-%m-%d" );
  1344. break;
  1345. case "dateTime":
  1346. value = value.replace(/&#10;/g,"");
  1347. data = Date.parse(value).format( "db" );
  1348. break;
  1349. case "dateList":
  1350. data = this.stringToArray(value).map( function(d, idx){ return Date.parse(d).format( "%Y-%m-%d" ); }.bind(this)).clean();
  1351. break;
  1352. case "dateTimeList":
  1353. data = this.stringToArray(value).map( function(d, idx){ return Date.parse(d).format( "db" ); }.bind(this)).clean();
  1354. break;
  1355. case "boolean":
  1356. value = value.replace(/&#10;/g,"");
  1357. data = value.trim().toLowerCase() !== "false";
  1358. break;
  1359. case "booleanList":
  1360. data = this.stringToArray(value).map( function(d, idx){ return value.trim().toLowerCase() !== "false"; }.bind(this)).clean();
  1361. break;
  1362. case "json":
  1363. case "stringMap":
  1364. value = value.replace(/&#10;/g,"");
  1365. data = JSON.parse(value);
  1366. break;
  1367. default:
  1368. data = value.replace(/&#10;/g,"");
  1369. break;
  1370. }
  1371. return data;
  1372. },
  1373. stringToArray: function(string){
  1374. return string.replace(/[\n\r]/g,",").replace(/&#10;/g,",").split(/\s*,\s*/g ).filter(function(s){
  1375. return !!s;
  1376. });
  1377. },
  1378. setDataWithPath: function(obj, path, data){
  1379. var names = path.split(".");
  1380. var d = obj;
  1381. Array.each(names, function (n, idx) {
  1382. if( idx === names.length -1 )return;
  1383. if ( !d[n] ){
  1384. var value = this.isNumberString( names[idx+1] ) ? [] : {};
  1385. var n1 = this.isNumberString( n ) ? n.toInt() : n;
  1386. d[n1] = value;
  1387. d = d[n1];
  1388. }else{
  1389. d = d[n];
  1390. }
  1391. }.bind(this));
  1392. d[names[names.length -1]] = data;
  1393. },
  1394. setDataWithField: function(obj, fieldName, path, isName){
  1395. if(!this.pathIndexMap)this.pathIndexMap = {};
  1396. if( !path )return;
  1397. var json = this.importer.json;
  1398. if( json.data[fieldName] ){
  1399. var f = json.data[fieldName];
  1400. json.data.columnList.each(function(json, i){
  1401. if(json.path === f)this.pathIndexMap[path] = i;
  1402. }.bind(this));
  1403. var d = this.data;
  1404. Array.each( f.split("."), function (n) {
  1405. if(this.isNumberString(n))n = n.toInt();
  1406. if (d) d = d[n];
  1407. }.bind(this));
  1408. if(!d)return;
  1409. var _d = (typeOf(d) === "array" && d.length) ? d[0] : d;
  1410. if( _d ){
  1411. if(isName){
  1412. obj[path] = typeOf(_d) === "object" ? _d.distinguishedName : _d;
  1413. }else{
  1414. obj[path] = d;
  1415. }
  1416. }
  1417. }
  1418. },
  1419. isNumberString: function(string){
  1420. return string.toInt().toString() === string;
  1421. },
  1422. parseCMSReadAndAuthor : function( data, t ){
  1423. var cnArray = ["组织","群组","人员","人员","角色"];
  1424. var keyArray = ["U","G","I","P","R"];
  1425. if( typeOf(data) !== "array" )data = [data];
  1426. return data.map( function( d ){
  1427. var dn = typeOf( d ) === "string" ? d : d.distinguishedName;
  1428. var name;
  1429. if( typeOf(d) === "object" && d.name ){
  1430. name = d.name;
  1431. }else if( MWF.name && MWF.name.cn ){
  1432. name = MWF.name.cn( dn );
  1433. }else{
  1434. name = dn.split("@")[0];
  1435. }
  1436. var index = keyArray.indexOf(dn.substr(dn.length-1, 1));
  1437. if( index > -1 ){
  1438. return {
  1439. "permission" : t,
  1440. "permissionObjectType": cnArray[ index ],
  1441. "permissionObjectName": name,
  1442. "permissionObjectCode": dn
  1443. }
  1444. }
  1445. }).clean()
  1446. },
  1447. getSrcData: function(){
  1448. var srcData = {};
  1449. this.importer.json.data.columnList.each( function (columnJson, i) {
  1450. if(columnJson.path)srcData[ columnJson.path ] = this.importedData[i] || "";
  1451. }.bind(this));
  1452. return srcData;
  1453. },
  1454. getResult: function(){
  1455. if( this.importer.json.type === "cms" ){
  1456. this.document.srcData = this.getSrcData(); //this.importedData;
  1457. return this.document;
  1458. }else if( this.importer.json.type === "process" ){
  1459. this.work.srcData = this.getSrcData(); //this.importedData;
  1460. return this.work;
  1461. }else if( this.importer.json.type === "dynamicTable" ){
  1462. this.data.srcData = this.getSrcData(); //this.importedData;
  1463. return this.data;
  1464. }
  1465. }
  1466. });
  1467. MWF.xDesktop.requireApp("Template", "utils.ExcelUtils", null, false);
  1468. MWF.xApplication.query.Query.Importer.ExcelUtils = new Class({
  1469. Extends: MWF.xApplication.Template.utils.ExcelUtils,
  1470. initialize: function( options ){
  1471. if(options)this.setOptions(options);
  1472. this.sheet2JsonOptions = {header:1};
  1473. this.pollyfill();
  1474. }
  1475. });
  1476. MWF.xApplication.query.Query.Importer.ProgressBar = new Class({
  1477. Implements: [Options, Events],
  1478. Extends: o2.widget.Common,
  1479. options: {
  1480. zindex: null,
  1481. disableDetailButton: false
  1482. },
  1483. initialize : function( importer, options ){
  1484. this.setOptions(options);
  1485. this.importer = importer;
  1486. this.actions = this.importer.lookupAction;
  1487. this.lp = MWF.xApplication.query.Query.LP;
  1488. this.css = importer.css;
  1489. this.openDlg();
  1490. this.status = "ready";
  1491. },
  1492. openDlg: function () {
  1493. var _self = this;
  1494. this.contentNode = new Element("div",{"styles": this.css.processContentNode});
  1495. var opt = {
  1496. "style" : "user",
  1497. "title": this.lp.importRecordDetail,
  1498. "content": this.contentNode,
  1499. "offset": {"y": 0},
  1500. "isMax": false,
  1501. "width": 500,
  1502. "height": 200,
  1503. "zindex": this.options.zindex,
  1504. "buttonList": [
  1505. {
  1506. "type": "openImportRecordDetail",
  1507. "text": this.lp.openImportRecordDetail,
  1508. "action": function () { _self.openImportRecordDetail(); }
  1509. },
  1510. {
  1511. "type": "cancel",
  1512. "text": this.lp.close,
  1513. "action": function () { this.dlg.close(); }.bind(this)
  1514. }
  1515. ],
  1516. "onPostShow": function(){
  1517. this.fireEvent("postShow");
  1518. }.bind(this),
  1519. "onPostLoad": function () {
  1520. this.titleAction.hide();
  1521. this.button.hide();
  1522. },
  1523. "onPostClose": function(){
  1524. this.dlg = null;
  1525. }.bind(this)
  1526. };
  1527. if( this.options.disableDetailButton ){
  1528. opt.buttonList.splice(0, 1);
  1529. }
  1530. this.dlg = o2.DL.open(opt);
  1531. },
  1532. createNode: function( noProgress ){
  1533. // var lp = this.lp;
  1534. // this.maskNode = new Element("div",{"styles": this.css.maskNode}).inject(this.importer.container);
  1535. //
  1536. // this.node = new Element("div", {"styles": this.css.progressBarNode}).inject(this.importer.container);
  1537. //
  1538. // this.topNode = new Element("div",{"styles": this.css.progressTopNode}).inject(this.node);
  1539. //
  1540. // this.subjectNode = new Element("div",{"styles": this.css.progressSubjectNode}).inject(this.topNode);
  1541. //
  1542. // this.topCloseAction = new Element("div.topCloseAction", {
  1543. // "styles": this.css.progressTopCloseAction,
  1544. // "text": "x"
  1545. // }).inject(this.topNode);
  1546. // this.topCloseAction.hide();
  1547. // this.topCloseAction.addEvent("click", function(){
  1548. // this.close();
  1549. // }.bind(this))
  1550. //
  1551. // this.contentNode = new Element("div",{"styles": this.css.processContentNode}).inject(this.node);
  1552. //
  1553. // this.bottomNode = new Element("div", {"styles": this.css.progressBottomNode}).inject(this.node);
  1554. // this.bottomNode.hide();
  1555. //
  1556. // this.closeAction = new Element("div.closeAction", {
  1557. // "styles": this.css.progressCloseAction,
  1558. // "text": lp.close
  1559. // }).inject(this.bottomNode);
  1560. // this.closeAction.addEvent("click", function(){
  1561. // this.close();
  1562. // }.bind(this))
  1563. },
  1564. setContentHtml: function(noProgress){
  1565. var lp = this.lp;
  1566. var contentHTML = "";
  1567. if (noProgress){
  1568. // contentHTML = "<div style=\"height: 20px; line-height: 20px\">"+lp.readyToImportData1+"</div></div>" ;
  1569. contentHTML =
  1570. "<div style=\"overflow: hidden\">" +
  1571. " <div class='mwf_progressInforNode'>"+lp.readyToImportData1+"</div>"+
  1572. "</div>" ;
  1573. this.contentNode.set("html", contentHTML );
  1574. this.progressNode = null;
  1575. this.progressPercentNode = null;
  1576. this.progressInforNode = this.contentNode.getElement(".mwf_progressInforNode");
  1577. this.progressInforNode.setStyles(this.css.progressInforNode)
  1578. }else{
  1579. contentHTML =
  1580. "<div style=\"overflow: hidden\">"+
  1581. " <div class='mwf_progressNode'>" +
  1582. " <div class='mwf_progressPercentNode'></div>"+
  1583. " </div>" +
  1584. " <div class='mwf_progressInforNode'>"+lp.readyToImportData1+"</div>"+
  1585. "</div>" ;
  1586. this.contentNode.set("html", contentHTML );
  1587. this.progressNode = this.contentNode.getElement(".mwf_progressNode");
  1588. this.progressNode.setStyles(this.css.progressNode);
  1589. this.progressPercentNode = this.contentNode.getElement(".mwf_progressPercentNode");
  1590. this.progressPercentNode.setStyles(this.css.progressPercentNode);
  1591. this.progressInforNode = this.contentNode.getElement(".mwf_progressInforNode");
  1592. this.progressInforNode.setStyles(this.css.progressInforNode)
  1593. }
  1594. },
  1595. showCheckData : function(){
  1596. // this.node.show();
  1597. this.setContentHtml(true);
  1598. this.setMessageTitle( this.lp.checkDataTitle );
  1599. this.setMessageText( this.lp.checkDataContent );
  1600. this.status = "check";
  1601. // this.setSize();
  1602. },
  1603. showImporting: function( recordId, callback, date ){
  1604. // this.node.show();
  1605. this.setContentHtml();
  1606. this.recordId = recordId;
  1607. this.currentDate = date || new Date();
  1608. this.intervalId = window.setInterval( function(){
  1609. this.actions.getImportModelRecordStatus( this.recordId, function( json ){
  1610. var data = json.data;
  1611. this.status = data.status;
  1612. if( data.status === "待导入" ) { //有其他人正在导入或上次导入还未完成
  1613. this.setMessageTitle(this.lp.importWaitingTitle);
  1614. this.setMessageText(this.lp.importWaitingContent);
  1615. }else if( data.status === "导入中" ){ //导入中
  1616. this.setMessageTitle( this.lp.importDataTitle );
  1617. this.setMessageText( this.lp.importDataContent.replace( "{count}", data.executeCount));
  1618. this.updateProgress( data );
  1619. }else{ //已经结束, 状态有 "导入成功","部分成功","导入失败"
  1620. if( callback )callback( data );
  1621. if( data.promise && typeOf(data.promise.then) === "function" ){
  1622. Promise.resolve( data.promise ).then(function () {
  1623. if(this.intervalId)window.clearInterval( this.intervalId );
  1624. this.transferComplete( data );
  1625. }.bind(this))
  1626. }else{
  1627. if(this.intervalId)window.clearInterval( this.intervalId );
  1628. this.transferComplete( data );
  1629. }
  1630. }
  1631. }.bind(this), null)
  1632. }.bind(this), 500 );
  1633. // this.setSize();
  1634. },
  1635. showCloseAction: function(){
  1636. this.dlg.titleAction.show();
  1637. this.dlg.button.show();
  1638. // if( this.bottomNode )this.bottomNode.show();
  1639. // if( this.topCloseAction )this.topCloseAction.show();
  1640. // this.setSize();
  1641. },
  1642. close: function(){
  1643. // this.maskNode.destroy();
  1644. // this.node.destroy();
  1645. this.dlg.close();
  1646. },
  1647. // setSize: function(){
  1648. // var containerSize = this.importer.container.getSize();
  1649. // var nodeSize = this.node.getSize();
  1650. // var top = (containerSize.y - nodeSize.y) / 2;
  1651. // var left = (containerSize.x - nodeSize.x) / 2;
  1652. // this.node.setStyles({
  1653. // "top": (top-40)+"px",
  1654. // "left": left+"px"
  1655. // })
  1656. // },
  1657. updateProgress: function(data){
  1658. //status, data.executeCount, data.count, data.failCount
  1659. var lp = this.lp;
  1660. var total = data.count.toInt();
  1661. var processed = data.executeCount.toInt();
  1662. var failCount = data.failCount.toInt();
  1663. var percent = 100*(processed/total);
  1664. var sendDate = new Date();
  1665. var lastDate = this.lastTime || this.currentDate;
  1666. var ms = sendDate.getTime() - lastDate.getTime();
  1667. var speed = ( (processed - ( this.lastProcessed || 0 )) * 1000)/ms ;
  1668. var u = lp.importSpeed;
  1669. speed = speed.round(2);
  1670. this.progressPercentNode.setStyle("width", ""+percent+"%");
  1671. var text = lp.importingDataContent.replace("{speed}",speed).replace("{total}",total).replace("{remaining}",( total - processed ));
  1672. text += failCount ? lp.importingDataErrorContent.replace("{errorCount}",failCount) : "";
  1673. this.progressInforNode.set("text", text);
  1674. this.lastProcessed = processed;
  1675. this.lastTime = new Date();
  1676. },
  1677. transferComplete: function( data ){
  1678. var lp = this.lp;
  1679. var sendDate = new Date();
  1680. var ms = sendDate.getTime()-this.currentDate.getTime();
  1681. if(ms<1000)ms = 1000;
  1682. var timeStr = "";
  1683. if (ms>3600000){
  1684. var h = ms/3600000;
  1685. var m_s = ms % 3600000;
  1686. var m = m_s / 60000;
  1687. var s_s = m_s % 60000;
  1688. var s = s_s/1000;
  1689. timeStr = ""+h.toInt()+lp.hour+m.toInt()+lp.mintue+s.toInt()+lp.second;
  1690. }else if (ms>60000){
  1691. var m = ms / 60000;
  1692. var s_s = ms % 60000;
  1693. var s = s_s/1000;
  1694. timeStr = ""+m.toInt()+lp.mintue+s.toInt()+lp.second;
  1695. }else{
  1696. var s = ms/1000;
  1697. timeStr = ""+s.toInt()+lp.second;
  1698. }
  1699. if( data.status === "导入成功" ){
  1700. var size = data.count;
  1701. var speed = (size * 1000)/ms ;
  1702. var u = lp.importSpeed;
  1703. speed = speed.round(2);
  1704. this.setMessageTitle( lp.importSuccessTitle );
  1705. var text = lp.importSuccessContent.replace("{total}",size).replace("{speed}",speed).replace("{timeStr}",timeStr);
  1706. this.setMessageText( text );
  1707. }else if(data.status === "部分成功"){
  1708. var size = data.count;
  1709. var speed = (size * 1000)/ms ;
  1710. var u = lp.importSpeed;
  1711. speed = speed.round(2);
  1712. this.setMessageTitle( lp.importPartSuccessTitle );
  1713. var text = lp.importPartSuccessContent.replace("{total}",size).replace("{speed}",speed).replace("{errorCount}",data.failCount).replace("{timeStr}",timeStr);
  1714. this.setMessageText( text );
  1715. }else{ //导入失败
  1716. var size = data.count;
  1717. this.setMessageTitle( lp.importFailTitle );
  1718. var text = lp.importFailContent.replace("{errorInfo}",data.distribution || "").replace("{total}",size).replace("{timeStr}",timeStr);
  1719. this.setMessageText( text );
  1720. }
  1721. this.clearMessageProgress();
  1722. this.showCloseAction();
  1723. },
  1724. setMessageText: function( text){
  1725. this.progressInforNode.set("text", text);
  1726. },
  1727. setMessageTitle: function( text){
  1728. this.dlg.titleText.set("text", text);
  1729. },
  1730. clearMessageProgress: function(){
  1731. this.progressNode.destroy();
  1732. },
  1733. openImportRecordDetail: function () {
  1734. MWF.xDesktop.requireApp("query.Query", "ImporterRecord", function () {
  1735. var detail = new MWF.xApplication.query.Query.ImporterRecord.Detail(
  1736. this.importer.container,
  1737. this.importer.app,
  1738. { importerId: this.importerId, recordId: this.recordId }
  1739. );
  1740. detail.load();
  1741. this.dlg.close();
  1742. }.bind(this), false);
  1743. }
  1744. });