c4d56c6595b9aac124d5980fb4d7c34e2e7f0853.svn-base 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. $(function () {
  2. BWA.DataGrid = BWA.DataGrid || {};
  3. BWA.DataGrid.createViewWithDataGrid = $CommonViewDataGrid = function (params, viewInfo, dbModelId, options) {
  4. var mandatoryFields = options.mandatoryFields,
  5. handleBeforePopupShowingPromise = options.handleBeforePopupShowingPromise,
  6. isValidateWithFunction = options.isValidateWithFunction,
  7. isModifiable = _.isBoolean(options.isModifiable) ? options.isModifiable : undefined,
  8. //2015 11 17 hcLee
  9. //handleCustermInsert = options.handleCustermInsert,
  10. //useDeleteButton = options.useDeleteButton || true // hcLee 2015 03 06 ->
  11. useDeleteButton = (options.useDeleteButton == false) ? false : true;// hcLee 2015 03 06 <-
  12. //alert('option = ' + options.useDeleteButton);
  13. var initialized = false,
  14. initializedInPopup = false,
  15. isHidden = false,
  16. shouldReload = false,
  17. dataViewModel = new BemsWebApplication[dbModelId + 'ViewModel'](),
  18. backupDataViewModel = null,
  19. isNewInPopup = ko.observable(false),
  20. isEditModeInPopup = ko.observable(false),
  21. viewModeInPopup = ko.observable(true),
  22. visibleEditButton = ko.observable(true),
  23. visibleDeleteButton = ko.observable(true),
  24. visibleCancelButton = ko.observable(false),
  25. selectedId = {},
  26. selectedData = ko.observable(),
  27. gridView = ko.observable(),
  28. popupVisible = ko.observable(false),
  29. dataSource,
  30. isUseSiteId = options.isUseSiteId,
  31. defaultFilter = ko.observable([]),
  32. popupInsertButtonOptions,
  33. hasnotModificationPermission;
  34. //alert(useDeleteButton);
  35. function handleModification() {
  36. shouldReload = true;
  37. }
  38. function showPopup(clickRowData) {
  39. if (handleBeforePopupShowingPromise) {
  40. var promise = handleBeforePopupShowingPromise(isNewInPopup, dataViewModel, clickRowData);
  41. if (_.isObject(promise)) {
  42. promise.done(function () {
  43. popupVisible(true);
  44. });
  45. }
  46. else {
  47. popupVisible(true);
  48. }
  49. }
  50. else {
  51. popupVisible(true);
  52. }
  53. }
  54. function handleViewShown() {
  55. if (shouldReload) {
  56. shouldReload = false;
  57. refreshList();
  58. //dataSource.pageIndex(0);
  59. //dataSource.load();
  60. }
  61. if (initialized === false) {
  62. if (dataViewModel.SiteId != null) {
  63. defaultFilter(dataSource.filter());
  64. if (_.isUndefined(defaultFilter()) && isUseSiteId !== false) {
  65. defaultFilter([['SiteId', '=', BWA.UserInfo.SiteId()]]);
  66. dataSource.filter(defaultFilter());
  67. }
  68. }
  69. $.extend(options, {
  70. dxDataSource: dataSource,
  71. selectedSourceItem: dataViewModel,
  72. selectedId: selectedId,
  73. selectedData: selectedData,
  74. datagridId: 'gridContainer',
  75. popupVisible: popupVisible,
  76. handleShowPopup: showPopup,
  77. dbId: dbModelId
  78. });
  79. if (options.useNumberColumn === undefined) {
  80. options.useNumberColumn = true;
  81. }
  82. $("#gridContainer").dxDataGrid(utils.datagrid.defaultOptions(options));
  83. gridView($('#gridContainer').dxDataGrid('instance'));
  84. // initializedFunction();
  85. initialized = true;
  86. }
  87. if (isHidden) {
  88. var grid = gridView();
  89. if (grid.refresh) {
  90. grid.refresh();
  91. }
  92. isHidden = false;
  93. }
  94. if (typeof options.handleViewShown === 'function') {
  95. options.handleViewShown(dataViewModel, isEditModeInPopup);
  96. }
  97. //$SearchView.isNotUse(true);
  98. //alert("viewShown");
  99. }
  100. function handleViewDisposing() {
  101. BemsWebApplication.db[dbModelId].modified.remove(handleModification);
  102. }
  103. function handleViewHidden() {
  104. isHidden = true;
  105. if ($SearchView.visibleObservable != null && $SearchView.visibleObservable != undefined) // 2018 01 19 hcLee 방어코드
  106. $SearchView.visibleObservable(false); // hcLee 2015 07 28 // 화면이 바뀌면 팝업되어있던 검색창은 닫는다.
  107. //
  108. //visiblePopup(false);
  109. }
  110. function handleViewShowing() {
  111. if (options.handleViewShowing) {
  112. options.handleViewShowing(dataViewModel);
  113. }
  114. //window.$SearchView.isNotUse(true);
  115. //BemsWebApplication.app.loadTemplates('views/sideMenu/sidemenu1.dxview');
  116. //deferred.resolve();
  117. }
  118. function refreshList() {
  119. //dataSource.pageIndex(0);
  120. //dataSource.load();
  121. gridView().refresh();
  122. }
  123. function handlePopupHiding(e) {
  124. if (options.handlePopupHiding) {
  125. options.handlePopupHiding(isNewInPopup);
  126. }
  127. }
  128. function handlePopupShowing(e) {
  129. //alert('handlePopupShowing');
  130. //visibleDeleteButton(useDeleteButton); // hcLee 2015 03 04
  131. //visibleDeleteButton(false); // hcLee 2015 03 04
  132. visibleCancelButton(false);
  133. if (isNewInPopup() === false) {
  134. activePopupViewMode();
  135. // hcLee 2016 02 14
  136. if (_.isUndefined(options.handlePopupShowing2) === false) {
  137. options.handlePopupShowing2(selectedId);
  138. }
  139. BemsWebApplication.db[dbModelId].byKey(selectedId).done(function (data) {
  140. dataViewModel.fromJS(data);
  141. var handle = options.handleAfterLoadingModelByKey;
  142. if (typeof handle === 'function') {
  143. handle(data, dataViewModel, isNewInPopup, isEditModeInPopup, selectedData());
  144. }
  145. });
  146. }
  147. else {
  148. clearDataModelValue(dataViewModel);
  149. }
  150. if (_.isUndefined(options.handlePopupShowing) === false) {
  151. options.handlePopupShowing(isNewInPopup, dataViewModel, selectedData());
  152. }
  153. }
  154. function handlePopupShown() {
  155. /* hcLee 2016 06 03 위로 이동
  156. if (_.isFunction(options.checkPopupVisible)) {
  157. if (options.checkPopupVisible(isNewInPopup) === false) {
  158. popupVisible(false);
  159. return;
  160. }
  161. }*/
  162. if (initializedInPopup === false) {
  163. if (_.has(options, 'handleInitializedInPopup')) {
  164. options.handleInitializedInPopup();
  165. }
  166. initializedInPopup = true;
  167. }
  168. if (_.has(options, 'handlePopupShown')) {
  169. options.handlePopupShown(isEditModeInPopup(), isNewInPopup(), dataViewModel);
  170. }
  171. }
  172. function clearDataModelValue(v) {
  173. BWA.DataUtil.resetViewModel(v);
  174. if (isUseSiteId) v.SiteId(BWA.UserInfo.SiteId()); // if 문 추가 hcLee2015 03 06
  175. var handleInitializeDataModelValue = options.handleInitializeDataModelValue;
  176. if (handleInitializeDataModelValue !== undefined) {
  177. handleInitializeDataModelValue(v);
  178. }
  179. }
  180. function handleConfirmDelete() {
  181. // hcLee 2015 07 16 -->
  182. if (options.handleBeforeDelete) {
  183. var promises = [];
  184. promises.push(options.handleBeforeDelete(selectedId));
  185. $.when.apply(this, promises).done(function () {
  186. });
  187. } // hcLee 2015 07 16
  188. BemsWebApplication.db[dbModelId].remove(selectedId).done(function () {
  189. popupVisible(false);
  190. refreshList();
  191. if (typeof options.handleAfterDelete === 'function') {
  192. options.handleAfterDelete();
  193. }
  194. utils.toast.show('데이터베이스 항목 삭제 작업이 성공하였습니다.');
  195. });
  196. }
  197. function update_real(showToast) {
  198. showToast = showToast || true;
  199. //console.log( dataViewModel.BuildingId() );
  200. var updatePromise = BemsWebApplication.db[dbModelId].update(selectedId, dataViewModel.toJS());
  201. var anotherPromise = null;
  202. if (_.isFunction(options.handleSaveButtonInPopup)) {
  203. anotherPromise = options.handleSaveButtonInPopup(false);
  204. }
  205. var promise = $.when(updatePromise, anotherPromise);
  206. promise.done(function () {
  207. refreshList();
  208. if (showToast) {
  209. utils.toast.show('데이터 수정 작업이 성공하였습니다.');
  210. }
  211. if (options.handleSaveSuccess) {
  212. options.handleSaveSuccess(dataViewModel);
  213. }
  214. popupVisible(false);
  215. // 2016 09 29 hcLee 추가
  216. if (typeof options.afterUpdateDataViewModel === 'function') {
  217. $.when(options.afterUpdateDataViewModel(dataViewModel))
  218. .done(function (result) {
  219. //utils.toast.show(result, '정보');
  220. });
  221. }
  222. })
  223. .fail(function () {
  224. // console.log(arguments);
  225. // utils.toast.show('데이터베이스 작업에 오류가 있습니다 : ' + arguments[2], 'error');
  226. utils.toast.show('수정이 실패하였습니다. 필수입력사항(*)이 누락, 데이터 중복, 또는 입력글자수 초과 입니다.', 'error');
  227. });
  228. return promise;
  229. }
  230. function update(showToast) {
  231. if (typeof options.beforeUpdateDataViewModel === 'function') {
  232. $.when(options.beforeUpdateDataViewModel(dataViewModel))
  233. .done(function (result, fMsg) {
  234. if (result == 1) {
  235. // 자체적으로 update를 하는 화면은 1을 리턴
  236. //2016 01 06 beforeUpdateDataViewModel를 사용하는 화면은 현재 구매요청과 발주 2군데 이다. 둘다 자체적으로 update를 직접 하고 있다.
  237. //update_real(showToast);
  238. }
  239. else if (result == 2) {
  240. update_real(showToast);
  241. }
  242. else {
  243. utils.toast.show(fMsg, 'error');
  244. return;
  245. }
  246. });
  247. }
  248. else {
  249. update_real(showToast);
  250. }
  251. }
  252. // 필수 데이터 필드 이름 목록이 입력되어 있으면, 해당 필드값이 null 인지 검사한다.
  253. function isValidateMandatoryDataFields() {
  254. if (_.isArray(mandatoryFields)) {
  255. var mandatoryFieldName = null;
  256. var isValid = _.every(mandatoryFields, function (field) {
  257. var value = dataViewModel[field.dataField];
  258. if (_.isFunction(value)) {
  259. value = value();
  260. }
  261. if (!_.isNull(value) && !_.isUndefined(value)) {
  262. if (_.isString(value)) {
  263. if (_.isEmpty(value) === false) {
  264. return true;
  265. }
  266. }
  267. else {
  268. return true;
  269. }
  270. }
  271. mandatoryFieldName = field.name;
  272. return false;
  273. });
  274. if (!isValid) {
  275. utils.toast.show('값을 입력해 주십시오: ' + mandatoryFieldName, 'error');
  276. return false;
  277. }
  278. }
  279. return true;
  280. }
  281. // 외부 함수를 통해 값이 유효한지 검사한다.
  282. // dataViewModel 외에 다른 유효한 상황들이 있을 때 사용한다.(예: 구매요청 자재)
  283. function checkValidateFunction() {
  284. if (_.isFunction(isValidateWithFunction)) {
  285. var errorMessage = { message: '' };
  286. if (!isValidateWithFunction(errorMessage)) {
  287. utils.toast.show('{0}: {1}'.formati($('error'), errorMessage.message), 'error');
  288. return false;
  289. }
  290. }
  291. return true;
  292. }
  293. function handlePopupButtonSave() {
  294. if (isValidateMandatoryDataFields() === false) {
  295. return;
  296. }
  297. // 필수 입력 조건 체크는 각 화면의 옵션 beforeInsertingDataViewModel에서 각각 처리 하는 것을 권합니다. hcLee 2016 01 15
  298. // -->>
  299. // 필수 입력 조건 체크
  300. // cyim 2015.12.28 : 설정-시설관리-시설등록-설비정보관리 에서 설비 등록 팝업창의 입력 정보 체크
  301. if (dbModelId == "CmFacility") {
  302. // 시설유형
  303. if (BWA.DataUtil.isValidInputValue(dataViewModel.FacilityTypeId()) == false
  304. // 시설명칭
  305. || BWA.DataUtil.isValidInputValue(dataViewModel.Name()) == false
  306. // 시설별칭
  307. || BWA.DataUtil.isValidInputValue(dataViewModel.Nickname()) == false
  308. // 시설분류
  309. || (BWA.DataUtil.isValidInputValue(dataViewModel.FirstClassId()) == false
  310. && BWA.DataUtil.isValidInputValue(dataViewModel.SecondClassId()) == false
  311. && BWA.DataUtil.isValidInputValue(dataViewModel.ThirdClassId()) == false)) {
  312. utils.toast.show($G('Error_CmFacility_NotInputData'), 'error');
  313. return;
  314. }
  315. }
  316. // cyim 2015.12.29 : 설정-시설관리-회사부서관리-회사구분코드 에서 입력 정보 체크
  317. else if (dbModelId == "CmCompanyType") {
  318. // 회사
  319. if (BWA.DataUtil.isValidInputValue(dataViewModel.Name()) == false) {
  320. utils.toast.show($G('Error_CmCompanyType_NotInputData'), 'error');
  321. return;
  322. }
  323. }
  324. else if (dbModelId == "BemsAlarmGroup") {
  325. if (BWA.DataUtil.isValidInputValue(dataViewModel.Name()) == false) {
  326. utils.toast.show($G('Error_BemsAlarmGroup_NotInputData'), 'error');
  327. return;
  328. }
  329. }
  330. else if (dbModelId == "BemsAlarmGroupUser") {
  331. if (BWA.DataUtil.isValidInputValue(dataViewModel.SiteId()) == false ||
  332. BWA.DataUtil.isValidInputValue(dataViewModel.UserId()) == false ||
  333. BWA.DataUtil.isValidInputValue(dataViewModel.AlarmGroupId()) == false) {
  334. utils.toast.show($G('Error_BemsAlarmGroup_NotInputData'), 'error');
  335. return;
  336. }
  337. }
  338. // cyim 2015.12.29 : 설정-시설관리-회사부서관리-회사정보관리 에서 입력 정보 체크
  339. else if (dbModelId == "CmCompany") {
  340. // 회사명칭
  341. if (BWA.DataUtil.isValidInputValue(dataViewModel.Name()) == false
  342. // 회사구분
  343. || BWA.DataUtil.isValidInputValue(dataViewModel.CompanyTypeId()) == false
  344. // 회사대표
  345. || BWA.DataUtil.isValidInputValue(dataViewModel.RepresentativeName()) == false
  346. // 대표번호
  347. || BWA.DataUtil.isValidInputValue(dataViewModel.PhoneNo()) == false) {
  348. utils.toast.show($G('Error_CmCompany_NotInputData'), 'error');
  349. return;
  350. }
  351. }
  352. //공사계획
  353. else if (dbModelId == "FmsConstruction") {
  354. //공사명
  355. if (BWA.DataUtil.isValidInputValue(dataViewModel.Name()) == false
  356. //공사위치
  357. || BWA.DataUtil.isValidInputValue(dataViewModel.ConstructLocation()) == false
  358. //공사구분
  359. || BWA.DataUtil.isValidInputValue(dataViewModel.ConstructionTypeId()) == false
  360. //공사상태
  361. || BWA.DataUtil.isValidInputValue(dataViewModel.ProgressId()) == false
  362. //공사업체
  363. || BWA.DataUtil.isValidInputValue(dataViewModel.PartnerId()) == false
  364. //공사업체 연락처
  365. //|| BWA.DataUtil.isValidInputValue(dataViewModel.PartnerPhoneNo()) == false
  366. //책임자
  367. || BWA.DataUtil.isValidInputValue(dataViewModel.OwnerShipName()) == false
  368. //작업자연락처
  369. || BWA.DataUtil.isValidInputValue(dataViewModel.OwnerShipPhoneNo()) == false) {
  370. utils.toast.show('저장 혹은 수정 반드시 필수 입력 정보(*)를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)', 'error');
  371. return;
  372. }
  373. }
  374. else if (dbModelId == "CmCompany") {
  375. // 회사명칭
  376. if (BWA.DataUtil.isValidInputValue(dataViewModel.Name()) == false
  377. // 회사구분
  378. || BWA.DataUtil.isValidInputValue(dataViewModel.CompanyTypeId()) == false
  379. // 회사대표
  380. || BWA.DataUtil.isValidInputValue(dataViewModel.RepresentativeName()) == false
  381. // 대표번호
  382. || BWA.DataUtil.isValidInputValue(dataViewModel.PhoneNo()) == false) {
  383. utils.toast.show($G('Error_CmCompany_NotInputData'), 'error');
  384. return;
  385. }
  386. }
  387. // <<---
  388. // 필수 입력 조건 체크는 각 화면의 옵션 beforeInsertingDataViewModel에서 각각 처리 하는 것을 권합니다. hcLee 2016 01 15
  389. //
  390. if (isNewInPopup()) {
  391. if (_.has(options, 'handleSaveInPopup')) {
  392. var promise = options.handleSaveInPopup(dataViewModel, popupVisible);
  393. if (promise) {
  394. promise.then(handleThenAfterInsert);
  395. }
  396. }
  397. else {
  398. insert();
  399. }
  400. }
  401. else {
  402. update();
  403. }
  404. }
  405. function handleThenAfterInsert(response, responseKey) {
  406. if (_.isFunction(options.handleSaveButtonInPopup)) {
  407. options.handleSaveButtonInPopup(true);
  408. }
  409. if (_.isFunction(options.handleAfterSaveInPopup)) {
  410. options.handleAfterSaveInPopup(responseKey, response);
  411. }
  412. refreshList();
  413. popupVisible(false);
  414. // 2015 07 16 hcLee
  415. if (typeof options.handleAfterInsert === 'function') {
  416. options.handleAfterInsert(responseKey, response);
  417. }
  418. utils.toast.show('데이터베이스 항목 등록 작업이 성공하였습니다.');
  419. }
  420. function insert_real() {
  421. BemsWebApplication.db[dbModelId].insert(dataViewModel.toJS()).done(handleThenAfterInsert)
  422. .fail(function () {
  423. utils.toast.show('등록이 실패하였습니다. 필수입력사항(*)이 누락 되었거나 중복된 데이터가 있습니다.', 'error');
  424. });
  425. }
  426. function insert() {
  427. if (typeof options.beforeInsertingDataViewModel === 'function') {
  428. // !!!!! hcLee 2015 11 18-19 결국 beforeInsertingDataViewModel 추가구현 필요,
  429. // beforeInsertingDataViewModel 는 Deferred로 구현되어져야 한다 !!!!!
  430. $.when(options.beforeInsertingDataViewModel(dataViewModel))
  431. .done(function (result, fMsg) {
  432. if (result == true) {
  433. insert_real();
  434. }
  435. else {
  436. utils.toast.show(fMsg, 'error');
  437. }
  438. });
  439. }
  440. else {
  441. insert_real();
  442. }
  443. }
  444. function activePopupEditMode() {
  445. //visibleCancelButton( false );
  446. // alert('activePopupEditMode');
  447. visibleEditButton(false);
  448. visibleDeleteButton(false);
  449. viewModeInPopup(false);
  450. isEditModeInPopup(true);
  451. }
  452. function activePopupViewMode() {
  453. // alert('activePopupViewMode');
  454. visibleEditButton(true);
  455. visibleDeleteButton(useDeleteButton); // 왜 이게 TRUE인가?
  456. //visibleDeleteButton(false);
  457. viewModeInPopup(true);
  458. isEditModeInPopup(false);
  459. }
  460. function handlePopupButtonEdit() {
  461. // hcLee 2016 02 01
  462. if (_.has(options, 'handlePopupButtonEdit')) {
  463. options.handlePopupButtonEdit(dataViewModel);
  464. }
  465. // hcLee 2016 02 01
  466. activePopupEditMode();
  467. visibleCancelButton(true);
  468. backupDataViewModel = getBackupDataViewModel(dataViewModel);
  469. }
  470. function getBackupDataViewModel(model) {
  471. var object = {};
  472. $.each(model, function (name, value) {
  473. if (ko.isObservable(value)) {
  474. object[name] = value();
  475. }
  476. });
  477. return object;
  478. }
  479. function restoreDataViewModelFromBackup(model, backupModel) {
  480. $.each(backupModel, function (name, value) {
  481. model[name](value);
  482. });
  483. }
  484. function handlePopupButtonCancel() {
  485. activePopupViewMode();
  486. visibleCancelButton(false);
  487. if (_.isFunction(options.handleCancelInPopup)) {
  488. options.handleCancelInPopup(dataViewModel, backupDataViewModel);
  489. }
  490. restoreDataViewModelFromBackup(dataViewModel, backupDataViewModel);
  491. }
  492. function popupInsertView() {
  493. // 2016 06 03 handlePopupShown에서 이곳으로 이동 hcLee
  494. if (_.isFunction(options.checkPopupVisible)) {
  495. if (options.checkPopupVisible(isNewInPopup) === false) {
  496. popupVisible(false);
  497. return;
  498. }
  499. }
  500. activePopupEditMode();
  501. isNewInPopup(true);
  502. visibleEditButton(false);
  503. visibleDeleteButton(false);
  504. showPopup();
  505. }
  506. function handlePopupButtonDelete() {
  507. DevExpress.ui.dialog.confirm($G('deleteConfirmMsg'), "삭제").then(function (result) {
  508. if (result) {
  509. handleConfirmDelete();
  510. }
  511. });
  512. }
  513. function handlePopupButtonClose() {
  514. // 팝업의 추가 버튼들 깜빡이는 문제 해결을 위해 확장한 2016 07 26 hcLee
  515. if (_.isFunction(options.handlePopupButtonClose)) {
  516. options.handlePopupButtonClose(dataViewModel, backupDataViewModel);
  517. }
  518. isNewInPopup(false);
  519. isEditModeInPopup(false);
  520. popupVisible(false);
  521. }
  522. popupVisible.subscribe(function (visible) {
  523. if (visible == false) {
  524. $.each(selectedId, function (name) {
  525. delete selectedId[name];
  526. });
  527. //clearDataModelValue(dataViewModel);
  528. isNewInPopup(false);
  529. // visibleEditButton(true);
  530. // hcLee 2016 01 19
  531. //visibleDeleteButton(useDeleteButton);
  532. visibleDeleteButton(false);
  533. }
  534. });
  535. //dataSource = $DataSource(options, dbModelId);
  536. dataSource = BWA.DataUtil.createDataSource(options, dbModelId);
  537. BemsWebApplication.db[dbModelId].modified.add(handleModification);
  538. var viewModel = BWA.CommonView.create(params, viewInfo,
  539. options,
  540. (options.NoSearch != undefined) ? null : ko.observable(null), // 2018 01 19 hcLee 검색버튼 다시 생기는 문제 처리
  541. //options, ko.observable(null), handleViewShown, defaultFilter); // 2018 01 19 hcLee 검색버튼 다시 생기는 문제 처리
  542. handleViewShown, defaultFilter); // 2018 01 19 hcLee
  543. hasnotModificationPermission = viewModel.hasnotModificationPermission;
  544. var toolbarItems, toolbarItems2;
  545. if (_.isUndefined(options.toolbarItemsInPopup)) {
  546. // isModifiable은 사용자 권한에 따라 바뀌는 것이 아니고, 설계된 화면 자체가 그렇게 생겼다는 의미다.
  547. toolbarItems = [
  548. { location: 'before', text: $G('detailInfo') },
  549. { location: 'after', widget: 'button', options: { text: $G('edit'), icon: 'edit', visible: _.isBoolean(isModifiable) ? isModifiable : visibleEditButton, disabled: hasnotModificationPermission, clickAction: handlePopupButtonEdit } },
  550. { location: 'after', widget: 'button', options: { text: $G('delete'), type: 'danger', icon: 'remove', visible: _.isBoolean(isModifiable) ? isModifiable : visibleDeleteButton, disabled: hasnotModificationPermission, clickAction: handlePopupButtonDelete } },
  551. { location: 'after', widget: 'button', options: { text: $G('cancel'), icon: 'cancel', visible: visibleCancelButton, clickAction: handlePopupButtonCancel } },
  552. { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', visible: isEditModeInPopup, disabled: hasnotModificationPermission, clickAction: handlePopupButtonSave } },
  553. { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } }
  554. ];
  555. toolbarItems2 = [
  556. { location: 'before', text: $G('detailInfo') },
  557. { location: 'after', widget: 'button', options: { text: $G('edit'), icon: 'edit', visible: _.isBoolean(isModifiable) ? isModifiable : visibleEditButton, disabled: hasnotModificationPermission, clickAction: handlePopupButtonEdit } },
  558. { location: 'after', widget: 'button', options: { text: $G('cancel'), icon: 'cancel', visible: visibleCancelButton, clickAction: handlePopupButtonCancel } },
  559. { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', visible: isEditModeInPopup, disabled: hasnotModificationPermission, clickAction: handlePopupButtonSave } },
  560. { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } }
  561. ];
  562. if (_.isUndefined(options.getAddedToolbarItemsInPopup) === false) {
  563. toolbarItems.splice.apply(toolbarItems, [1, 0].concat(options.getAddedToolbarItemsInPopup({
  564. // param 추가 : JDSONG
  565. isNewInPopup: isNewInPopup,
  566. isEditModeInPopup: isEditModeInPopup,
  567. hasnotModificationPermission: hasnotModificationPermission,
  568. dataViewModel: dataViewModel,
  569. popupVisible: popupVisible
  570. })));
  571. }
  572. if (_.isUndefined(options.getAddedToolbarItemsInPopup) === false) {
  573. toolbarItems2.splice.apply(toolbarItems2, [1, 0].concat(options.getAddedToolbarItemsInPopup({
  574. // param 추가 : JDSONG
  575. isNewInPopup: isNewInPopup,
  576. isEditModeInPopup: isEditModeInPopup,
  577. hasnotModificationPermission: hasnotModificationPermission,
  578. dataViewModel: dataViewModel,
  579. popupVisible: popupVisible
  580. })));
  581. }
  582. }
  583. else {
  584. toolbarItems = options.toolbarItemsInPopup;
  585. toolbarItems.push({ location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } });
  586. toolbarItems2 = options.toolbarItemsInPopup;
  587. toolbarItems2.push({ location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } });
  588. }
  589. var popupOptions = {
  590. width: options.popupWidth || '680px',
  591. height: 'auto',
  592. //shading: false,
  593. shadingColor: 'rgba(0,0,0,0.0)',
  594. visible: popupVisible,
  595. closeOnOutsideClick: false,
  596. showingAction: handlePopupShowing,
  597. shownAction: handlePopupShown,
  598. hidingAction: handlePopupHiding,
  599. animation: params.popupAnimation || utils.popup.createAnimation()
  600. };
  601. var popupOptions_floorplan = {
  602. width: options.popupWidth || '720px',
  603. height: '780px',
  604. //shading: false,
  605. shadingColor: 'rgba(0,0,0,0.0)',
  606. visible: popupVisible,
  607. closeOnOutsideClick: false,
  608. showingAction: handlePopupShowing,
  609. shownAction: handlePopupShown,
  610. hidingAction: handlePopupHiding,
  611. animation: params.popupAnimation || utils.popup.createAnimation()
  612. };
  613. popupInsertButtonOptions = {
  614. icon: 'add',
  615. id: 'create',
  616. title: options.insertButtonText || $G('insert'),
  617. action: popupInsertView,
  618. visible: 'true',
  619. disabled: hasnotModificationPermission
  620. };
  621. if (_.has(params, 'popupPosition')) {
  622. popupOptions.position = params.positions;
  623. popupOptions_floorplan.position = params.positions;
  624. }
  625. if (_.isFunction(options.contentReadyActionInPopup)) {
  626. popupOptions.contentReadyAction = options.contentReadyActionInPopup;
  627. popupOptions_floorplan.contentReadyAction = options.contentReadyActionInPopup;
  628. }
  629. if (_.isUndefined(params.popupPosition) === false) {
  630. popupOptions.position = params.popupPosition;
  631. popupOptions_floorplan.position = params.popupPosition;
  632. }
  633. if (_.isUndefined(params.shownActionInPopup) === false) {
  634. popupOptions.shownAction = params.shownActionInPopup;
  635. popupOptions_floorplan.shownAction = params.shownActionInPopup;
  636. }
  637. viewModel = $.extend(viewModel, {
  638. gridView: gridView,
  639. dataModel: dataViewModel,
  640. dataSource: dataSource,
  641. refreshList: refreshList,
  642. viewShowing: handleViewShowing,
  643. // viewShown: handleViewShown,
  644. viewHidden: handleViewHidden,
  645. viewDisposing: handleViewDisposing,
  646. popupInsertView: popupInsertView,
  647. viewModeInPopup: viewModeInPopup,
  648. isEditModeInPopup: isEditModeInPopup,
  649. isNewInPopup: isNewInPopup,
  650. popupOptions: popupOptions,
  651. popupOptions_floorplan: popupOptions_floorplan,
  652. popupVisible: popupVisible,
  653. toolbarItems: toolbarItems,
  654. toolbarItems2: toolbarItems2,
  655. handlePopupButtonClose: handlePopupButtonClose,
  656. visibleEditButton: visibleEditButton,
  657. visibleDeleteButton: visibleDeleteButton,
  658. popupInsertButtonOptions: popupInsertButtonOptions,
  659. update: update
  660. });
  661. // 이 함수로 filter를 설정하면, SearchConditionView의 조건과 나중에 합산 된다.
  662. viewModel.setGridViewFilter = function (filter) {
  663. defaultFilter(filter);
  664. gridView().filter(filter);
  665. };
  666. // SearchConditionView에서 검색 버튼을 클릭하면 호출된다.
  667. viewModel.promiseSearchEvent.progress(function (filter) {
  668. gridView().filter(filter);
  669. });
  670. viewModel.handleExcelDownload = function () {
  671. };
  672. viewModel.handlePopupButtonEdit = handlePopupButtonEdit;
  673. return viewModel;
  674. };
  675. });