0ceeaeb7a7f82e9ba4b33b9a775f1ecb31719d21.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. BemsWebApplication.WorkCodeCauseClass = function( params, viewInfo ) {
  2. "use strict";
  3. var dbModelId = 'FmsWorkCodeCauseClass';
  4. var initialized = false,
  5. shouldReload = false,
  6. dataViewModel = new BemsWebApplication.FmsWorkCodeCauseClassViewModel(),
  7. isNewInPopup = ko.observable( false ),
  8. isEditModeInPopup = ko.observable( false ),
  9. isViewModeInPopup = ko.observable( true ),
  10. visibleCancelButton = ko.observable( false ),
  11. selectedIds = [ {}, {}, {} ],
  12. gridViews = [],
  13. popupVisible = ko.observable( false ),
  14. popupVisibles = [ ko.observable( false ), ko.observable( false ) ],
  15. buttonEditDisabledFlags = [ ko.observable( true ), ko.observable( true ) ],
  16. dataSources = [];
  17. var selectedClass = 0;
  18. var isClass2 = ko.observable( false );
  19. popupVisible.subscribe( function( visible ) {
  20. if( visible == false ) {
  21. //$.each( selectedIds[selectedClass] , function( name ) {
  22. // delete selectedIds[selectedClass][name];
  23. //});
  24. $.each( popupVisibles, function( i, item ) {
  25. item( false );
  26. } );
  27. }
  28. } );
  29. popupVisibles[0].subscribe( function( visible ) {
  30. selectedClass = 0;
  31. isClass2( false );
  32. if( visible ) popupVisible( visible );
  33. } );
  34. popupVisibles[1].subscribe( function( visible ) {
  35. selectedClass = 1;
  36. isClass2( true );
  37. if( visible ) popupVisible( visible );
  38. } );
  39. function handleModification() {
  40. shouldReload = true;
  41. }
  42. function handleSelectionChanged( selectedRowsInfo ) {
  43. var id = $(selectedRowsInfo.element).attr( 'id' );
  44. console.log( selectedRowsInfo.selectedRowKeys.length );
  45. switch( id ) {
  46. case 'gridContainer1':
  47. {
  48. buttonEditDisabledFlags[0]( selectedRowsInfo.selectedRowKeys.length == 0 );
  49. break;
  50. }
  51. case 'gridContainer2':
  52. {
  53. buttonEditDisabledFlags[1]( selectedRowsInfo.selectedRowKeys.length == 0 );
  54. break;
  55. }
  56. }
  57. console.log( selectedRowsInfo.selectedRowKeys );
  58. }
  59. function handleViewShown() {
  60. window.$SearchView.isNotUse(true); // hcLee 2015 03 06 common view에서 상속하지 않은 관계로 화면 전환될때 강제로 해줘야 한다.
  61. if(shouldReload) {
  62. shouldReload = false;
  63. for( var i = 0 ; i < 2 ; i++ ) {
  64. dataSources[i].pageIndex(0);
  65. dataSources[i].load();
  66. }
  67. }
  68. if ( initialized === false ) {
  69. for( var j = 0 ; j < 2 ; j++ ) {
  70. var options = j == 1 ? {
  71. columns: [
  72. { dataField: 'Name', caption: $G( 'className' ), width: '70%', alignment: 'center' },
  73. utils.datagrid.columnIsUse( '30%' )
  74. ],
  75. } : {
  76. columns: [
  77. { dataField: 'Number', caption: $G( 'number' ), width: '30%', alignment: 'center' },
  78. { dataField: 'Name', caption: $G( 'className' ), width: '70%', alignment: 'center' }
  79. ],
  80. useNumberColumn: true,
  81. };
  82. options.selectedSourceItem = dataViewModel;
  83. options.dbId = dbModelId;
  84. options.dxDataSource = dataSources[j];
  85. options.selectedId = selectedIds[j];
  86. options.datagridId = 'gridContainer' + (j + 1);
  87. options.selectionChanged = handleSelectionChanged;
  88. options.popupVisible = popupVisibles[j];
  89. options.handleDataGridRowClick = handleDataGridRowClick;
  90. var id = '#' + options.datagridId;
  91. $(id).dxDataGrid( utils.datagrid.defaultOptions( options ) );
  92. gridViews[j] = $(id).dxDataGrid('instance');
  93. }
  94. initialized = true;
  95. }
  96. $SideMenu.showSideMenuIfWill( params.view );
  97. }
  98. function refreshDataSource( dataIndex, parentId ) {
  99. dataSources[dataIndex].filter( 'ParentId', '=', parentId );
  100. dataSources[dataIndex].pageIndex( 0 );
  101. dataSources[dataIndex].load();
  102. gridViews[dataIndex].option( 'dataSource', utils.datagrid.dataSource( dataSources[dataIndex] ) );
  103. gridViews[dataIndex].refresh();
  104. }
  105. function handleDataGridRowClick( id, dataGrid, clickRow ) {
  106. switch( id ) {
  107. case 'gridContainer1':
  108. {
  109. refreshDataSource( 1, clickRow.data.CauseClassId() );
  110. break;
  111. }
  112. }
  113. }
  114. function handleViewDisposing() {
  115. BemsWebApplication.db[dbModelId].modified.remove(handleModification);
  116. }
  117. var dataSourceOptions = {
  118. store: BemsWebApplication.db[dbModelId] ,
  119. map: function( item ) {
  120. return new BemsWebApplication.FmsWorkCodeCauseClassViewModel( item );
  121. }
  122. };
  123. for( var k = 0 ; k < 2 ; k++ ) {
  124. dataSources[k] = new DevExpress.data.DataSource( dataSourceOptions );
  125. }
  126. dataSources[0].filter( [
  127. [ 'SiteId', '=', BWA.UserInfo.SiteId() ],
  128. 'and',
  129. [ 'ParentId', '=', 0 ]
  130. ] );
  131. dataSources[1].filter( 'ParentId', '=', -1 );
  132. function refreshList() {
  133. for( var i = 0 ; i < 2 ; i++ ) {
  134. dataSources[i].pageIndex(0);
  135. dataSources[i].load();
  136. gridViews[i].refresh();
  137. }
  138. }
  139. function handlePopupShowing( e )
  140. {
  141. visibleCancelButton( false );
  142. if( isNewInPopup() == false ) {
  143. activePopupViewMode();
  144. BemsWebApplication.db[dbModelId].byKey( selectedIds[selectedClass] ).done( function( data ) {
  145. dataViewModel.fromJS( data );
  146. } );
  147. }
  148. else {
  149. //activePopupInsertMode();
  150. clearDataModelValue( dataViewModel );
  151. }
  152. }
  153. function clearDataModelValue( v ) {
  154. $.each( v , function ( name , value ) {
  155. if( name !== 'ParentId' ) {
  156. v[name]( null );
  157. }
  158. });
  159. v.SiteId( BWA.UserInfo.SiteId() );
  160. console.log( v.ParentId() );
  161. }
  162. BemsWebApplication.db[dbModelId].modified.add( handleModification );
  163. function handleConfirmDelete() // hcLee 2015 03 06
  164. {
  165. //BemsWebApplication.db[dbModelId].remove(selectedIds[selectedClass]).done(function () {
  166. //alert(dataViewModel.SiteId());
  167. var classIdFieldName = ['CauseClassId'];
  168. //alert(classIdFieldName);
  169. var parameters = {
  170. SiteId: dataViewModel.SiteId(),
  171. //Depth: dataViewModel.Depth()
  172. };
  173. //classIdFieldName = [options.classId, 'ClassId'].join(''),
  174. parameters[classIdFieldName] = dataViewModel[classIdFieldName]();
  175. //alert(classIdFieldName + parameters[classIdFieldName]);
  176. BemsWebApplication.api.delete(dbModelId, parameters).done(function () {
  177. refreshList();
  178. popupVisible(false);
  179. utils.toast.show( '데이터베이스 항목 삭제 작업이 성공하였습니다.' );
  180. });
  181. }
  182. function update() {
  183. //console.log( dataViewModel.BuildingId() );
  184. BemsWebApplication.db[dbModelId].update( selectedIds[selectedClass], dataViewModel.toJS() ).done(function () {
  185. refreshList();
  186. utils.toast.show( '데이터베이스 항목 수정 작업이 성공하였습니다.' );
  187. // popupVisible( false );
  188. });
  189. }
  190. function insert()
  191. {
  192. BemsWebApplication.db[dbModelId].insert( dataViewModel.toJS() ).done(function ( values, newId ) {
  193. refreshList();
  194. popupVisible( false );
  195. });
  196. }
  197. function activePopupEditMode() {
  198. isViewModeInPopup( false );
  199. isEditModeInPopup( true );
  200. }
  201. function activePopupViewMode() {
  202. isViewModeInPopup( true );
  203. isEditModeInPopup( false );
  204. }
  205. function handlePopupButtonEdit() {
  206. activePopupEditMode();
  207. visibleCancelButton( true );
  208. }
  209. function handlePopupButtonCancel() {
  210. activePopupViewMode();
  211. visibleCancelButton( false );
  212. }
  213. function popupInsertView() {
  214. activePopupEditMode();
  215. popupVisible( true );
  216. }
  217. function handlePopupButtonSave() {
  218. if( isNewInPopup() )
  219. insert();
  220. else
  221. update();
  222. }
  223. function handlePopupButtonDelete()
  224. {
  225. DevExpress.ui.dialog.confirm( $G('deleteConfirmMsg') , "삭제").then( function( result ) {
  226. if ( result ) {
  227. handleConfirmDelete();
  228. refreshList();
  229. }
  230. else {
  231. // toast
  232. }
  233. });
  234. }
  235. function handlePopupButtonClose() {
  236. popupVisible( false );
  237. }
  238. var toolbarItems = [
  239. { location: 'before', text: $G('detailInfo') },
  240. { location: 'after', widget: 'button', options: { text: $G('edit'), icon: 'edit' , visible: isViewModeInPopup, clickAction: handlePopupButtonEdit } },
  241. { location: 'after', widget: 'button', options: { text: $G('delete'), type: 'danger', icon: 'remove', visible: isViewModeInPopup, clickAction: handlePopupButtonDelete } },
  242. { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', visible: isEditModeInPopup, clickAction: handlePopupButtonSave } },
  243. { location: 'after', widget: 'button', options: { text: $G('cancel'), icon: 'arrowleft', visible: visibleCancelButton , clickAction: handlePopupButtonCancel } } ,
  244. { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } }
  245. //{ location: 'right', widget: 'button', options: { text: '@edit', click: handleEdit } },
  246. //{ location: 'after', widget: 'button', options: { icon: 'find' } },
  247. //{ location: 'menu', text: 'Add' },
  248. //{ location: 'center', text: 'Products' }
  249. ];
  250. var popupOptions = {
  251. width: '480px',
  252. height: 'auto',
  253. visible: popupVisible,
  254. closeOnOutsideClick: true,
  255. showingAction: handlePopupShowing,
  256. animation: {
  257. show: { type: "pop", duration: 200 , from: { opacity: 1, scale: 0.4 }, to: { scale: 1 } },
  258. hide: { type: "fade", duration: 200, from: 1, to: 0 }
  259. }
  260. };
  261. function setInsertPopupInfo( index, classId ) {
  262. isNewInPopup( true );
  263. activePopupEditMode();
  264. dataViewModel.ParentId( classId );
  265. popupVisibles[index]( true );
  266. }
  267. return {
  268. dataModel: dataViewModel,
  269. refreshList: refreshList,
  270. buttonEditDisabledFlags: buttonEditDisabledFlags,
  271. //viewShowing: handleViewShowing ,
  272. viewShown: handleViewShown,
  273. viewDisposing: handleViewDisposing,
  274. popupInsertView: popupInsertView,
  275. isViewModeInPopup: isViewModeInPopup,
  276. isEditModeInPopup: isEditModeInPopup,
  277. isNewInPopup: isNewInPopup,
  278. popupOptions: popupOptions,
  279. toolbarItems: toolbarItems,
  280. isClass2: isClass2,
  281. buttonInsertClass1: function() {
  282. setInsertPopupInfo( 0, 0 );
  283. },
  284. buttonInsertClass2: function() {
  285. setInsertPopupInfo( 1, selectedIds[0].CauseClassId );
  286. },
  287. buttonEditClass1: function() {
  288. isNewInPopup( false );
  289. popupVisibles[0]( true );
  290. },
  291. buttonEditClass2: function() {
  292. isNewInPopup( false );
  293. popupVisibles[1]( true );
  294. },
  295. };
  296. };