4530f9ddef2d452f8577241703ef11c907c0ee19.svn-base 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  1. BemsWebApplication.ReportJob = function (params, viewInfo) {
  2. var visiblePopup = ko.observable(false);
  3. var change = false;
  4. var newReport;
  5. var seq = 0;
  6. var beforeReportFormatId;
  7. var beforeFormatName;
  8. var beforeSeq;
  9. var beforeDateTime;
  10. var editor;
  11. var rowClick = false;
  12. var contentsUnit = 10000;
  13. var filePath = "/App_Data/files/report2/";
  14. var popupInit = false;
  15. var SiteId = BWA.UserInfo.SiteId();
  16. //권한설정
  17. var hasnotModificationPermission = ko.observable(true);
  18. var endpointSelector = "";
  19. if (BemsWebApplication.config.mode == "production") {
  20. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
  21. } else {
  22. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
  23. }
  24. var tempcontent = "";
  25. function getFormatData() {
  26. var dataSource = new DevExpress.data.DataSource({
  27. store: {
  28. type: "odata",
  29. url: endpointSelector + "/BemsReportFormat",
  30. },
  31. requireTotalCount: true,
  32. pageSize: 1000
  33. });
  34. dataSource.filter([
  35. ["parts", "=", 0]
  36. ]);
  37. dataSource.sort({ getter: "FormatName", asc: true });
  38. dataSource.load()
  39. .done(function (result) {
  40. $("#formatSelect").dxSelectBox("instance").option('dataSource', result);
  41. $("#formatSelect").dxSelectBox("instance").option('displayExpr', 'FormatName');
  42. $("#formatSelect").dxSelectBox("instance").option('valueExpr', "ReportFormatId");
  43. })
  44. .fail(function (error) {
  45. utils.toast.show(error);
  46. });
  47. }
  48. function getFormatContent() {
  49. rowClick = false;
  50. var dataSource = new DevExpress.data.DataSource({
  51. store: {
  52. type: "odata",
  53. url: endpointSelector + "/BemsReportFormat",
  54. },
  55. requireTotalCount: true,
  56. pageSize: 1000
  57. });
  58. dataSource.filter([
  59. ["ReportFormatId", "=", $("#formatSelect").dxSelectBox("instance").option('value')]
  60. ]);
  61. dataSource.load()
  62. .done(function (result) {
  63. var content = "";
  64. for (var i = 0; i < result.length; i++) {
  65. content = content + result[i].Content;
  66. }
  67. editor.doCmd('NewDocument', '1');
  68. if (result.length > 0) {
  69. editor.insertContents(content);
  70. } else {
  71. editor.insertContents("");
  72. }
  73. })
  74. .fail(function (error) {
  75. utils.toast.show(error);
  76. });
  77. }
  78. function saveReport() {
  79. $("#saveBtn").dxButton("instance").option('disabled', true);
  80. $("#delBtn").dxButton("instance").option('disabled', true);
  81. $("#confirmBtn").dxButton("instance").option('disabled', true);
  82. var dataSource = new DevExpress.data.DataSource({
  83. store: {
  84. type: "odata",
  85. url: endpointSelector + "/BemsReportHistory",
  86. },
  87. requireTotalCount: true,
  88. pageSize: 1000
  89. });
  90. dataSource.filter([
  91. ["SiteId", "=", BWA.UserInfo.SiteId()],
  92. "and",
  93. ["parts", "=", 0]
  94. ]);
  95. dataSource.sort({ getter: "Seq", desc: true });
  96. dataSource.load()
  97. .done(function (result) {
  98. if (result.length > 0) {
  99. seq = result[0].Seq;
  100. } else {
  101. seq = 0;
  102. }
  103. var store = new DevExpress.data.ODataStore({
  104. url: endpointSelector + "/BemsReportHistory",
  105. key: ["DateTime", "Seq", "ReportFormatId", "parts"],
  106. keyType: {
  107. DateTime: "DateTime",
  108. Seq: "Int32",
  109. ReportFormatId: "Int32",
  110. parts: "Int32"
  111. }
  112. });
  113. if ($("#formatSelect").dxSelectBox("instance").option('value') == null) {
  114. utils.toast.show('일지 양식을 선택 해 주세요.', 'error');
  115. $("#saveBtn").dxButton("instance").option('disabled', false);
  116. $("#delBtn").dxButton("instance").option('disabled', false);
  117. $("#confirmBtn").dxButton("instance").option('disabled', false);
  118. return;
  119. }
  120. if ($("#reportName").dxTextBox("instance").option('value') == "") {
  121. utils.toast.show('일지 이름을 입력 해 주세요.', 'error');
  122. $("#saveBtn").dxButton("instance").option('disabled', false);
  123. $("#delBtn").dxButton("instance").option('disabled', false);
  124. $("#confirmBtn").dxButton("instance").option('disabled', false);
  125. return;
  126. }
  127. var contentData = editor.outputBodyHTML();
  128. if (contentData.substring(7, 14) == "<p></p>") {
  129. var temp1 = contentData.substring(0, 6);
  130. var temp2 = contentData.substring(18, contentData.length);
  131. contentData = temp1 + temp2;
  132. }
  133. var partCnt = 1;
  134. if (contentData.length > contentsUnit) {
  135. partCnt = parseInt(contentData.length / contentsUnit) + 1;
  136. }
  137. var contentsArray = new Array(partCnt);
  138. var contentLength = contentData.length;
  139. for (var i = 0; i < partCnt; i++) {
  140. if (contentLength <= contentsUnit) {
  141. contentsArray[i] = contentData;
  142. } else {
  143. if (contentLength <= contentsUnit) {
  144. contentsArray[i] = contentData.substr(i * contentsUnit, contentLength - i * contentsUnit);
  145. } else {
  146. contentsArray[i] = contentData.substr(i * contentsUnit, contentsUnit);
  147. }
  148. }
  149. var tmpDate = new Date();
  150. var fileValue = $("#FILE_TAG").val().split("\\");
  151. var fileName = fileValue[fileValue.length - 1]; // 파일명
  152. var tmpDateFormat = new Date(tmpDate.getFullYear(), tmpDate.getMonth(), tmpDate.getDate(), tmpDate.getHours(), tmpDate.getMinutes(), tmpDate.getSeconds(), 0);
  153. var insertData = { SiteId: BWA.UserInfo.SiteId(), Seq: seq + 1, DateTime: tmpDateFormat, ReportName: $("#reportName").dxTextBox("instance").option('value'), ReportFormatId: $("#formatSelect").dxSelectBox("instance").option('value'), FormatName: $("#formatSelect").dxSelectBox("instance").option('text'), Content: contentsArray[i], Writer: BWA.UserInfo.Name(), Confirm1: '', Confirm2: '', parts: i, FileName: fileName };
  154. store.insert(insertData)
  155. .done(function (values, key) {
  156. utils.toast.show("일지를 작성하였습니다.");
  157. })
  158. .fail(function (error) {
  159. utils.toast.show("일지 작성이 실패하였습니다.", "error");
  160. });
  161. }
  162. uploadFile();
  163. if ((window.navigator.appName == 'Netscape' && window.navigator.userAgent.search('Trident') != -1) || (window.navigator.userAgent.indexOf("msie") != -1)) {
  164. $("#FILE_TAG").replaceWith($("#FILE_TAG").clone(true));
  165. $("#FILE_TAG").val("");
  166. } else {
  167. $("#FILE_TAG").val("");
  168. }
  169. setTimeout(function () {
  170. $("#saveBtn").dxButton("instance").option('disabled', false);
  171. $("#delBtn").dxButton("instance").option('disabled', false);
  172. $("#confirmBtn").dxButton("instance").option('disabled', false);
  173. visiblePopup(false);
  174. change = true;
  175. loadGridReportDate();
  176. }, 100);
  177. })
  178. .fail(function (error) {
  179. $("#saveBtn").dxButton("instance").option('disabled', false);
  180. $("#delBtn").dxButton("instance").option('disabled', false);
  181. $("#confirmBtn").dxButton("instance").option('disabled', false);
  182. utils.toast.show(error);
  183. });
  184. }
  185. function modifyReport() {
  186. var partsCnt = 0;
  187. var id;
  188. var formatName = '';
  189. var name = $("#reportName").dxTextBox("instance").option('value');
  190. var Writer = '';
  191. var confirm1 = '';
  192. var confirm2 = '';
  193. var removecnt = 0;
  194. var tmpDateFormat = new Date(beforeDateTime.getFullYear(), beforeDateTime.getMonth(), beforeDateTime.getDate(), beforeDateTime.getHours(), beforeDateTime.getMinutes(), beforeDateTime.getSeconds(), 0);
  195. var dataSource = new DevExpress.data.DataSource({
  196. store: {
  197. type: "odata",
  198. url: endpointSelector + "/BemsReportHistory",
  199. },
  200. requireTotalCount: true,
  201. pageSize: 100
  202. });
  203. dataSource.filter([
  204. ["SiteId", "=", BWA.UserInfo.SiteId()],
  205. "and",
  206. ["Seq", "=", beforeSeq],
  207. "and",
  208. ["DateTime", "=", beforeDateTime]
  209. ]);
  210. dataSource.load()
  211. .done(function (result) {
  212. partsCnt = result.length;
  213. Writer = result[0].Writer;
  214. confirm1 = result[0].Confirm1;
  215. confirm2 = result[0].Confirm2;
  216. id = result[0].ReportFormatId;
  217. formatName = result[0].FormatName;
  218. var store = new DevExpress.data.ODataStore({
  219. url: endpointSelector + "/BemsReportHistory",
  220. key: ["DateTime", "Seq", "ReportFormatId", "parts"],
  221. keyType: {
  222. DateTime: "DateTime",
  223. Seq: "Int32",
  224. ReportFormatId: "Int32",
  225. parts: "Int32"
  226. }
  227. });
  228. for (var i = 0; i < partsCnt; i++) {
  229. var removeData = { Seq: beforeSeq, DateTime: tmpDateFormat, ReportFormatId: id, parts: i };
  230. store.remove(removeData)
  231. .done(function (values, key) {
  232. removecnt++;
  233. if (removecnt == partsCnt) {
  234. var store = new DevExpress.data.ODataStore({
  235. url: endpointSelector + "/BemsReportHistory",
  236. key: ["DateTime", "Seq", "ReportFormatId", "parts"],
  237. keyType: {
  238. DateTime: "DateTime",
  239. Seq: "Int32",
  240. ReportFormatId: "Int32",
  241. parts: "Int32"
  242. }
  243. });
  244. var contentData = editor.outputBodyHTML();
  245. if (contentData.substring(7, 14) == "<p></p>") {
  246. var temp1 = contentData.substring(0, 6);
  247. var temp2 = contentData.substring(18, contentData.length);
  248. contentData = temp1 + temp2;
  249. }
  250. var partCnt = 1;
  251. if (contentData.length > contentsUnit) {
  252. partCnt = parseInt(contentData.length / contentsUnit) + 1;
  253. }
  254. var contentsArray = new Array(partCnt);
  255. var contentLength = contentData.length;
  256. var addcnt = 0;
  257. for (var i = 0; i < partCnt; i++) {
  258. if (contentLength <= contentsUnit) {
  259. contentsArray[i] = contentData;
  260. } else {
  261. if (contentLength <= contentsUnit) {
  262. contentsArray[i] = contentData.substr(i * contentsUnit, contentLength - i * contentsUnit);
  263. } else {
  264. contentsArray[i] = contentData.substr(i * contentsUnit, contentsUnit);
  265. }
  266. }
  267. var fileValue = $("#FILE_TAG").val().split("\\");
  268. var fileName = fileValue[fileValue.length - 1]; // 파일명
  269. if (fileName == "") {
  270. fileName = $("#FILE_DOWN").text();
  271. }
  272. var insertData = { SiteId: BWA.UserInfo.SiteId(), Seq: beforeSeq, DateTime: tmpDateFormat, ReportName: name, ReportFormatId: id, FormatName: formatName, Content: contentsArray[i], Writer: Writer, Confirm1: confirm1, Confirm2: confirm2, parts: i, FileName: fileName };
  273. store.insert(insertData)
  274. .done(function (values, key) {
  275. addcnt++;
  276. if (addcnt == partCnt) {
  277. utils.toast.show("일지를 수정하였습니다.");
  278. $("#saveBtn").dxButton("instance").option('disabled', false);
  279. $("#delBtn").dxButton("instance").option('disabled', false);
  280. $("#confirmBtn").dxButton("instance").option('disabled', false);
  281. visiblePopup(false);
  282. change = true;
  283. loadGridReportDate();
  284. }
  285. })
  286. .fail(function (error) {
  287. utils.toast.show("일지 수정이 실패하였습니다.", "error");
  288. $("#saveBtn").dxButton("instance").option('disabled', false);
  289. $("#delBtn").dxButton("instance").option('disabled', false);
  290. $("#confirmBtn").dxButton("instance").option('disabled', false);
  291. visiblePopup(false);
  292. });
  293. }
  294. uploadFile();
  295. if ((window.navigator.appName == 'Netscape' && window.navigator.userAgent.search('Trident') != -1) || (window.navigator.userAgent.indexOf("msie") != -1)) {
  296. $("#FILE_TAG").replaceWith($("#FILE_TAG").clone(true));
  297. $("#FILE_TAG").val("");
  298. } else {
  299. $("#FILE_TAG").val("");
  300. }
  301. }
  302. })
  303. .fail(function (error) {
  304. utils.toast.show("일지 수정이 실패하였습니다.", "error");
  305. });
  306. }
  307. }).fail(function (error) {
  308. utils.toast.show(error);
  309. });
  310. $("#saveBtn").dxButton("instance").option('disabled', true);
  311. $("#delBtn").dxButton("instance").option('disabled', true);
  312. $("#confirmBtn").dxButton("instance").option('disabled', true);
  313. }
  314. function loadGridReportDate() {
  315. var dataSource = new DevExpress.data.DataSource({
  316. store: {
  317. type: "odata",
  318. url: endpointSelector + "/BemsReportHistory",
  319. },
  320. requireTotalCount: true,
  321. pageSize: 1000
  322. });
  323. dataSource.filter([
  324. ["SiteId", "=", BWA.UserInfo.SiteId()]
  325. , "and",
  326. ["parts", "=", 0]
  327. ]);
  328. dataSource.sort({ getter: "Seq", desc: true });
  329. console.log('ds', dataSource);
  330. dataSource.load()
  331. .done(function (result) {
  332. if (result.length > 0) {
  333. seq = result[0].Seq;
  334. } else {
  335. seq = 0;
  336. }
  337. if (change) {
  338. //$("#gridContainer").dxDataGrid("instance").option('dataSource', result);
  339. //$("#gridContainer").dxDataGrid({
  340. // scrolling: {
  341. // showScrollbar: "never"
  342. // },
  343. // paging: {
  344. // pageSize: 20,
  345. // enabled: true
  346. // },
  347. //});
  348. $("#gridContainer").dxDataGrid("instance").refresh();
  349. change = false;
  350. }
  351. })
  352. .fail(function (error) {
  353. utils.toast.show(error);
  354. });
  355. }
  356. function deleteReport() {
  357. var partsCnt = 0;
  358. if (seq == 0) {
  359. utils.toast.show('삭제할 일지가 없습니다.', "error");
  360. } else {
  361. var dataSource = new DevExpress.data.DataSource({
  362. store: {
  363. type: "odata",
  364. url: endpointSelector + "/BemsReportHistory",
  365. },
  366. requireTotalCount: true,
  367. pageSize: 100
  368. });
  369. dataSource.filter([
  370. ["SiteId", "=", BWA.UserInfo.SiteId()],
  371. "and",
  372. ["Seq", "=", beforeSeq]
  373. , "and",
  374. ["DateTime", "=", beforeDateTime],
  375. ]);
  376. dataSource.load()
  377. .done(function (result) {
  378. var id = result[0].ReportFormatId;
  379. partsCnt = result.length;
  380. var store = new DevExpress.data.ODataStore({
  381. url: endpointSelector + "/BemsReportHistory",
  382. key: ["DateTime", "Seq", "ReportFormatId", "parts"],
  383. keyType: {
  384. DateTime: "DateTime",
  385. Seq: "Int32",
  386. ReportFormatId: "Int32",
  387. parts: "Int32"
  388. }
  389. });
  390. var tmpDateFormat = new Date(beforeDateTime.getFullYear(), beforeDateTime.getMonth(), beforeDateTime.getDate(), beforeDateTime.getHours(), beforeDateTime.getMinutes(), beforeDateTime.getSeconds(), 0);
  391. for (var i = 0; i < partsCnt; i++) {
  392. var removeData = { SiteId: BWA.UserInfo.SiteId(), Seq: beforeSeq, DateTime: tmpDateFormat, ReportFormatId: id, parts: i };
  393. store.remove(removeData)
  394. .done(function (values, key) {
  395. utils.toast.show("일지를 삭제하였습니다.");
  396. })
  397. .fail(function (error) {
  398. utils.toast.show("일지 삭제를 실패하였습니다.", "error");
  399. });
  400. }
  401. })
  402. .fail(function (error) {
  403. utils.toast.show(error);
  404. });
  405. $("#saveBtn").dxButton("instance").option('disabled', true);
  406. $("#delBtn").dxButton("instance").option('disabled', true);
  407. $("#confirmBtn").dxButton("instance").option('disabled', true);
  408. setTimeout(function () {
  409. $("#saveBtn").dxButton("instance").option('disabled', false);
  410. $("#delBtn").dxButton("instance").option('disabled', false);
  411. $("#confirmBtn").dxButton("instance").option('disabled', false);
  412. visiblePopup(false);
  413. change = true;
  414. loadGridReportDate();
  415. }, 100);
  416. }
  417. }
  418. function confirmReport() {
  419. var confirm1;
  420. var partsCnt = 0;
  421. if (seq == 0) {
  422. utils.toast.show('결재할 일지가 없습니다.', 'error');
  423. } else {
  424. var confimcnt = 0;
  425. var confimcnt1 = 0;
  426. var id = $("#formatSelect").dxSelectBox("instance").option('value');
  427. var dataSource = new DevExpress.data.DataSource({
  428. store: {
  429. type: "odata",
  430. url: endpointSelector + "/BemsReportHistory",
  431. },
  432. requireTotalCount: true,
  433. pageSize: 100
  434. });
  435. dataSource.filter([
  436. ["SiteId", "=", BWA.UserInfo.SiteId()],
  437. "and",
  438. ["Seq", "=", beforeSeq],
  439. "and",
  440. ["DateTime", "=", beforeDateTime]
  441. ]);
  442. dataSource.load()
  443. .done(function (result) {
  444. partsCnt = result.length;
  445. var store = new DevExpress.data.ODataStore({
  446. url: endpointSelector + "/BemsReportHistory",
  447. key: ["DateTime", "Seq", "ReportFormatId", "parts"],
  448. keyType: {
  449. DateTime: "DateTime",
  450. Seq: "Int32",
  451. ReportFormatId: "Int32",
  452. parts: "Int32"
  453. }
  454. });
  455. for (var i = 0; i < partsCnt; i++) {
  456. if (BWA.UserInfo.UserGroupName().indexOf('팀장') > -1) {
  457. store.update({
  458. DateTime: new Date(beforeDateTime.getFullYear(), beforeDateTime.getMonth(), beforeDateTime.getDate(), beforeDateTime.getHours(), beforeDateTime.getMinutes(), beforeDateTime.getSeconds(), 0),
  459. Seq: beforeSeq,
  460. ReportFormatId: beforeReportFormatId,
  461. parts: i
  462. }, { Confirm1: BWA.UserInfo.Name() })
  463. .done(function (values, key) {
  464. confimcnt++;
  465. if (confimcnt == partsCnt) {
  466. utils.toast.show("결재가 진행되었습니다.");
  467. confimcnt = 0;
  468. }
  469. })
  470. .fail(function (error) {
  471. utils.toast.show("결재가 실패하였습니다.", "error");
  472. });
  473. } else if (BWA.UserInfo.UserGroupName().indexOf('소장') > -1) {
  474. var dataSource = new DevExpress.data.DataSource({
  475. store: {
  476. type: "odata",
  477. url: endpointSelector + "/BemsReportHistory",
  478. },
  479. requireTotalCount: true,
  480. pageSize: 1
  481. });
  482. dataSource.filter([
  483. ["SiteId", "=", BWA.UserInfo.SiteId()],
  484. "and",
  485. ["Seq", "=", beforeSeq],
  486. "and",
  487. ["DateTime", "=", beforeDateTime]
  488. ]);
  489. dataSource.load()
  490. .done(function (result) {
  491. if (result[0].Confirm1 == "") {
  492. confirm1 = false;
  493. } else {
  494. confirm1 = true;
  495. }
  496. if (confirm1) {
  497. for (var i = 0; i < partsCnt; i++) {
  498. store.update({
  499. DateTime: new Date(beforeDateTime.getFullYear(), beforeDateTime.getMonth(), beforeDateTime.getDate(), beforeDateTime.getHours(), beforeDateTime.getMinutes(), beforeDateTime.getSeconds(), 0),
  500. Seq: beforeSeq,
  501. ReportFormatId: beforeReportFormatId,
  502. parts: i
  503. }, { Confirm2: BWA.UserInfo.Name() })
  504. .done(function (values, key) {
  505. confimcnt1++;
  506. if (confimcnt1 == partsCnt) {
  507. utils.toast.show("결재가 진행되었습니다.");
  508. confimcnt1 = 0;
  509. }
  510. })
  511. .fail(function (error) {
  512. utils.toast.show("결재가 실패하였습니다.", "error");
  513. });
  514. }
  515. } else {
  516. utils.toast.show("팀장 결재가 진행되지 않습니다.", "error");
  517. }
  518. })
  519. .fail(function (error) {
  520. utils.toast.show(error);
  521. });
  522. } else {
  523. utils.toast.show("결재자 정보가 명확하지 않습니다.", "error");
  524. }
  525. }
  526. })
  527. .fail(function (error) {
  528. utils.toast.show(error);
  529. });
  530. $("#saveBtn").dxButton("instance").option('disabled', true);
  531. $("#delBtn").dxButton("instance").option('disabled', true);
  532. $("#confirmBtn").dxButton("instance").option('disabled', true);
  533. setTimeout(function () {
  534. $("#saveBtn").dxButton("instance").option('disabled', false);
  535. $("#delBtn").dxButton("instance").option('disabled', false);
  536. $("#confirmBtn").dxButton("instance").option('disabled', false);
  537. visiblePopup(false);
  538. change = true;
  539. loadGridReportDate();
  540. }, 100);
  541. }
  542. }
  543. function HideConfirm() {
  544. var dataSource = new DevExpress.data.DataSource({
  545. store: {
  546. type: "odata",
  547. url: endpointSelector + "/BemsReportHistory",
  548. },
  549. requireTotalCount: true,
  550. pageSize: 1
  551. });
  552. dataSource.filter([
  553. ["SiteId", "=", BWA.UserInfo.SiteId()],
  554. "and",
  555. ["Seq", "=", beforeSeq],
  556. "and",
  557. ["DateTime", "=", beforeDateTime]
  558. ]);
  559. dataSource.load()
  560. .done(function (result) {
  561. if (BWA.UserInfo.UserGroupName().indexOf('팀장') > -1) {
  562. if (result[0].Confirm1 == "") {
  563. $("#confirmBtn").dxButton("instance").option("visible", true);
  564. } else {
  565. $("#confirmBtn").dxButton("instance").option("visible", false);
  566. }
  567. }
  568. if (BWA.UserInfo.UserGroupName().indexOf('소장') > -1) {
  569. if (result[0].Confirm2 == "") {
  570. $("#confirmBtn").dxButton("instance").option("visible", true);
  571. } else {
  572. $("#confirmBtn").dxButton("instance").option("visible", false);
  573. }
  574. }
  575. })
  576. .fail(function (error) {
  577. utils.toast.show(error);
  578. });
  579. }
  580. function uploadFile() {
  581. if ($("#FILE_TAG")[0].files[0] != null) {
  582. var form = $('#FILE_FORM')[0];
  583. var formData = new FormData(form);
  584. formData.append("fileObj", $("#FILE_TAG")[0].files[0]);
  585. var urlHeader = BemsWebApplication.config.endpoints.api[BemsWebApplication.config.mode];
  586. var url = urlHeader + '/DailyReport/FileUpload?&SiteId=' + SiteId;
  587. $.ajax({
  588. url: url,
  589. processData: false,
  590. contentType: false,
  591. data: formData,
  592. type: 'POST',
  593. success: function (result) {
  594. },
  595. error: function (error) {
  596. }
  597. });
  598. }
  599. }
  600. var searchViewOptions = {
  601. };
  602. var dataSourceOptions = {
  603. select: [
  604. 'SiteId',
  605. 'Seq',
  606. 'DateTime',
  607. 'ReportName',
  608. 'ReportFormatId',
  609. 'FormatName',
  610. 'Content',
  611. 'Writer',
  612. 'Confirm1',
  613. 'Confirm2',
  614. 'parts',
  615. 'FileName'
  616. ],
  617. filter: [[
  618. ["SiteId", "=", BWA.UserInfo.SiteId()],
  619. "and",
  620. ["parts", "=", 0]
  621. ]]
  622. };
  623. var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'BemsReportHistory',
  624. {
  625. dataSourceOptions: dataSourceOptions,
  626. isUseSiteId: false,
  627. columns: [
  628. {
  629. dataField: 'Index',
  630. width: 100,
  631. caption: "번호",
  632. alignment: 'center'
  633. },
  634. {
  635. dataField: 'FormatName',
  636. width: 260,
  637. caption: "양식",
  638. alignment: 'center',
  639. cellTemplate: function (element, info) {
  640. element.append("<div>" + info.text + "</div>")
  641. .css("text-align", "left")
  642. }
  643. },
  644. {
  645. dataField: 'DateTime',
  646. width: 150,
  647. caption: "등록일",
  648. alignment: 'center'
  649. },
  650. {
  651. dataField: 'ReportName',
  652. width: 390,
  653. caption: "제목",
  654. alignment: 'center',
  655. cellTemplate: function (element, info) {
  656. element.append("<div>" + info.text + "</div>")
  657. .css("text-align", "left")
  658. }
  659. },
  660. {
  661. dataField: 'FileName',
  662. width: 100,
  663. caption: "첨부파일",
  664. alignment: 'center',
  665. cellTemplate: function (element, info) {
  666. if (info.text != null && info.text != "")
  667. element.append("<div> O </div>")
  668. else {
  669. element.append("<div> </div>")
  670. }
  671. }
  672. },
  673. {
  674. dataField: 'Writer',
  675. width: 120,
  676. caption: "등록자",
  677. alignment: 'center'
  678. },
  679. {
  680. dataField: 'Confirm1',
  681. width: 120,
  682. caption: "팀장확인",
  683. alignment: 'center'
  684. },
  685. {
  686. dataField: 'Confirm2',
  687. width: 120,
  688. caption: "소장확인",
  689. alignment: 'center'
  690. },
  691. {
  692. dataField: 'Seq',
  693. width: 50,
  694. caption: "시퀀스",
  695. alignment: 'center',
  696. visible: false,
  697. sortOrder: 'desc'
  698. }
  699. ],
  700. paging: {
  701. enabled: true,
  702. pageSize: 18
  703. },
  704. pager: {
  705. },
  706. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
  707. rowClick = true;
  708. newReport = false;
  709. visiblePopup(true);
  710. var $EditorCommon = $('#EditorCommon');
  711. $('#EditorCommon').empty();
  712. $('<form><textarea name="editorjob" id="editorjob"></textarea></form>')
  713. .appendTo($EditorCommon)
  714. editor = new cheditor(); // 에디터 개체를 생성합니다.
  715. editor.config.editorHeight = '570px'; // 에디터 세로폭입니다.
  716. editor.config.editorWidth = '1296px'; // 에디터 가로폭입니다.
  717. editor.inputForm = 'editorjob'; // 위에 있는 textarea의 id입니다. 주의: name 속성 이름이 아닙니다.
  718. editor.run();
  719. $('#formatSelect').dxSelectBox("instance").option('value', clickRow.data.ReportFormatId());
  720. if (clickRow.data.ReportName().indexOf('<img src=')) {
  721. var tmp = clickRow.data.ReportName().split('<img src=');
  722. clickRow.data.ReportName(tmp[0]);
  723. }
  724. $('#reportName').dxTextBox("instance").option('value', clickRow.data.ReportName());
  725. $("#saveBtn").dxButton("instance").option("visible", true);
  726. beforeReportFormatId = clickRow.data.ReportFormatId();
  727. beforeFormatName = clickRow.data.FormatName();
  728. beforeSeq = clickRow.data.Seq();
  729. beforeDateTime = clickRow.data.DateTime();
  730. $("#saveBtn").dxButton("instance").option("text", "수정");
  731. $("#FILE_FORM").show();
  732. if (hasnotModificationPermission() || (BWA.UserInfo.UserId() == 'admin')) {
  733. $("#FILE_TAG").attr('disabled', false);
  734. } else {
  735. $("#FILE_TAG").attr('disabled', true);
  736. }
  737. $("#FILE_DOWN").show();
  738. $("#FILE_ADD").show();
  739. var dataSource = new DevExpress.data.DataSource({
  740. store: {
  741. type: "odata",
  742. url: endpointSelector + "/BemsReportHistory",
  743. },
  744. requireTotalCount: true,
  745. pageSize: 100
  746. });
  747. dataSource.filter([
  748. ["SiteId", "=", BWA.UserInfo.SiteId()],
  749. "and",
  750. ["Seq", "=", clickRow.data.Seq()],
  751. "and",
  752. ["DateTime", "=", clickRow.data.DateTime()]
  753. , "and",
  754. ["ReportName", "=", clickRow.data.ReportName()]
  755. , "and",
  756. ["ReportFormatId", "=", clickRow.data.ReportFormatId()]
  757. ]);
  758. dataSource.sort({ getter: "parts", asc: true });
  759. dataSource.load()
  760. .done(function (result) {
  761. var content = "";
  762. for (var i = 0; i < result.length; i++) {
  763. content = content + result[i].Content;
  764. }
  765. if (result.length > 0) {
  766. tempcontent = content;
  767. $("#FILE_DOWN").text(result[0].FileName);
  768. if (BemsWebApplication.config.mode == "production") {
  769. $("#FILE_DOWN").attr("href", BemsWebApplication.config.endpoints.service.production + filePath + result[0].FileName);
  770. } else {
  771. $("#FILE_DOWN").attr("href", BemsWebApplication.config.endpoints.service.local + filePath + result[0].FileName);
  772. }
  773. } else {
  774. tempcontent = "";
  775. }
  776. })
  777. .fail(function (error) {
  778. utils.toast.show(error);
  779. });
  780. },
  781. searchViewItems: [
  782. { id: 'FormatName' },
  783. { id: 'DateTime', type: 'dateRange', isOnlyDate: true },
  784. { id: 'ReportName' },
  785. { id: 'Writer' }
  786. ],
  787. handleViewShown: function () {
  788. },
  789. handleViewShowing: function () {
  790. //권한설정
  791. hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
  792. loadGridReportDate();
  793. $SideMenu.showSideMenuIfWill(params.view);
  794. },
  795. hasnotModificationPermission: hasnotModificationPermission //권한설정
  796. });
  797. var reportName = {
  798. placeholder: "일지 제목을 작성해주세요."
  799. }
  800. var formatSelect = {
  801. placeholder: "불러올 일지 양식을 선택해주세요.",
  802. onValueChanged: function () {
  803. var test = $("#formatSelect").dxSelectBox("instance").option('value');
  804. if (rowClick == false) {
  805. if ($("#formatSelect").dxSelectBox("instance").option('value') != null) {
  806. getFormatContent();
  807. }
  808. }
  809. }
  810. }
  811. function saveButtonClicked() {
  812. if ($("#saveBtn").dxButton("instance").option("text") == "작성") {
  813. saveReport();
  814. } else if ($("#saveBtn").dxButton("instance").option("text") == "수정") {
  815. DevExpress.ui.dialog.confirm("수정 하시겠습니까?", "수정").done(function (dialogResult) {
  816. if (dialogResult)
  817. modifyReport();
  818. });
  819. }
  820. }
  821. function delButtonClicked() {
  822. DevExpress.ui.dialog.confirm("삭제 하시겠습니까?", "삭제").done(function (dialogResult) {
  823. if (dialogResult)
  824. deleteReport();
  825. });
  826. }
  827. function confirmButtonClicked() {
  828. DevExpress.ui.dialog.confirm("결재 하시겠습니까?", "결재").done(function (dialogResult) {
  829. if (dialogResult)
  830. confirmReport();
  831. });
  832. }
  833. function newButtonClicked() {
  834. newReport = true;
  835. rowClick = false;
  836. visiblePopup(true);
  837. var $EditorCommon = $('#EditorCommon');
  838. $('#EditorCommon').empty();
  839. $('<form><textarea name="editorjob" id="editorjob"></textarea></form>')
  840. .appendTo($EditorCommon)
  841. editor = new cheditor(); // 에디터 개체를 생성합니다.
  842. editor.config.editorHeight = '570px'; // 에디터 세로폭입니다.
  843. editor.config.editorWidth = '1296px'; // 에디터 가로폭입니다.
  844. editor.inputForm = 'editorjob'; // 위에 있는 textarea의 id입니다. 주의: name 속성 이름이 아닙니다.
  845. editor.run();
  846. $("#FILE_FORM").show();
  847. if (hasnotModificationPermission() || (BWA.UserInfo.UserId() == 'admin')) {
  848. $("#FILE_TAG").attr('disabled', false);
  849. } else {
  850. $("#FILE_TAG").attr('disabled', true);
  851. }
  852. $("#FILE_DOWN").hide();
  853. $("#FILE_ADD").hide();
  854. $("#formatSelect").dxSelectBox("instance").option('value', null);
  855. $("#reportName").dxTextBox("instance").option('value', '');
  856. }
  857. viewModel.popupOptions = {
  858. width: 1300,
  859. height: 900,
  860. visible: visiblePopup,
  861. dragEnabled: false,
  862. shading: true,
  863. shadingColor: 'transparent',
  864. showTitle: true,
  865. title: "일지 상세",
  866. showCloseButton: true,
  867. onShown: function (t, tt) {
  868. popupInit = true;
  869. $("#FILE_TAG").val("");
  870. if (newReport) {
  871. $("#saveBtn").dxButton("instance").option("text", "작성");
  872. $("#delBtn").dxButton("instance").option("visible", false);
  873. $("#confirmBtn").dxButton("instance").option("visible", false);
  874. $("#formatSelect").dxSelectBox("instance").option("visible", true);
  875. $("#formatTxt").show();
  876. getFormatData();
  877. $("#formatSelect").dxSelectBox("instance").open();
  878. $("#formatSelect").dxSelectBox("instance").close();
  879. editor.doCmd('NewDocument', '1');
  880. editor.insertContents("");
  881. } else {
  882. $("#saveBtn").dxButton("instance").option("text", "수정");
  883. $("#delBtn").dxButton("instance").option("visible", true);
  884. $("#formatSelect").dxSelectBox("instance").option("visible", false);
  885. $("#formatTxt").hide();
  886. if (BWA.UserInfo.UserGroupName().indexOf('소장') > -1 || BWA.UserInfo.UserGroupName().indexOf('팀장') > -1) {
  887. HideConfirm();
  888. } else {
  889. $("#confirmBtn").dxButton("instance").option("visible", false);
  890. }
  891. getFormatData();
  892. $("#formatSelect").dxSelectBox("instance").open();
  893. $("#formatSelect").dxSelectBox("instance").close();
  894. editor.doCmd('NewDocument', '1');
  895. editor.insertContents(tempcontent);
  896. }
  897. },
  898. onHiding: function () {
  899. editor.doCmd('NewDocument', '1');
  900. }
  901. };
  902. viewModel.newButtonClicked = newButtonClicked;
  903. viewModel.saveButtonClicked = saveButtonClicked;
  904. viewModel.confirmButtonClicked = confirmButtonClicked;
  905. viewModel.delButtonClicked = delButtonClicked;
  906. viewModel.formatSelect = formatSelect;
  907. viewModel.reportName = reportName;
  908. return viewModel;
  909. };