Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.24 KB | None | 0 0
  1. <div class="row">
  2. <div class="col-sm-4 pull-right">
  3. <div class="form-group" ng-if="isShowDropdown">
  4. <select id="ddlStates" class="form-control" ng-disabled="readOnly || isFormISO"
  5. ng-model="lobStateSelected" ng-change="addNewLob(lobStateSelected,this)" ng-options="lb.LobValue for lb in originalLobData">
  6. <option value="">{{::languageStrings.lbl_AddanewLOB}}</option>
  7. </select>
  8. </div>
  9. </div>
  10. </div>
  11.  
  12. <div class="row" ng-repeat="lobItem in lobStateItemData track by $index">
  13. <div ng-show="lobItem.LobId" class="col-md-12 sa-state-container">
  14. <h4><span>{{lobItem.LobValue}}</span> <a href="" ng-click="removeLobIfo(lobItem)" class="link" ng-hide="readOnly || isFormISO">{{::languageStrings.lbl_RemovethisLOB}}<span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a> </h4>
  15. <div class="row">
  16. <div class="col-md-12">
  17. <table class="table-theme-one">
  18. <thead>
  19. <tr>
  20. <th valign="top" class="col-sm-4 required"><label for=""><span ng-if="formStatusId === 'X'">*</span>{{::languageStrings.lbl_State}}</label></th>
  21. <th valign="top" class="col-sm-3 required"><label for=""><span ng-if="formStatusId === 'X'">*</span>{{::languageStrings.lbl_EffectiveDate}}</label></th>
  22. <th valign="top" class="col-sm-3"><label for="">{{::languageStrings.lbl_WithdrawnDate}}</label></th>
  23. <th ng-if="!readOnly" valign="top" class="col-sm-2"></th>
  24. </tr>
  25. <tr>
  26. <th valign="top" class="col-sm-4" ng-class="{'has-error':stateInvalid{{$index}}}">
  27. <div class="btn-group btn-block btn-group-sm">
  28. <vm-multi-select multi-select-control="stateMultiSelect" options="lobItem.StateData.stateList" selected-model="lobItem.selectedStates" events="formEvents" checkboxes="true" extra-settings="settings" translation-texts="translationTexts" disable="readOnly || isFormISO">
  29. </vm-multi-select>
  30. </div>
  31. <p ng-show="stateInvalid{{$index}}">{{::languageStrings.lbl_State_is_required}}</p>
  32. </th>
  33. <th valign="top" class="col-sm-3" ng-class="{'has-error':effectiveDateInvalid{{$index}}}">
  34. <div class="input-group date">
  35. <input type="text" readonly class="timeselect form-control input-sm" placeholder="{{dateFormat | lowercase}}" ng-change="effectiveChanged({{$index}}, lobItem.StateData)"
  36. data-show-weeks="false" show-button-bar="false" uib-datepicker-popup='{{dateFormat}}' datepicker-localdate datepicker-append-to-body="true" ng-model="lobItem.StateData.EffectiveDate" id="dateCustomeFive" is-open="openedInterLineEffectiveDate$index"
  37. close-text="Close" />
  38. <span class="input-group-btn">
  39. <button type="button" class="btn btn-default input-sm" ng-disabled="readOnly || isFormISO" ng-click="openedInterLineEffectiveDate$index = !openedInterLineEffectiveDate$index"><i class="glyphicon glyphicon-calendar"></i></button>
  40. </span>
  41. </div>
  42. <p ng-show="effectiveDateInvalid{{$index}}">{{::languageStrings.lbl_EffectiveDate_is_required}}</p>
  43. </th>
  44. <th valign="top" class="col-sm-3">
  45. <div class="input-group date">
  46. <input type="text" readonly class="timeselect form-control input-sm" placeholder="{{dateFormat | lowercase}}" datepicker-options="lobItem.StateData.dateOptions"
  47. data-show-weeks="false" show-button-bar="false" uib-datepicker-popup='{{dateFormat}}' datepicker-localdate datepicker-append-to-body="true" ng-model="lobItem.StateData.WithdrawnDate" is-open="openedInterLineWithDrawnDate$index"
  48. close-text="Close" />
  49. <span class="input-group-btn">
  50. <button type="button" class="btn btn-default input-sm" ng-disabled="readOnly || isFormISO" ng-click="openedInterLineWithDrawnDate$index = !openedInterLineWithDrawnDate$index"><i class="glyphicon glyphicon-calendar"></i></button>
  51. </span>
  52. </div>
  53. </th>
  54. <th valign="top" class="col-sm-2"><button id="btnAddStates" class="btn btn-primary btn-sm " value="Add" ng-click="addStateInfo(lobItem.StateData,lobItem.StateData.showLobState)" ng-disabled="readOnly || isFormISO">{{::languageStrings.lbl_Add}}</button></th>
  55. </tr>
  56. </thead>
  57. <tbody>
  58. <tr ng-repeat="state in lobItem.StateItemData | orderBy : 'StateName'">
  59. <td><span>{{state.StateName}}</span></td>
  60. <td valign="top">
  61. <div class="input-group date">
  62. <input type="text" readonly class="timeselect form-control input-sm" placeholder="{{dateFormat | lowercase}}" ng-change="effectiveChanged({{$index}}, state)"
  63. data-show-weeks="false" show-button-bar="false" uib-datepicker-popup='{{dateFormat}}' datepicker-localdate datepicker-append-to-body="true" ng-model="state.EffectiveDate" is-open="openedEffectiveDate$index"
  64. close-text="Close" />
  65. <span class="input-group-btn">
  66. <button type="button" class="btn btn-default input-sm" ng-disabled="readOnly || isFormISO" ng-click="openedEffectiveDate$index = !openedEffectiveDate$index"><i class="glyphicon glyphicon-calendar"></i></button>
  67. </span>
  68. </div>
  69. </td>
  70. <td valign="top">
  71. <div class="input-group date">
  72. <input type="text" readonly class="timeselect form-control input-sm" placeholder="{{dateFormat | lowercase}}" datepicker-options="state.dateOptions"
  73. data-show-weeks="false" show-button-bar="false" uib-datepicker-popup='{{dateFormat}}' datepicker-localdate datepicker-append-to-body="true" ng-model="state.WithdrawnDate" is-open="openedWithdrawnDate$index"
  74. close-text="Close" />
  75. <span class="input-group-btn" ng-init="state.dateOptions.minDate = state.EffectiveDate">
  76. <button type="button" class="btn btn-default input-sm" ng-disabled="readOnly || isFormISO" ng-click="openedWithdrawnDate$index = !openedWithdrawnDate$index"><i class="glyphicon glyphicon-calendar"></i></button>
  77. </span>
  78. </div>
  79. </td>
  80. <td valign="top">
  81. <a href="" name="Remove" value="remove" ng-click="removeStateInfo(state)" ng-if="!readOnly && !isFormISO">{{::languageStrings.lbl_Remove}}</a>
  82. <span ng-if="readOnly || isFormISO">{{::languageStrings.lbl_Remove}}</span>
  83. </td>
  84. </tr>
  85. </tbody>
  86. </table>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91.  
  92. <div ng-show="selectedLOB">
  93. <h4><span>{{selectedLOB}}</span></h4>
  94. <div class="row">
  95. <div class="col-md-12">
  96. <table class="table-theme-one">
  97. <thead>
  98. <tr>
  99. <th valign="top" class="col-sm-4 required" ng-class="{'has-error':stateInvalid0}"><label for=""><span ng-if="formStatusId == 2">*</span>{{::languageStrings.lbl_State}}</label></th>
  100. <th valign="top" class="col-sm-3 required" ng-class="{'has-error':effectiveDateInvalid0}"><label for=""><span ng-if="formStatusId == 2">*</span>{{::languageStrings.lbl_EffectiveDate}}</label></th>
  101. <th valign="top" class="col-sm-3"><label>{{::languageStrings.lbl_WithdrawnDate}}</label></th>
  102. <th valign="top" class="col-sm-2"></th>
  103. </tr>
  104. <tr>
  105. <th valign="top" class="col-sm-4" ng-class="{'has-error':stateInvalid0}">
  106. <div class="btn-group btn-block btn-group-sm">
  107. <vm-multi-select multi-select-control="stateMultiSelect" options="stateList" selected-model="selectedStates" events="formEvents" checkboxes="true" extra-settings="settings" translation-texts="translationTexts" disable="readOnly || isFormISO">
  108. </vm-multi-select>
  109. </div>
  110. <p ng-show="stateInvalid0">{{::languageStrings.lbl_State_is_required}}</p>
  111. </th>
  112. <th valign="top" class="col-sm-3" ng-class="{'has-error':effectiveDateInvalid0}">
  113. <div class="input-group date" id="datetimepicker1">
  114. <input type="text" readonly class="timeselect form-control input-sm" placeholder="{{dateFormat | lowercase}}" ng-change="effectiveChanged(-1, stateObj)"
  115. data-show-weeks="false" show-button-bar="false" uib-datepicker-popup='{{dateFormat}}' datepicker-localdate datepicker-append-to-body="true" ng-model="stateObj.EffectiveDate" is-open="status.openedEffectiveDate"
  116. close-text="Close" />
  117. <span class="input-group-btn">
  118. <button type="button" class="btn btn-default input-sm" ng-disabled="readOnly || isFormISO" ng-click="status.openedEffectiveDate = !status.openedEffectiveDate"><i class="glyphicon glyphicon-calendar"></i></button>
  119. </span>
  120. </div>
  121. <p ng-show="effectiveDateInvalid0">{{::languageStrings.lbl_EffectiveDate_is_required}}</p>
  122. </th>
  123. <th valign="top" class="col-sm-3">
  124. <div class="input-group date" id="datetimepicker1">
  125. <input type="text" readonly class="timeselect form-control input-sm" placeholder="{{dateFormat | lowercase}}" datepicker-options="stateObj.dateOptions"
  126. data-show-weeks="false" show-button-bar="false" uib-datepicker-popup='{{dateFormat}}' datepicker-localdate datepicker-append-to-body="true" ng-model="stateObj.WithdrawnDate" is-open="status.openedWithdrawnDate"
  127. close-text="Close" />
  128. <span class="input-group-btn">
  129. <button type="button" class="btn btn-default input-sm" ng-disabled="readOnly || isFormISO" ng-click="status.openedWithdrawnDate = !status.openedWithdrawnDate"><i class="glyphicon glyphicon-calendar"></i></button>
  130. </span>
  131. </div>
  132. </th>
  133. <th valign="top" class="col-sm-2"><button id="btnAddStates" class="btn btn-primary btn-sm" value="Add" ng-click="addStateInfo(stateObj,selectedLOBId)" ng-disabled="readOnly || isFormISO">{{::languageStrings.lbl_Add}}</button></th>
  134. </tr>
  135. </thead>
  136. <tbody>
  137. <tr ng-repeat="stateItem in stateData | orderBy : 'StateName'">
  138. <td><span>{{stateItem.StateName}}</span></td>
  139. <td valign="top">
  140. <div class="input-group date">
  141. <input type="text" readonly class="timeselect form-control input-sm" placeholder="{{dateFormat | lowercase}}" ng-change="effectiveChanged({{$index}}, stateItem)"
  142. data-show-weeks="false" show-button-bar="false" uib-datepicker-popup='{{dateFormat}}' datepicker-localdate datepicker-append-to-body="true" ng-model="stateItem.EffectiveDate" is-open="openedEffectiveDate"
  143. close-text="Close" />
  144. <span class="input-group-btn">
  145. <button type="button" class="btn btn-default input-sm" ng-disabled="readOnly || isFormISO" ng-click="openedEffectiveDate = !openedEffectiveDate"><i class="glyphicon glyphicon-calendar"></i></button>
  146. </span>
  147. </div>
  148. </td>
  149. <td valign="top">
  150. <div class="input-group date">
  151. <input type="text" readonly class="timeselect form-control input-sm" placeholder="{{dateFormat | lowercase}}" datepicker-options="stateItem.dateOptions"
  152. data-show-weeks="false" show-button-bar="false" uib-datepicker-popup='{{dateFormat}}' datepicker-localdate datepicker-append-to-body="true" ng-model="stateItem.WithdrawnDate" is-open="openedWithdrawnDate"
  153. close-text="Close" />
  154. <span class="input-group-btn" ng-init="stateItem.dateOptions.minDate = stateItem.EffectiveDate">
  155. <button type="button" class="btn btn-default input-sm" ng-disabled="readOnly || isFormISO" ng-click="openedWithdrawnDate = !openedWithdrawnDate"><i class="glyphicon glyphicon-calendar"></i></button>
  156. </span>
  157. </div>
  158. </td>
  159. <td valign="top">
  160. <a href="" name="Remove" value="remove" ng-click="removeStateInfo(stateItem)" ng-if="!readOnly && !isFormISO">{{::languageStrings.lbl_Remove}}</a>
  161. <span ng-if="readOnly || isFormISO">{{::languageStrings.lbl_Remove}}</span>
  162. </td>
  163. </tr>
  164. </tbody>
  165. </table>
  166. </div>
  167. </div>
  168. </div>
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176. // <copyright file="stateApplicability.js" company="Verisk">
  177. // Copyright 2015
  178. // </copyright>
  179. // <summary>
  180. // State Applicability Controller
  181. // </summary>
  182.  
  183. /// <summary>
  184. // stateApplicabilityDirectiveCtrl
  185. /// </summary>
  186. /// <param name="$scope">The $scope.</param>
  187. /// <param name="$vmModal">The $VM modal.</param>
  188. /// <param name="vmConfig">The vm configuration.</param>
  189. /// <param name="$filter">The $filter.</param>
  190. app.controller('stateApplicabilityDirectiveCtrl', ['$scope', '$vmModal', 'vmConfig', '$filter', '$rootScope', function ($scope, $vmModal, vmConfig, $filter, $rootScope) {
  191. //$scope.dateOptions =[];
  192. //$scope.singleDateOptions = { };
  193. /// <summary>
  194. // effectiveChanged
  195. /// </summary>
  196. /// <param name="idx">The index.</param>
  197. /// <param name="val">The value.</param>
  198. $scope.effectiveChanged = function (idx, stateData) {
  199. // $scope.stateData = $filter('orderBy')($scope.stateData, 'StateName');
  200. // if (idx === -1) {
  201. //$scope.singleDateOptions.minDate = val;
  202. stateData.dateOptions = {
  203. minDate: stateData.EffectiveDate
  204. };
  205. console.log('stateData', stateData, stateData.EffectiveDate);
  206. if (stateData.WithdrawnDate && stateData.EffectiveDate > stateData.WithdrawnDate) {
  207. stateData.WithdrawnDate = null;
  208. }
  209. // } else {
  210. // $scope.stateData[idx].dateOptions = {
  211. // minDate: val
  212. // };
  213. //$scope.dateOptions[idx].minDate = val;
  214. //if ($scope.stateData[idx] && $scope.stateData[idx].WithdrawnDate && new Date(val).getTime() > new Date($scope.stateData[idx].WithdrawnDate).getTime()) {
  215. // $scope.stateData[idx].WithdrawnDate = null;
  216. //}
  217. // }
  218. if (idx >= 0) {
  219. $scope['effectiveDateInvalid' + idx] = false;
  220. }
  221. //idx = idx === -1 ? 0 : idx;
  222. //$scope['effectiveDateInvalid' + idx] = false;
  223. };
  224. $scope.languageStrings = vmConfig.languageStrings;
  225. var stateApplicability = $scope.stateApplicabilityControl,
  226. stateMultiSelect;
  227. $scope.stateMultiSelect = stateMultiSelect = {};
  228. /// <summary>
  229. // clear states
  230. /// </summary>
  231. stateApplicability.clearStates = function () {
  232. stateMultiSelect.clearAllSelection();
  233. };
  234. $scope.settings = {
  235. idProp: 'StateCode',
  236. displayProp: 'StateName',
  237. externalIdProp: ''
  238. };
  239. $scope.translationTexts = {
  240. dynamicButtonTextSuffix: 'State(s) selected',
  241. buttonDefaultText: 'Select'
  242. };
  243. $scope.formEvents = {
  244. /// <summary>
  245. // onItemSelect
  246. /// </summary>
  247. /// <param name="item">The item.</param>
  248. onItemSelect: function (item) {
  249. var lobId = item.lobId === undefined ? $scope.selectedLOBId : item.lobId;
  250. item.LobId = lobId;
  251. $scope.selectedOptions = $scope.selectedStates;
  252. var noOfLobs = $scope.lobStateItemData.length || $scope.selectedOptions.length;
  253. for (var idx = 0; idx < noOfLobs; ++idx) {
  254. if ($scope['stateInvalid' + idx]) {
  255. $scope['stateInvalid' + idx] = false;
  256. }
  257. }
  258. },
  259. /// <summary>
  260. // onItemDeselect
  261. /// </summary>
  262. /// <param name="item">The item.</param>
  263. /// <returns>broad casts selectedStateChanges</returns>
  264. onItemDeselect: function (item) {
  265. var lobId = item.lobId === undefined ? $scope.selectedLOBId : item.lobId;
  266. for (var stateIndex = 0; stateIndex < $scope.stateData.length; stateIndex++) {
  267. if ($scope.stateData[stateIndex].StateId === item.StateCode) {
  268. $scope.stateData.splice(stateIndex, 1);
  269. }
  270. }
  271. for (var lobIndex = 0; lobIndex < $scope.lobStateItemData.length; lobIndex++) {
  272. if (($scope.lobStateItemData[lobIndex].LobId === lobId) && ($scope.lobStateItemData[lobIndex].StateItemData !== undefined)) {
  273. for (var j = 0; j < $scope.lobStateItemData[lobIndex].StateItemData.length; j++) {
  274. if ($scope.lobStateItemData[lobIndex].StateItemData[j].StateId === item.StateCode) {
  275. $scope.lobStateItemData[lobIndex].StateItemData.splice(j, 1);
  276. }
  277. }
  278. }
  279. }
  280. $scope.selectedOptions = $scope.selectedStates;
  281. $rootScope.$broadcast('selectedStateChanges', { data: $scope.lobStateItemData.length > 0 ? $scope.lobStateItemData : $scope.stateData });
  282. }
  283. };
  284. /// <summary>
  285. // triggers on validateStateInfo
  286. /// </summary>
  287. /// <param name="event">The event.</param>
  288. /// <param name="args">The arguments.</param>
  289. $scope.$on('validateStateInfo', function (event, args) {
  290. if (args.data.length === 0) {
  291. $scope.stateInvalid0 = true;
  292. $scope.effectiveDateInvalid0 = true;
  293. }
  294. });
  295. }]);
  296. /// <summary>
  297. // stateApplicability directive
  298. /// </summary>
  299. /// <param name="$rootScope">The $root scope.</param>
  300. /// <param name="$vmModal">The $VM modal.</param>
  301. /// <param name="vmConfig">The vm configuration.</param>
  302. /// <param name="roleAccessService">The role access service.</param>
  303. /// <returns>directive</returns>
  304. app.directive('stateApplicability', ['$rootScope', '$vmModal', 'vmConfig', 'roleAccessService', 'viewFormService', function ($rootScope, $vmModal, vmConfig, roleAccessService, viewFormService) {
  305. var directive = {};
  306. directive.restrict = 'E';
  307. directive.require = 'ngModel';
  308. directive.$scope = {
  309. ngModel: '=',
  310. stateData: '=',
  311. statesList: '=',
  312. formInfo: '=',
  313. stateApplicabilityControl: '='
  314. };
  315. directive.templateUrl = '/Content/templates/StateApplicabilityTemp.tmpl.html';
  316. directive.controller = 'stateApplicabilityDirectiveCtrl';
  317.  
  318. /// <summary>
  319. // directive link
  320. /// </summary>
  321. /// <param name="$scope">The $scope.</param>
  322. directive.link = function ($scope) {
  323. $scope.lobStateItemData = [];
  324. $scope.selectedStates = [];
  325. $scope.interLineStateData = [];
  326. $scope.lobStateItemData.StateItemData = [];
  327. $scope.dateFormat = vmConfig.dateFormat;
  328. /// <summary>
  329. // getAllModules
  330. /// </summary>
  331. /// <param name="accessModulesData">The access modules data.</param>
  332. /// <returns>sets scope variable</returns>
  333. roleAccessService.isUserISOTenant(function (isIsoTenant) {
  334. $scope.isIsoTenant = isIsoTenant;
  335. roleAccessService.getAllModules(function (accessModulesData) {
  336. var auditAccessModule = _.findWhere(accessModulesData, { 'Module': 'EditMetaData', Function: 'StateApplicability' });
  337. if (auditAccessModule || ($scope.isIsoTenant && viewFormService.getFormIdentifier().FormStatusId === 'P')) {
  338. $scope.readOnly = false;
  339. } else {
  340. $scope.readOnly = true;
  341. }
  342. });
  343. });
  344. /// <summary>
  345. // triggers when applyViewStateInfo
  346. /// </summary>
  347. /// <param name="event">The event.</param>
  348. /// <param name="args">The arguments.</param>
  349. /// <returns>broad casts selected states</returns>
  350. $scope.$on('applyViewStateInfo', function (event, args) {
  351. if (args.generalInfo !== undefined && args.lobStates.length !== 0) {
  352. $scope.setViewState(args.generalInfo.Library);
  353. var lobStatesInfo = [];
  354. if (args.generalInfo.GeneralLOBId === 'IL') {
  355. for (var stateIndex = 0; stateIndex < args.stateInfo.length; stateIndex++) {
  356. for (var lobIndex = 0; lobIndex < args.lobStates.length; lobIndex++) {
  357. if (args.stateInfo[stateIndex].LobId === args.lobStates[lobIndex].LobId) {
  358. lobStatesInfo.push({
  359. LobId: args.lobStates[lobIndex].LobId,
  360. LobValue: args.lobStates[lobIndex].LobValue
  361. });
  362. }
  363. }
  364. }
  365. if (args.stateInfo.length !== 0) {
  366. /// <summary>
  367. // lobStatesInfo
  368. /// </summary>
  369. /// <param name="item">The item.</param>
  370. /// <returns>LobId array</returns>
  371. lobStatesInfo = _.uniq(lobStatesInfo, function (item) {
  372. return item.LobId;
  373. });
  374. var sortedLobStatesInfo = _.sortBy(lobStatesInfo, 'LobId');
  375. $scope.originalLobData = args.lobStates;
  376. for (var lobStateDataIndex = 0; lobStateDataIndex < $scope.originalLobData.length; lobStateDataIndex++) {
  377. for (var lobStatesInfoIndex = 0; lobStatesInfoIndex < sortedLobStatesInfo.length; lobStatesInfoIndex++) {
  378. if (sortedLobStatesInfo[lobStatesInfoIndex].LobId === $scope.originalLobData[lobStateDataIndex].LobId) {
  379. $scope.originalLobData.splice(lobStateDataIndex, 1);
  380. }
  381. }
  382. }
  383. $scope.lobStateItemData = sortedLobStatesInfo;
  384. } else {
  385. $scope.originalLobData = args.lobStates;
  386. }
  387. }
  388. for (var lobStateItemDataIndex = 0; lobStateItemDataIndex < $scope.lobStateItemData.length; lobStateItemDataIndex++) {
  389. $scope.lobStateItemData[lobStateItemDataIndex].selectedStates = [];
  390. var interLineStates = angular.copy(args.stateList);
  391. /// <summary>
  392. // fills selectedStates
  393. /// </summary>
  394. /// <param name="stateItem">The state item.</param>
  395. angular.forEach(interLineStates, function (stateItem) {
  396. for (var stateInfoIndex = 0; stateInfoIndex < args.stateInfo.length; stateInfoIndex++) {
  397. if (args.stateInfo[stateInfoIndex].StateId === stateItem.StateCode && $scope.lobStateItemData[lobStateItemDataIndex].LobId === args.stateInfo[stateInfoIndex].LobId) {
  398. stateItem.lobId = args.stateInfo[stateInfoIndex].LobId;
  399. $scope.lobStateItemData[lobStateItemDataIndex].selectedStates.push(stateItem);
  400. break;
  401. }
  402. }
  403. });
  404. $scope.lobStateItemData[lobStateItemDataIndex].StateData = { stateList: interLineStates, EffectiveDate: '', WithdrawnDate: '' };
  405. $scope.lobStateItemData[lobStateItemDataIndex].StateItemData = [];
  406. var sortedLobStates = _.sortBy(lobStatesInfo, 'LobId');
  407. if (sortedLobStates.length > 0) {
  408. $scope.lobStateItemData[lobStateItemDataIndex].StateData.showLobState = sortedLobStates[lobStateItemDataIndex].LobId;
  409. $scope.lobStateItemData[lobStateItemDataIndex].StateData.showLobStateName = sortedLobStates[lobStateItemDataIndex].LobValue;
  410. }
  411. }
  412. var selectedStates = [];
  413. /// <summary>
  414. // fills selectedStates
  415. /// </summary>
  416. /// <param name="stateItem">The state item.</param>
  417. angular.forEach(args.stateList, function (stateItem) {
  418. for (var stateDataIndex = 0; stateDataIndex < args.stateInfo.length; stateDataIndex++) {
  419. if (args.stateInfo[stateDataIndex].StateId === stateItem.StateCode) {
  420. selectedStates.push(stateItem);
  421. }
  422. }
  423. });
  424. $scope.selectedStates = selectedStates;
  425. for (var i = 0; i < $scope.lobStateItemData.length; i++) {
  426. for (var j = 0; j < args.stateInfo.length; j++) {
  427. if (args.stateInfo[j].LobId === $scope.lobStateItemData[i].LobId) {
  428. $scope.lobStateItemData[i].StateItemData.push(args.stateInfo[j]);
  429. }
  430. }
  431. }
  432. $rootScope.$broadcast('selectedStateChanges', { data: $scope.lobStateItemData.length > 0 ? $scope.lobStateItemData : $scope.stateData });
  433. }
  434. });
  435.  
  436.  
  437. /// <summary>
  438. // setViewState
  439. /// </summary>
  440. /// <param name="library">The library.</param>
  441. /// <returns>sets scope variables</returns>
  442. $scope.setViewState = function (library) {
  443. $scope.isFormISO = false;
  444. if (library === 'ISO') {
  445. $scope.isFormISO = true;
  446. }
  447. };
  448.  
  449. /// <summary>
  450. // Add new lob
  451. /// </summary>
  452. /// <param name="selectedData">The selected data.</param>
  453. /// <param name="stateData">The state data.</param>
  454. $scope.addNewLob = function (selectedData, stateData) {
  455. if (selectedData != null) {
  456. $scope.selectedStates = [];
  457. stateData.lobStateSelected.selectedStates = [];
  458. stateData.lobStateSelected.StateItemData = [];
  459. if (stateData.lobStateSelected.StateData) {
  460. stateData.lobStateSelected.StateData.EffectiveDate = null;
  461. stateData.lobStateSelected.StateData.WithdrawnDate = null;
  462. }
  463. var stateTempList = angular.copy($scope.stateList);
  464. /// <summary>
  465. // foreach item in stateTempList sets selectedData lobid
  466. /// </summary>
  467. /// <param name="item">The item.</param>
  468. /// <returns></returns>
  469. angular.forEach(stateTempList, function (item) {
  470. item.lobId = selectedData.LobId;
  471. });
  472. $scope.originalLobData.splice(stateData.originalLobData.indexOf(selectedData), 1);
  473. $scope.lobStateItemData.push(selectedData);
  474. for (var i = 0; i < $scope.lobStateItemData.length; i++) {
  475. if ($scope.lobStateItemData[i].selectedStates) {
  476. $scope.lobStateItemData[i].selectedStates = $scope.lobStateItemData[i].selectedStates;
  477. } else {
  478. $scope.lobStateItemData[i].selectedStates = [];
  479. }
  480. if ($scope.lobStateItemData[i].StateData === undefined) {
  481. $scope.lobStateItemData[i].StateData = { stateList: stateTempList, EffectiveDate: '', WithdrawnDate: '', showLobState: selectedData.LobId, showLobStateName: selectedData.LobValue };
  482. }
  483. }
  484. }
  485. };
  486.  
  487. /// <summary>
  488. // removeLobIfo
  489. /// </summary>
  490. /// <param name="data">The data.</param>
  491. /// <returns>broad casts selectedStateChanges </returns>
  492. $scope.removeLobIfo = function (data) {
  493. if (data) {
  494. data.StateItemData = [];
  495. data.selectedStates = [];
  496. data.StateData.EffectiveDate = null;
  497. data.StateData.WithdrawnDate = null;
  498. }
  499. $scope.lobStateItemData.splice($scope.lobStateItemData.indexOf(data), 1);
  500. $scope.originalLobData.push(data);
  501. $rootScope.$broadcast('selectedStateChanges', { data: $scope.lobStateItemData });
  502. };
  503.  
  504. /// <summary>
  505. // checkStatesSelected
  506. /// </summary>
  507. /// <returns> boolean </returns>
  508. $scope.checkStatesSelected = function () {
  509. return $scope.selectedStates.length > 0 ? true : ($scope.selectedStates.length === 0 ? false : true);
  510. };
  511.  
  512. /// <summary>
  513. // Add state information
  514. /// </summary>
  515. /// <param name="data">The data.</param>
  516. /// <param name="lobId">The lob identifier.</param>
  517. /// <returns>broad casts selectedStateChanges</returns>
  518. $scope.addStateInfo = function (data, lobId) {
  519. var effectiveDate,
  520. stateIndex,
  521. withdrawnDate;
  522. var interlineStateCount = 0;
  523. /// <summary>
  524. // foreach item in lobStateItemData sets variables
  525. /// </summary>
  526. /// <param name="item">The item.</param>
  527. /// <param name="idx">The index.</param>
  528. /// <returns>sets scope variables</returns>
  529. angular.forEach($scope.lobStateItemData, function (item, idx) {
  530. if (item.LobId === lobId) {
  531. interlineStateCount = item.selectedStates.length;
  532. stateIndex = idx;
  533. }
  534. });
  535. stateIndex = stateIndex || 0;
  536. $scope['stateInvalid' + stateIndex] = false;
  537. $scope['effectiveDateInvalid' + stateIndex] = false;
  538. if ($scope.selectedLOBId !== 'IL') {
  539. if ($scope.selectedStates.length === 0) {
  540. $scope['stateInvalid' + stateIndex] = true;
  541. return;
  542. }
  543. } else {
  544. if ($scope.selectedLOBId === 'IL' && interlineStateCount === 0) {
  545. $scope['stateInvalid' + stateIndex] = true;
  546. return;
  547. }
  548. }
  549. if (data) {
  550. effectiveDate = data.EffectiveDate;
  551. withdrawnDate = data.WithdrawnDate;
  552. } else {
  553. if ($scope.stateObj) {
  554. effectiveDate = $scope.stateObj.EffectiveDate;
  555. withdrawnDate = $scope.stateObj.WithdrawnDate;
  556. } else {
  557. $scope['effectiveDateInvalid' + stateIndex] = true;
  558. return;
  559. }
  560. }
  561.  
  562. withdrawnDate = withdrawnDate === null ? '' : withdrawnDate;
  563. if (!effectiveDate || effectiveDate === '' || (withdrawnDate !== '' && new Date(withdrawnDate) < new Date(effectiveDate))) {
  564. $scope['effectiveDateInvalid' + stateIndex] = true;
  565. } else {
  566. console.log('stateIndex', stateIndex);
  567. $scope.addStateAfterValidation(data, lobId);
  568. }
  569. $rootScope.$broadcast('selectedStateChanges', { data: $scope.lobStateItemData.length > 0 ? $scope.lobStateItemData : $scope.stateData });
  570. };
  571.  
  572. /// <summary>
  573. // Add state
  574. /// </summary>
  575. /// <param name="data">The data.</param>
  576. /// <param name="lobId">The lob identifier.</param>
  577. /// <returns>sets scope variables</returns>
  578. $scope.addStateAfterValidation = function (data, lobId) {
  579. console.log('addStateAfterValidation', lobId, data);
  580. for (var stateIndex = 0; stateIndex < $scope.selectedStates.length; stateIndex++) {
  581. if ($scope.selectedStates[stateIndex].LobId === lobId) {
  582. //console.log('stateIndex', stateIndex, $scope.dateOptions[stateIndex] && $scope.dateOptions[stateIndex].minDate);
  583. //if (!$scope.dateOptions[stateIndex]) {
  584. // $scope.dateOptions[stateIndex] = {
  585. // minDate: data.EffectiveDate
  586. // };
  587. //}
  588. var stateData = {
  589. EffectiveDate: data.EffectiveDate, LobId: lobId, StateId: $scope.selectedStates[stateIndex].StateCode, StateName: $scope.selectedStates[stateIndex].StateName, WithdrawnDate: data.WithdrawnDate,
  590. dateOptions: {
  591. minDate: data.EffectiveDate
  592. }
  593. };
  594. $scope.stateData.push(stateData);
  595. $scope.interLineStateData.push(stateData);
  596. }
  597. }
  598. for (var lobIndex = 0; lobIndex < $scope.lobStateItemData.length; lobIndex++) {
  599. console.log('$scope.lobStateItemData', lobIndex, $scope.lobStateItemData[lobIndex]);
  600. if ($scope.lobStateItemData[lobIndex].LobId === lobId) {
  601. //if (!$scope.dateOptions[stateIndex]) {
  602. // $scope.dateOptions[lobIndex] = {};
  603. //}
  604. //$scope.dateOptions[lobIndex].minDate = $scope.lobStateItemData[lobIndex].StateData.EffectiveDate;
  605. for (var j = 0; j < $scope.lobStateItemData[lobIndex].selectedStates.length; j++) {
  606. var stateData = {
  607. EffectiveDate: $scope.lobStateItemData[lobIndex].StateData.EffectiveDate, LobId: lobId, StateId: $scope.lobStateItemData[lobIndex].selectedStates[j].StateCode, StateName: $scope.lobStateItemData[lobIndex].selectedStates[j].StateName, WithdrawnDate: $scope.lobStateItemData[lobIndex].StateData.WithdrawnDate,
  608. dateOptions: {
  609. minDate: $scope.lobStateItemData[lobIndex].StateData.EffectiveDate
  610. }
  611. };
  612. $scope.stateData.push(stateData);
  613. $scope.interLineStateData.push(stateData);
  614. }
  615. }
  616. }
  617. /// <summary>
  618. // uniqueList of stateData
  619. /// </summary>
  620. /// <param name="item">The item.</param>
  621. /// <returns>StateId array</returns>
  622. var uniqueList = _.uniq($scope.stateData, function (item) {
  623. return item.StateId;
  624. });
  625. var uniqueInterLineList = [];
  626. /// <summary>
  627. // fills uniqueInterLineList using foreach
  628. /// </summary>
  629. /// <param name="interLineItem">The inter line item.</param>
  630. /// <returns>uniqueInterLineList</returns>
  631. angular.forEach($scope.interLineStateData, function (interLineItem) {
  632. if (interLineItem.LobId === lobId) {
  633. uniqueInterLineList.push(interLineItem);
  634. }
  635. });
  636. /// <summary>
  637. // uniqueInterLineList
  638. /// </summary>
  639. /// <param name="item">The item.</param>
  640. /// <returns>StateId array</returns>
  641. uniqueInterLineList = _.uniq(uniqueInterLineList, function (item) {
  642. return item.StateId;
  643. });
  644. $scope.interLineStateData = uniqueInterLineList;
  645. $scope.stateData = uniqueList;
  646. for (var i = 0; i < $scope.lobStateItemData.length; i++) {
  647. if (!$scope.lobStateItemData[i].StateItemData) {
  648. $scope.lobStateItemData[i].StateItemData = [];
  649. }
  650.  
  651. if ($scope.lobStateItemData[i].StateItemData.length > 0) {
  652. for (var interLineIndex = 0; interLineIndex < uniqueInterLineList.length; interLineIndex++) {
  653. if (uniqueInterLineList[interLineIndex].LobId === $scope.lobStateItemData[i].LobId) {
  654. $scope.lobStateItemData[i].StateItemData.push(uniqueInterLineList[interLineIndex]);
  655. }
  656. }
  657. /// <summary>
  658. // uniqueStateList
  659. /// </summary>
  660. /// <param name="item">The item.</param>
  661. /// <returns> StateId array </returns>
  662. var uniqueStateList = _.uniq($scope.lobStateItemData[i].StateItemData, function (item) {
  663. return item.StateId;
  664. });
  665. $scope.lobStateItemData[i].StateItemData = uniqueStateList;
  666. } else {
  667. for (var uniqueInterlineIndex = 0; uniqueInterlineIndex < uniqueInterLineList.length; uniqueInterlineIndex++) {
  668. if (uniqueInterLineList[uniqueInterlineIndex].LobId === $scope.lobStateItemData[i].LobId) {
  669. $scope.lobStateItemData[i].StateItemData.push(uniqueInterLineList[uniqueInterlineIndex]);
  670. }
  671. }
  672. }
  673. }
  674. if ($scope.stateObj) {
  675. $scope.stateObj.EffectiveDate = null;
  676. $scope.stateObj.WithdrawnDate = null;
  677. }
  678. for (var lobClearIndex = 0; lobClearIndex < $scope.lobStateItemData.length; lobClearIndex++) {
  679. if ($scope.lobStateItemData[lobClearIndex].LobId === lobId && $scope.lobStateItemData[lobClearIndex].StateData) {
  680. $scope.lobStateItemData[lobClearIndex].StateData.EffectiveDate = null;
  681. $scope.lobStateItemData[lobClearIndex].StateData.WithdrawnDate = null;
  682. }
  683. }
  684. };
  685.  
  686. /// <summary>
  687. // removes state information
  688. /// </summary>
  689. /// <param name="data">The data.</param>
  690. /// <returns>broad casts selectedStateChanges</returns>
  691. $scope.removeStateInfo = function (data) {
  692. /// <summary>
  693. // Selected States
  694. /// </summary>
  695. /// <param name="curItem">The current item.</param>
  696. /// <returns>boolean</returns>
  697. $scope.tempSelectedStates = $.grep($scope.selectedStates, function (curItem) {
  698. return curItem.StateName !== data.StateName;
  699. });
  700. $scope.selectedStates = $scope.tempSelectedStates;
  701. for (var i = 0; i < $scope.lobStateItemData.length; i++) {
  702. if ($scope.lobStateItemData[i].LobId === data.LobId) {
  703. if ($scope.lobStateItemData[i].StateItemData !== undefined) {
  704. for (var lobIndex = 0; lobIndex < $scope.lobStateItemData[i].StateItemData.length; lobIndex++) {
  705. if ($scope.lobStateItemData[i].StateItemData[lobIndex].StateId === data.StateId) {
  706. $scope.lobStateItemData[i].StateItemData.splice(lobIndex, 1);
  707. }
  708. }
  709. }
  710. if ($scope.lobStateItemData[i].selectedStates !== undefined) {
  711. for (var j = 0; j < $scope.lobStateItemData[i].selectedStates.length; j++) {
  712. if ($scope.lobStateItemData[i].selectedStates[j].StateCode === data.StateId) {
  713. $scope.lobStateItemData[i].selectedStates.splice(j, 1);
  714. }
  715. }
  716. }
  717. }
  718. }
  719. $scope.stateData.splice($scope.stateData.indexOf(data), 1);
  720. $scope.interLineStateData.splice($scope.interLineStateData.indexOf(data), 1);
  721. $rootScope.$broadcast('selectedStateChanges', { data: $scope.lobStateItemData.length > 0 ? $scope.lobStateItemData : $scope.stateData });
  722. };
  723.  
  724. /// <summary>
  725. // Lob changes
  726. /// </summary>
  727. /// <param name="event">The event.</param>
  728. /// <param name="args">The arguments.</param>
  729. /// <returns>broad casts selectedStateChanges</returns>
  730. $rootScope.$on('lobChanges', function (event, args) {
  731. $scope.stateInvalid0 = false;
  732. $scope.effectiveDateInvalid0 = false;
  733. if (args.data !== null) {
  734. $scope.isShowDropdown = args.data.LobId === 'IL' ? true : false;
  735. $scope.selectedLOB = args.data.LobId === 'IL' ? null : args.data.LobValue;
  736. $scope.selectedLOBId = args.data.LobId;
  737. $scope.stateData = [];
  738. $scope.lobStateItemData = [];
  739.  
  740. if ($scope.selectedLOBId === 'IL' && $scope.isIsoTenant) {
  741. $scope.originalLobData = _.where($scope.originalLobData, { 'LOBType': 'ISO' });
  742. }
  743.  
  744. /// <summary>
  745. // sets scope variables
  746. /// </summary>
  747. /// <param name="item">The item.</param>
  748. angular.forEach($scope.stateList, function (item) {
  749. item.IsChecked = false;
  750. item.lobId = args.data.LobId;
  751. });
  752. $scope.selectedStates = [];
  753. } else {
  754. $scope.selectedLOB = null;
  755. $scope.isShowDropdown = false;
  756. $scope.stateData = [];
  757. $scope.lobStateItemData = [];
  758. $scope.selectedStates = [];
  759. }
  760. $rootScope.$broadcast('selectedStateChanges', { data: $scope.lobStateItemData });
  761. });
  762. };
  763.  
  764. return directive;
  765.  
  766. }]);
  767. /// <summary>
  768. // stateApplicabilityCtrl
  769. /// </summary>
  770. /// <param name="$scope">The $scope.</param>
  771. /// <param name="$uibModalInstance">The $uib modal instance.</param>
  772. /// <param name="vmConfig">The vm configuration.</param>
  773. app.controller('stateApplicabilityCtrl', ['$scope', '$uibModalInstance', 'vmConfig', function ($scope, $uibModalInstance, vmConfig) {
  774. $scope.languageStrings = vmConfig.languageStrings;
  775. /// <summary>
  776. // closes $uibModalInstance
  777. /// </summary>
  778. $scope.close = function () {
  779. $uibModalInstance.close();
  780. };
  781. }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement