aa1c84aac7cdb28c45b202a8e28f9653b4c8868f.svn-base 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. $UserSearchPopup = function (viewModel, selectUserData, isMultipleSelect, onSelectedUsers, datagridId) {
  2. //isMultipleSelect 추가 hcLee 2016 02 15
  3. var isMultipleSelect = isMultipleSelect;
  4. // 멀티선택기능 추가 hcLee2016 02 15
  5. //var onSelectedUsers = options.onSelectedUsers;
  6. var onSelectedUsers = onSelectedUsers;
  7. var datagridId = datagridId;
  8. var dataViewModel = new BemsWebApplication.CmUserViewModel(),
  9. gridView,
  10. popupVisible = ko.observable(false),
  11. dataSource;
  12. // _Name 작업을 original로 수정해야 한다.
  13. dataSource = BWA.DataUtil.createDataSource({
  14. dataSourceOptions: {
  15. select: [
  16. 'SiteId',
  17. 'CompanyId',
  18. 'DepartmentId',
  19. 'UserId',
  20. 'Name',
  21. 'EmploymentType',
  22. 'MobilePhoneNo',
  23. 'EmploymentStatus',
  24. 'CmPosition/Name',
  25. 'CmDepartment/Name',
  26. 'CmCompany/Name'],
  27. expand: ["CmPosition", "CmDepartment", "CmCompany"],
  28. //2016 09 27 hcLee
  29. filter: [
  30. //['SiteId', '=', 0] // 4
  31. //eq('SiteId', 0), // 초기화를 위해서 0
  32. ['SiteId', '=', BWA.UserInfo.SiteId()],
  33. ['EmploymentStatus', '=', 1],
  34. // ['FmsWorkRequest/WorkProgressId', '=', $Code.WorkProgress.WORKING] // 4
  35. // //, and, ['FmsWorkRequest/WorkProgressId', '<=', 5]
  36. ],
  37. extendOptions: {}
  38. }
  39. }, 'CmUser');
  40. var dataGridOptions = utils.datagrid.defaultOptions({
  41. dxDataSource: dataSource,
  42. selectedSourceItem: dataViewModel,
  43. datagridId: 'gridUserContainer',
  44. dbId: 'CmUser',
  45. useNumberColumn: true,
  46. columns: [
  47. { dataField: 'Number', caption: $G('number'), width: '10%', alignment: 'center', allowFiltering: false },
  48. { dataField: 'UserId', caption: $G('userId'), width: '15%', alignment: 'center' },
  49. { dataField: 'Name', caption: $G('userName'), width: '15%', alignment: 'center' },
  50. {
  51. dataField: 'EmploymentType',
  52. caption: $G('employmentType'),
  53. width: '15%',
  54. alignment: 'center',
  55. allowFiltering: false,
  56. customizeText: function (cellInfo) {
  57. return $Name($G.EmploymentTypeNames, cellInfo.value);
  58. }
  59. },
  60. {
  61. dataField: 'EmploymentStatus',
  62. caption: $G('employmentStatus'),
  63. width: '15%',
  64. alignment: 'center',
  65. allowFiltering: false,
  66. customizeText: function (cellInfo) {
  67. return $Name($G.EmploymentStatusNames, cellInfo.value);
  68. }
  69. },
  70. { dataField: 'CmDepartment/Name', caption: $G('departmentName'), width: '15%', alignment: 'center' }
  71. ],
  72. cellPrepared: function (cellElement, cellInfo) {
  73. if (cellInfo.rowType == 'data' && cellInfo.columnIndex == (isMultipleSelect ? 6 : 5)) {
  74. if (cellInfo.data.CmCompany_Name !== undefined && cellInfo.data.CmDepartment_Name !== undefined)
  75. $(cellElement).text(cellInfo.data.CmCompany_Name() + ' / ' + cellInfo.data.CmDepartment_Name());
  76. else if (cellInfo.data.CmCompany_Name !== undefined && cellInfo.data.CmDepartment_Name === undefined)
  77. $(cellElement).text(cellInfo.data.CmCompany_Name() + ' / ');
  78. else if (cellInfo.data.CmCompany_Name === undefined && cellInfo.data.CmDepartment_Name !== undefined)
  79. $(cellElement).text(' / ' + cellInfo.data.CmDepartment_Name());
  80. }
  81. },
  82. searchPanelPlaceHolder: '사용자 검색',
  83. paging: {
  84. pageSize: 11,
  85. enabled: true
  86. },
  87. pager: { visible: true }
  88. });
  89. if (isMultipleSelect) {
  90. dataGridOptions.selection = { mode: 'multiple', allowSelectAll: true };
  91. dataGridOptions.handleDataGridRowClick = function (id, dataGrid, clickRow) {
  92. /*
  93. var data = clickRow.data;
  94. if (!_.isUndefined(onSelectedUsers)) {
  95. onSelectedUsers([BWA.DataUtil.convertViewModelToJS(data)]);
  96. }*/
  97. };
  98. }
  99. else {
  100. dataGridOptions.handleDataGridRowClick = function (id, dataGrid, clickRow) {
  101. var data = clickRow.data;
  102. selectUserData({
  103. SiteId: data.SiteId(),
  104. UserId: data.UserId(),
  105. CompanyId: data.CompanyId(),
  106. DepartmentId: data.DepartmentId(),
  107. CompanyName: data.CmCompany_Name(),
  108. MobilePhoneNo: data.MobilePhoneNo(),
  109. Name: data.Name()
  110. });
  111. if (data.CmDepartment_Name !== undefined)
  112. selectUserData.DepartmentName = data.CmDepartment_Name();
  113. popupVisible(false);
  114. }
  115. }
  116. function handlePopupShowing(e) {
  117. //console.log( $( "#gridUserContainer" ) );
  118. //$( "#gridUserContainer" ).text( 'test' );
  119. //$( "#gridUserContainer" ).dxDataGrid( utils.datagrid.defaultOptions( {
  120. // dxDataSource: dataSource,
  121. // selectedSourceItem: dataViewModel,
  122. // selectedId: selectedId,
  123. // datagridId: 'gridUserContainer',
  124. // popupVisible: popupVisible,
  125. // dbId: 'CmUser',
  126. // useNumberColumn: true,
  127. // columns: [
  128. // { dataField: 'Number', caption: $G( 'number' ), width: '10%', alignment: 'center' },
  129. // { dataField: 'UserId', caption: $G( 'userId' ), width: '15%', alignment: 'center' },
  130. // { dataField: 'Name', caption: $G( 'userName' ), width: '15%', alignment: 'center' },
  131. // { dataField: 'EmploymentType', caption: $G( 'employmentType' ), width: '15%', alignment: 'center' ,
  132. // customizeText: function( cellInfo ) {
  133. // return $Name( $G.EmploymentTypes, cellInfo.value );
  134. // }
  135. // },
  136. // { dataField: 'EmploymentStatus', caption: $G( 'employmentStatus' ), width: '15%', alignment: 'center' ,
  137. // customizeText: function( cellInfo ) {
  138. // return $Name( $G.EmploymentStatus, cellInfo.value );
  139. // }
  140. // },
  141. // //{ dataField: 'CmCompany_Name', caption: $G( 'companyName' ), width: '15%', alignment: 'center' },
  142. // //{ dataField: 'CmDepartment_Name', caption: $G( 'affiliation' ), width: '15%', alignment: 'center' }
  143. // { caption: $G( 'affiliation' ), width: '15%', alignment: 'center' }
  144. // ],
  145. // cellPrepared: function( cellElement, cellInfo ) {
  146. // if( cellInfo.columnIndex == 5 ) {
  147. // //cellInfo.value = cellInfo.displayValue = cellInfo.rowIndex + 1;
  148. // //cellInfo.text = cellInfo.rowIndex + 1;
  149. // $( cellElement ).text( cellInfo.data.CmCompany_Name() + ' / ' + cellInfo.data.CmDepartment_Name() );
  150. // }
  151. // },
  152. // searchPanelPlaceHolder: '사용자 검색',
  153. //} ) );
  154. gridView = $('#gridUserContainer').dxDataGrid('instance');
  155. }
  156. function handlePopupShown() {
  157. }
  158. function handlePopupButtonSelect() {
  159. var array = utils.datagrid.getSelectedRowsData('gridUserContainer');
  160. if (!_.isUndefined(onSelectedUsers)) {
  161. onSelectedUsers(array);
  162. }
  163. $('#gridUserContainer').dxDataGrid('instance').clearSelection();
  164. popupVisible(false);
  165. }
  166. function handlePopupButtonClose() {
  167. $('#gridUserContainer').dxDataGrid('instance').clearSelection();
  168. popupVisible(false);
  169. }
  170. var toolbarItems = [
  171. { location: 'before', text: '찾기' },
  172. { location: 'after', widget: 'button', options: { text: $G('select'), icon: 'save', visible: isMultipleSelect, clickAction: handlePopupButtonSelect } },
  173. { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } }
  174. ];
  175. var popupOptions = {
  176. width: isMultipleSelect ? '800px' : '600px',
  177. height: 'auto',
  178. visible: popupVisible,
  179. closeOnOutsideClick: true,
  180. shading: false,
  181. showingAction: handlePopupShowing,
  182. shownAction: handlePopupShown,
  183. animation: {
  184. show: { type: "pop", duration: 200, from: { opacity: 1, scale: 0.4 }, to: { scale: 1 } },
  185. hide: { type: "fade", duration: 200, from: 1, to: 0 }
  186. }
  187. };
  188. return {
  189. dataModel: dataViewModel,
  190. dataSource: dataSource,
  191. popupOptions: popupOptions,
  192. toolbarItems: toolbarItems,
  193. dataGridOptions: dataGridOptions,
  194. show: function () {
  195. popupVisible(true);
  196. }
  197. };
  198. }