6322fecbf6498ea8c7165f856aa4362d180b5f72.svn-base 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. 
  2. BWA.UserInfo = {
  3. IsCenter: ko.observable(false),
  4. IsLogin: ko.observable(false),
  5. SiteId: ko.observable(),
  6. UserId: ko.observable(),
  7. Name: ko.observable(),
  8. CompanyId: ko.observable(),
  9. CompanyName: ko.observable(),
  10. DepartmentId: ko.observable(),
  11. DepartmentName: ko.observable(),
  12. UserGroupName: ko.observable(), // 2016 07 27
  13. PositionId: ko.observable(),
  14. PositionName: ko.observable(),
  15. BusinessFieldId: ko.observable(),
  16. BusinessFieldName: ko.observable(), // 변경될 수 있으니 프로필 같은 곳으로 가면 갱신하자
  17. MenuPermissions: ko.observableArray(),
  18. // hcLee 2018 02 23
  19. chartInfo: ko.observableArray(),
  20. };
  21. (function() {
  22. 'use strict';
  23. var PERMISSION_SEARCH = 1,
  24. PERMISSION_MODIFICATION = 2,
  25. PERMISSION_DEPEND_BUSINESS_FIELD = 4
  26. ;
  27. var userInfo = BWA.UserInfo;
  28. function handleHasPermissionFunc(permissionIndex) {
  29. return function(menuViewId) {
  30. if (this.isAdmin()) {
  31. // Admin 계정은 업무분야와 상관없다.
  32. if (permissionIndex === PERMISSION_DEPEND_BUSINESS_FIELD) {
  33. return false;
  34. }
  35. return true;
  36. }
  37. var menus = this.MenuPermissions();
  38. return _.some(menus, function(x) {
  39. var hasPermission = (x.MenuId === menuViewId) && ((x.MenuPermission & permissionIndex) > 0);
  40. // console.log('{0} : {1}, {2}, {3}'.formati(x.MenuId, menuViewId, x.MenuPermission, ((x.MenuPermission & permissionIndex) > 0)));
  41. return hasPermission;
  42. });
  43. }.bind(userInfo);
  44. }
  45. userInfo.hasPermissionOfSearch = handleHasPermissionFunc(PERMISSION_SEARCH);
  46. userInfo.hasPermissionOfModification = handleHasPermissionFunc(PERMISSION_MODIFICATION);
  47. userInfo.isDependBusinessField = handleHasPermissionFunc(PERMISSION_DEPEND_BUSINESS_FIELD);
  48. userInfo.isAdmin = function() {
  49. return this.UserId() === 'admin';
  50. }.bind(userInfo);
  51. // hcLee 2018 02 23
  52. userInfo.GetChartInfo = function (ftype, chartid) {
  53. /*
  54. _.each(this.chartInfo(), function (chart) {
  55. if (chart.FacilityTypeId() == ftype && chart.ChartId() == chartid) return chart;
  56. });
  57. return null;*/
  58. var chartinfos = this.chartInfo();
  59. for (var n = 0; n < chartinfos.length; n++) {
  60. if (chartinfos[n].FacilityTypeId() == ftype && chartinfos[n].ChartId() == chartid) return chartinfos[n];
  61. }
  62. return null;
  63. }.bind(userInfo);
  64. // hcLee 2018 02 26
  65. userInfo.GetChartInfo_Title = function (ftype, chartid) {
  66. /*
  67. _.each(this.chartInfo(), function (chart) {
  68. if (chart.FacilityTypeId() == ftype && chart.ChartId() == chartid) return chart.Title();
  69. });
  70. return '';*/
  71. var chartinfos = this.chartInfo();
  72. for (var n = 0; n < chartinfos.length; n++) {
  73. if (chartinfos[n].FacilityTypeId() == ftype && chartinfos[n].ChartId() == chartid) return chartinfos[n].Title();
  74. }
  75. return '';
  76. }.bind(userInfo);
  77. // hcLee 2018 02 27
  78. userInfo.GetChartInfo_Count = function (ftype) {
  79. var chartCount = 0;
  80. var chartinfos = this.chartInfo();
  81. for (var n = 0; n < maxLength; n++) {
  82. if (chartinfos[n].FacilityTypeId() == ftype)
  83. chartCount++;
  84. }
  85. return chartCount;
  86. }.bind(userInfo);
  87. userInfo.GetCharts = function (ftype) {
  88. var chartinfos = this.chartInfo();
  89. var charts = [];
  90. for (var n = 0; n < chartinfos.length; n++) {
  91. if (chartinfos[n].FacilityTypeId() == ftype)
  92. charts.push(chartinfos[n]);
  93. // hcLee 2018 04 23
  94. if (charts.length >= 17) return charts;
  95. }
  96. return charts;
  97. }.bind(userInfo);
  98. userInfo.logout = function() {
  99. this.IsCenter(false);
  100. this.IsLogin(false);
  101. this.SiteId(undefined);
  102. this.UserId(undefined);
  103. this.Name(undefined);
  104. this.CompanyId(undefined);
  105. this.CompanyName(undefined);
  106. this.BusinessFieldId(undefined);
  107. this.BusinessFieldName(undefined);
  108. this.DepartmentId(undefined);
  109. this.DepartmentName(undefined);
  110. this.UserGroupName(undefined);
  111. this.PositionId(undefined);
  112. this.PositionName(undefined);
  113. this.MenuPermissions(undefined);
  114. // hcLee 2018 02 23
  115. this.chartInfo(undefined);
  116. }.bind(userInfo);
  117. })();