272420c2548c7ff2195f619757338bb852239c53.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. BemsWebApplication.ReportFormat = function (params, viewInfo) {
  2. var formatCnt;
  3. var editor;
  4. var ReportFormatId = 0;
  5. var endpointSelector = "";
  6. if (BemsWebApplication.config.mode == "production") {
  7. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
  8. } else {
  9. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
  10. }
  11. var contentsUnit = 10000;
  12. var selectedName = null;
  13. //권한설정
  14. var hasnotModificationPermission = ko.observable(true);
  15. function getFormatData() {
  16. var dataSource = new DevExpress.data.DataSource({
  17. store: {
  18. type: "odata",
  19. url: endpointSelector + "/BemsReportFormat",
  20. },
  21. requireTotalCount: true,
  22. pageSize: 1000
  23. });
  24. dataSource.filter([
  25. ["parts", "=", 0]
  26. ]);
  27. dataSource.sort({ getter: "FormatName", asc: true });
  28. dataSource.load()
  29. .done(function (result) {
  30. for (var i = 0; i < result.length; i++) {
  31. if (ReportFormatId <= result[i].ReportFormatId)
  32. ReportFormatId = result[i].ReportFormatId;
  33. }
  34. formatCnt = result.length;
  35. $("#formatSelect").dxSelectBox("instance").option('dataSource', result);
  36. $("#formatSelect").dxSelectBox("instance").option('displayExpr', 'FormatName');
  37. $("#formatSelect").dxSelectBox("instance").option('valueExpr', "ReportFormatId");
  38. })
  39. .fail(function (error) {
  40. utils.toast.show(error);
  41. });
  42. }
  43. function setNewFormat() {
  44. if (editor == null) {
  45. editor = new cheditor(); // 에디터 개체를 생성합니다.
  46. editor.config.editorHeight = '530px'; // 에디터 세로폭입니다.
  47. editor.config.editorWidth = '1360px'; // 에디터 가로폭입니다.
  48. editor.inputForm = 'editor'; // 위에 있는 textarea의 id입니다. 주의: name 속성 이름이 아닙니다.
  49. editor.run(); // 에디터를 실행합니다.
  50. }
  51. else {
  52. editor.doCmd('NewDocument', '1');
  53. }
  54. $("#formatName").dxTextBox("instance").option('value', null);
  55. $("#formatName").dxTextBox("instance").option('readOnly', false);
  56. $("#formatTxt2").text("새 일지 양식 제목 : ");
  57. $("#saveBtn").dxButton("instance").option("text", "저장");
  58. $("#saveBtn").css("visibility", "visible");
  59. $("#formatName").dxTextBox("instance").option('value', null);
  60. $("#formatName").dxTextBox("instance").option('readOnly', false);
  61. $("#formatSelect").dxSelectBox("instance").option('value', null);
  62. getFormatData();
  63. }
  64. function saveFormat() {
  65. var store = new DevExpress.data.ODataStore({
  66. url: endpointSelector + "/BemsReportFormat",
  67. key: ["ReportFormatId", "parts"],
  68. keyType: {
  69. ReportFormatId: "Int32",
  70. parts: "Int32"
  71. }
  72. });
  73. var name = $("#formatName").dxTextBox("instance").option('value');
  74. if (!BWA.DataUtil.isValidInputValue(name)) {
  75. utils.toast.show('일지 이름이 정상적으로 입력되지 않았습니다 (앞뒤공백 허용안함)', 'error');
  76. return;
  77. }
  78. //if ($("#formatName").dxTextBox("instance").option('value') == "" || $("#formatName").dxTextBox("instance").option('value') == null) {
  79. // utils.toast.show('일지 이름을 입력해 주세요.', 'error');
  80. // return;
  81. //}
  82. var selectBoxItems = $("#formatSelect").dxSelectBox("instance").option('items');
  83. for (var i = 0; i < selectBoxItems.length; i++) {
  84. if (selectBoxItems[i].FormatName == $("#formatName").dxTextBox("instance").option('value')) {
  85. utils.toast.show('기존 일지 이름과 동일 합니다. 다른 이름을 적어 주세요.', 'error');
  86. return;
  87. }
  88. }
  89. var contentData = editor.outputBodyHTML();
  90. var partCnt = 1;
  91. if (contentData.length >= contentsUnit) {
  92. partCnt = parseInt(contentData.length / contentsUnit) + 1;
  93. }
  94. var contentsArray = new Array(partCnt);
  95. var contentLength = contentData.length;
  96. for (var i = 0; i < partCnt; i++) {
  97. if (contentLength <= contentsUnit) {
  98. contentsArray[i] = contentData;
  99. } else {
  100. if (contentLength <= contentsUnit) {
  101. contentsArray[i] = contentData.substr(i * contentsUnit, contentLength - i * contentsUnit);
  102. } else {
  103. contentsArray[i] = contentData.substr(i * contentsUnit, contentsUnit);
  104. }
  105. }
  106. var insertData = { ReportFormatId: parseInt(ReportFormatId) + 1, FormatName: $("#formatName").dxTextBox("instance").option('value'), Content: contentsArray[i], parts: i };
  107. store.insert(insertData)
  108. .done(function (values, key) {
  109. utils.toast.show('일지 양식이 등록되었습니다.');
  110. })
  111. .fail(function (error) {
  112. utils.toast.show('일지 양식이 실패하였습니다.', 'error');
  113. });
  114. }
  115. $("#saveBtn").dxButton("instance").option('disabled', true);
  116. $("#delBtn").dxButton("instance").option('disabled', true);
  117. $("#newBtn").dxButton("instance").option('disabled', true);
  118. setTimeout(function () {
  119. $("#saveBtn").dxButton("instance").option('disabled', false);
  120. $("#delBtn").dxButton("instance").option('disabled', false);
  121. $("#newBtn").dxButton("instance").option('disabled', false);
  122. getFormatData();
  123. setNewFormat();
  124. }, 1000);
  125. }
  126. function getFormatContent() {
  127. $("#saveBtn").dxButton("instance").option("text", "수정");
  128. $("#saveBtn").css("visibility", "visible");
  129. editor.doCmd('NewDocument', '1');
  130. var dataSource = new DevExpress.data.DataSource({
  131. store: {
  132. type: "odata",
  133. url: endpointSelector + "/BemsReportFormat",
  134. },
  135. requireTotalCount: true,
  136. pageSize: 100
  137. });
  138. dataSource.filter([
  139. ["ReportFormatId", "=", $("#formatSelect").dxSelectBox("instance").option('value')]
  140. ]);
  141. dataSource.sort({ getter: "parts", asc: true });
  142. dataSource.load()
  143. .done(function (result) {
  144. var content = "";
  145. for (var i = 0; i < result.length; i++) {
  146. content = content + result[i].Content;
  147. }
  148. if (editor == null) {
  149. editor = new cheditor(); // 에디터 개체를 생성합니다.
  150. editor.config.editorHeight = '530px'; // 에디터 세로폭입니다.
  151. editor.config.editorWidth = '1360px'; // 에디터 가로폭입니다.
  152. editor.inputForm = 'editor'; // 위에 있는 textarea의 id입니다. 주의: name 속성 이름이 아닙니다.
  153. editor.run(); // 에디터를 실행합니다.
  154. }
  155. editor.insertContents(content);
  156. })
  157. .fail(function (error) {
  158. utils.toast.show(error);
  159. });
  160. }
  161. function modifyFormat() {
  162. var id = $("#formatSelect").dxSelectBox("instance").option('value');
  163. if (formatCnt == 0 || id == null) {
  164. utils.toast.show('일지 양식이 없습니다.', 'error');
  165. } else {
  166. var id = $("#formatSelect").dxSelectBox("instance").option('value');
  167. var name = $("#formatName").dxTextBox("instance").option('value');
  168. var selectBoxItems = $("#formatSelect").dxSelectBox("instance").option('items');
  169. for (var i = 0; i < selectBoxItems.length; i++) {
  170. if (selectBoxItems[i].FormatName == $("#formatName").dxTextBox("instance").option('value') && selectedName != name) {
  171. utils.toast.show('기존 일지 이름과 동일 합니다. 다른 이름을 적어 주세요.', 'error');
  172. return;
  173. }
  174. }
  175. if (!BWA.DataUtil.isValidInputValue(name)) {
  176. utils.toast.show('일지 이름이 정상적으로 입력되지 않았습니다 (앞뒤공백 허용안함)', 'error');
  177. return;
  178. }
  179. var dataSource = new DevExpress.data.DataSource({
  180. store: {
  181. type: "odata",
  182. url: endpointSelector + "/BemsReportFormat",
  183. },
  184. requireTotalCount: true,
  185. pageSize: 100
  186. });
  187. dataSource.filter([
  188. ["ReportFormatId", "=", id]
  189. ]);
  190. dataSource.load()
  191. .done(function (result) {
  192. partsCnt = result.length;
  193. var store = new DevExpress.data.ODataStore({
  194. url: endpointSelector + "/BemsReportFormat",
  195. key: ["ReportFormatId", "parts"],
  196. keyType: {
  197. ReportFormatId: "Int32",
  198. parts: "Int32"
  199. }
  200. });
  201. for (var i = 0; i < partsCnt; i++) {
  202. var removeData = { ReportFormatId: id, parts: i };
  203. store.remove(removeData)
  204. .done(function (values, key) {
  205. })
  206. .fail(function (error) {
  207. utils.toast.show(error);
  208. });
  209. }
  210. }).fail(function (error) {
  211. utils.toast.show(error);
  212. });
  213. $("#saveBtn").dxButton("instance").option('disabled', true);
  214. $("#delBtn").dxButton("instance").option('disabled', true);
  215. $("#newBtn").dxButton("instance").option('disabled', true);
  216. setTimeout(function () {
  217. var store = new DevExpress.data.ODataStore({
  218. url: endpointSelector + "/BemsReportFormat",
  219. key: ["ReportFormatId"],
  220. keyType: {
  221. ReportFormatId: "Int32"
  222. }
  223. });
  224. var contentData = editor.outputBodyHTML();
  225. var partCnt = 1;
  226. if (contentData.length >= contentsUnit) {
  227. partCnt = parseInt(contentData.length / contentsUnit) + 1;
  228. }
  229. var contentsArray = new Array(partCnt);
  230. var contentLength = contentData.length;
  231. for (var i = 0; i < partCnt; i++) {
  232. if (contentLength <= contentsUnit) {
  233. contentsArray[i] = contentData;
  234. } else {
  235. if (contentLength <= contentsUnit) {
  236. contentsArray[i] = contentData.substr(i * contentsUnit, contentLength - i * contentsUnit);
  237. } else {
  238. contentsArray[i] = contentData.substr(i * contentsUnit, contentsUnit);
  239. }
  240. }
  241. var insertData = { ReportFormatId: id, FormatName: name, Content: contentsArray[i], parts: i };
  242. store.insert(insertData)
  243. .done(function (values, key) {
  244. utils.toast.show('일지 양식이 수정되었습니다.');
  245. })
  246. .fail(function (error) {
  247. utils.toast.show('일지 양식 수정이 실패하였습니다.', 'error');
  248. });
  249. }
  250. setTimeout(function () {
  251. $("#saveBtn").dxButton("instance").option('disabled', false);
  252. $("#delBtn").dxButton("instance").option('disabled', false);
  253. $("#newBtn").dxButton("instance").option('disabled', false);
  254. getFormatData();
  255. setNewFormat();
  256. }, 1000);
  257. }, 1000);
  258. }
  259. }
  260. function DeleteFormat() {
  261. var partsCnt = 0;
  262. if (formatCnt == 0 || $("#formatSelect").dxSelectBox("instance").option('value') == null) {
  263. utils.toast.show('일지 양식이 없습니다.', 'error');
  264. } else {
  265. var id = $("#formatSelect").dxSelectBox("instance").option('value');
  266. var dataSource = new DevExpress.data.DataSource({
  267. store: {
  268. type: "odata",
  269. url: endpointSelector + "/BemsReportFormat",
  270. },
  271. requireTotalCount: true,
  272. pageSize: 100
  273. });
  274. dataSource.filter([
  275. ["ReportFormatId", "=", id]
  276. ]);
  277. dataSource.load()
  278. .done(function (result) {
  279. partsCnt = result.length;
  280. var store = new DevExpress.data.ODataStore({
  281. url: endpointSelector + "/BemsReportFormat",
  282. key: ["ReportFormatId", "parts"],
  283. keyType: {
  284. ReportFormatId: "Int32",
  285. parts: "Int32"
  286. }
  287. });
  288. for (var i = 0; i < partsCnt; i++) {
  289. var removeData = { ReportFormatId: id, parts: i };
  290. store.remove(removeData)
  291. .done(function (values, key) {
  292. utils.toast.show('일지 양식이 삭제되었습니다.');
  293. })
  294. .fail(function (error) {
  295. utils.toast.show('일지 양식 삭제가 실패하였습니다.', 'error');
  296. });
  297. }
  298. })
  299. .fail(function (error) {
  300. utils.toast.show(error);
  301. });
  302. $("#saveBtn").dxButton("instance").option('disabled', true);
  303. $("#delBtn").dxButton("instance").option('disabled', true);
  304. $("#newBtn").dxButton("instance").option('disabled', true);
  305. setTimeout(function () {
  306. $("#saveBtn").dxButton("instance").option('disabled', false);
  307. $("#delBtn").dxButton("instance").option('disabled', false);
  308. $("#newBtn").dxButton("instance").option('disabled', false);
  309. getFormatData();
  310. setNewFormat();
  311. }, 1000);
  312. }
  313. }
  314. function handleViewShown() {
  315. //권한설정
  316. hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
  317. $("#delBtn").dxButton("instance").option("visible", true);
  318. setNewFormat();
  319. $SideMenu.showSideMenuIfWill(params.view);
  320. }
  321. var searchViewOptions = {
  322. };
  323. function handleSearchInSearchView() {
  324. }
  325. var viewModel = $.extend(BWA.CommonView.create(params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null, handleSearchInSearchView),
  326. {
  327. formatSelect: {
  328. placeholder: "불러올 기존 일지를 선택해주세요.",
  329. onInitialized: function () {
  330. getFormatData();
  331. },
  332. onValueChanged: function () {
  333. if ($("#formatSelect").dxSelectBox("instance").option('value') != null) {
  334. $("#formatName").dxTextBox("instance").option('value', $("#formatSelect").dxSelectBox("instance").option('text'));
  335. $("#formatName").dxTextBox("instance").option('readOnly', false);
  336. $("#formatTxt2").text("기존 일지 양식 제목 : ");
  337. getFormatContent();
  338. selectedName = $("#formatSelect").dxSelectBox("instance").option('text');
  339. }
  340. }
  341. },
  342. formatName: {
  343. readOnly: false
  344. },
  345. newButtonClicked: function () {
  346. setNewFormat();
  347. },
  348. saveButtonClicked: function () {
  349. if ($("#saveBtn").dxButton("instance").option("text") == "저장") {
  350. DevExpress.ui.dialog.confirm("양식을 저장 하시겠습니까?", "저장").done(function (dialogResult) {
  351. if (dialogResult) {
  352. saveFormat();
  353. }
  354. });
  355. } else if ($("#saveBtn").dxButton("instance").option("text") == "수정") {
  356. DevExpress.ui.dialog.confirm("양식을 수정 하시겠습니까?", "수정").done(function (dialogResult) {
  357. if (dialogResult) {
  358. modifyFormat();
  359. }
  360. });
  361. }
  362. },
  363. delButtonClicked: function () {
  364. DevExpress.ui.dialog.confirm("양식을 삭제 하시겠습니까?", "삭제").done(function (dialogResult) {
  365. if (dialogResult) {
  366. DeleteFormat();
  367. }
  368. });
  369. },
  370. hasnotModificationPermission: hasnotModificationPermission //권한설정
  371. });
  372. return viewModel;
  373. };