selectResidentNodesCtrl.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. angular.module('push')
  2. .controller('selectResidentNodesCtrl', function ($scope,ResourceLibraryService,$timeout,UtilService,resourceLibraryModel,UserService) {
  3. //加载等待页
  4. $scope.isloadingPageFloor=false;
  5. //全部企业加载失败页
  6. $scope.isloadingPageFailAll=false;
  7. //我的企业加载失败页
  8. $scope.isloadingPageFail=false;
  9. $scope.userid=1;
  10. $scope.keyword='';
  11. $scope.nodeid='';
  12. $scope.allResidentNodesList=[];
  13. var getAllResidentNodesList = function () {
  14. $scope.isloadingPageFloor=true;
  15. ResourceLibraryService.getNodeList("").then(function (response) {
  16. // console.log(response);
  17. $scope.allResidentNodesList = response.data;
  18. $scope.nodeid=response.data.id;
  19. $scope.isloadingPageFloor=false;
  20. $scope.isloadingPageFail=false;
  21. $timeout(function () {
  22. //默认第一个展开
  23. })
  24. }, function () {
  25. $scope.isloadingPageFloor=false;
  26. $scope.isloadingPageFail=true;
  27. });
  28. };
  29. getAllResidentNodesList();
  30. //获取我的常驻节点名称
  31. var getNormalNodeList = function () {
  32. ResourceLibraryService.getNormalNodeList().then(function (response) {
  33. //console.log(response);
  34. // 节点列表
  35. $scope.normalNodes = response.data;
  36. }, function () {
  37. });
  38. };
  39. getNormalNodeList();
  40. // 将已选择的nodeid组合
  41. $scope.nodeidlist = [];
  42. $scope.selectedSectionLength=0;
  43. if(UtilService.isDefined($scope.nodeidlist) && $scope.nodeidlist.length > 0){
  44. angular.forEach($scope.nodeidlist, function (value, ind) {
  45. $scope.nodeidlist.push(value.id);
  46. $scope.selectedSectionLength += 1;
  47. });
  48. }
  49. // 记录选中节点列表索引
  50. var indexNodelist = [];
  51. // 转换用到的indexNodelist为impost需要的model
  52. $scope.postResidentModel=
  53. {
  54. //TODO
  55. userid:UserService.id,
  56. // userid:1,
  57. data:[]
  58. };
  59. // 选择节点(多选)
  60. $scope.selectNodelId = function (nodeId,index,isCheckedAble) {
  61. if(isCheckedAble==0){
  62. if ($scope.allResidentNodesList[index].isChecked) {
  63. var ind = indexNodelist.indexOf(index);
  64. indexNodelist.splice(ind,1);
  65. $scope.selectedSectionLength -= 1;
  66. } else {
  67. indexNodelist.push(nodeId);
  68. $scope.selectedSectionLength += 1;
  69. }
  70. $scope.allResidentNodesList[index].isChecked = !$scope.allResidentNodesList[index].isChecked;
  71. //console.log(indexNodelist);
  72. }else{
  73. return
  74. }
  75. };
  76. //重新加载
  77. $scope.repeatLoadAll = function () {
  78. $scope.isloadingPageFail=false;
  79. getAllResidentNodesList();
  80. };
  81. // 返回选择节点页面
  82. $scope.gotoSourcePage=function () {
  83. // 不刷新页面
  84. resourceLibraryModel.setFlag(false);
  85. $scope.goback();
  86. };
  87. //提交已选择的常驻节点
  88. var postCheckedNodes=function () {
  89. //传入indexNodelist,每循环一遍就push一次
  90. angular.forEach(indexNodelist,function (value,key) {
  91. $scope.postResidentModel.data.push({
  92. 'node':value
  93. })
  94. });
  95. //console.dir($scope.postResidentModel);
  96. $scope.nodeCheckedList=$scope.postResidentModel;
  97. ResourceLibraryService.postNodeList(angular.toJson($scope.nodeCheckedList)).then(function (response) {
  98. // console.log('成功了');
  99. }, function () {
  100. // console.log('失败了');
  101. });
  102. };
  103. // 返回已选中的成员
  104. $scope.returnCheckedNodeList=function (isPostNone) {
  105. var isPostNone=$scope.selectedSectionLength;
  106. if(isPostNone==0){
  107. $timeout(function () {
  108. $scope.goback();
  109. },300);
  110. }else{
  111. // 不刷新页面
  112. resourceLibraryModel.setFlag(false);
  113. //console.log(indexNodelist);
  114. postCheckedNodes();
  115. $timeout(function () {
  116. $scope.goback();
  117. },300);
  118. }
  119. };
  120. });