Advertisement
Guest User

wawan

a guest
Dec 8th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. app.controller('pendataanDBKBJPB2', ['$scope', '$http','$stateParams','$state','$modal','$sce', 'toaster', '$cookieStore', '$timeout', function($scope, $http, $stateParams, $state, $modal, $sce, toaster, $cookieStore, $timeout) {
  2. filterable();
  3. var offset = ((parseInt($stateParams.page) - 1) * 10) || 0;
  4. try {
  5. $scope.search = ($stateParams.search!==undefined) ? JSON.parse($stateParams.search) : [];
  6. } catch(e){
  7. $scope.search = [];
  8. }
  9. angular.element(document).ready(function(){
  10. var flash_message = $cookieStore.get('flash_message');
  11.  
  12. if(flash_message!=undefined && flash_message!=null && flash_message.type!=undefined){
  13. $timeout(function(){
  14. toaster.pop(flash_message.type,flash_message.title,flash_message.text);
  15. $cookieStore.remove('flash_message');
  16. }, 1000);
  17. }
  18. });
  19. $scope.data = {};
  20.  
  21. $scope.data.search_tahun = $scope.search[0];
  22. $scope.data.search_kelas = $scope.search[1];
  23. $scope.search_tahun = $scope.search[0];
  24. $scope.search_kelas = $scope.search[1];
  25. $scope.info = '';
  26. $scope.search_submit = function(){
  27. $state.go($state.current,{search:JSON.stringify([$scope.data.search_tahun || '', $scope.data.search_kelas || ''])},{reload:true});
  28. };
  29. // var search_q = [],
  30. // search_col = [],
  31. // col = ['thn_dbkb_jpb2','kls_dbkb_jpb2'];
  32. // for(key in $scope.search){
  33. // if($scope.search[key]){
  34. // search_q.push($scope.search[key]);
  35. // search_col.push(col[key]);
  36. // }
  37. // }
  38.  
  39. // $http({
  40. // method: 'POST',
  41. // url: "/pendataan/Dbkb_jpb02/index/"+offset,
  42. // data: $.param({
  43. // tahun:search_q[0],
  44. // kelas:search_q[1],
  45. // go:'1',
  46. // }),
  47. // headers: {'Content-Type': 'application/x-www-form-urlencoded'}
  48.  
  49. var current_tahun = $scope.data.search_tahun;
  50. var current_kelas = $scope.data.search_kelas;
  51. $http({
  52. method: 'POST',
  53. url: "/pendataan/Dbkb_jpb02/index/"+offset,
  54. data: $.param({
  55. tahun : current_tahun,
  56. kelas : current_kelas,
  57. go:1,
  58. }),
  59. headers: {
  60. 'Content-Type': 'application/x-www-form-urlencoded'
  61. }
  62. }).success(function(response){
  63. //response.data.table = [];
  64. $scope.search = response.data.search;
  65.  
  66. $scope.list = response.data.table;
  67. $scope.total = parseInt(response.data.tot_row);
  68. $scope.offset = parseInt(response.data.offset);
  69. $scope.perpage = parseInt(response.data.perpage);
  70. $scope.maxoffset = ($scope.offset + $scope.perpage);
  71. $scope.maxoffset = $scope.maxoffset > $scope.total ? $scope.total : $scope.maxoffset;
  72.  
  73. $scope.page = parseInt($stateParams.page);
  74. $scope.maxpage = Math.ceil(parseInt(response.data.tot_row) / parseInt(response.data.perpage));
  75. $scope.getNumber = function(current,maxpage){
  76. var numbers = [],
  77. end = Math.ceil((current) / 10) * 10,
  78. start = Math.floor((current - 1) / 10) * 10;
  79. if(end > maxpage) end = maxpage;
  80. if(start < 1) start = 1;
  81. for(i=start; i <= end; ++i) numbers.push(i);
  82. return numbers;
  83. };
  84. var page_info = angular.element(document.getElementById('HeaderDD')).scope();
  85. page_info.refresh(function(res){
  86. $scope.info = res.content_help;
  87. });
  88. if($scope.list.length < 1 && $scope.page > 1){
  89. $state.go($state.current,{page:1},{reload:true});
  90. }
  91. });
  92. $scope.refresh = function(){
  93. $state.go($state.current,{page:$stateParams.page,search:$stateParams.search || ''},{reload:true});
  94. };
  95. $scope.info_btn = function(){
  96. var modalInstance = $modal.open({
  97. templateUrl: 'info_modal',
  98. controller: 'modal_info',
  99. });
  100. modalInstance.info = $scope.info;
  101. };
  102. }]);
  103.  
  104. app.controller('refKecamatanTambah', ['$scope', '$http','$stateParams', '$sce', 'toaster', '$state', '$cookieStore', '$modal', '$window', function($scope, $http, $stateParams, $sce, toaster, $state, $cookieStore, $modal, $window) {
  105. var id = $stateParams.id;
  106. $scope.data = {
  107. KD_PROPINSI : '',
  108. KD_DATI2 : '',
  109. KD_KECAMATAN : '',
  110. NM_KECAMATAN : '',
  111. };
  112.  
  113. $http.get("/referensi/wilayah_kecamatan/create").success(function(response){
  114. $scope.data.KD_PROPINSI = response.data.propinsi;
  115. $scope.data.KD_DATI2 = response.data.dati2;
  116.  
  117. var page_info = angular.element(document.getElementById('HeaderDD')).scope();
  118. page_info.refresh(function(res){
  119. $scope.info = res.content_help;
  120. });
  121. });
  122. $scope.submit = function(){
  123. $http({
  124. method: 'POST',
  125. url: '/referensi/wilayah_kecamatan/store',
  126. data: $.param(lowerCaseKey($scope.data)),
  127. headers: {
  128. 'Content-Type': 'application/x-www-form-urlencoded'
  129. }
  130. }).success(function(response){
  131. if(response.status){
  132. $cookieStore.put('flash_message',{type:'success',title:'Sukses',text:'Data berhasil ditambahkan'});
  133. $state.go('^',null,{reload:true});
  134. } else {
  135. toaster.pop('error', 'Error', response.msg, 3000, 'trustedHtml');
  136. }
  137. });
  138. };
  139. $scope.back = function(){
  140. $window.history.back();
  141. };
  142. $scope.info_btn = function(){
  143. var modalInstance = $modal.open({
  144. templateUrl: 'info_modal',
  145. controller: 'modal_info',
  146. });
  147. modalInstance.info = $scope.info;
  148. };
  149. }]);
  150. app.controller('refKecamatanEdit',function($scope, $http, $stateParams, $sce, toaster, $state, $cookieStore, $modal, $filter, $window) {
  151. var id = $stateParams.id;
  152. $http.get("/referensi/wilayah_kecamatan/edit/"+id.split('-').join('/')).success(function(response){
  153. $scope.data = response.data.table[0];
  154. $scope.id = id;
  155.  
  156. $scope.update = function(_id){
  157. _id = _id.split('-');
  158. $http({
  159. method: 'POST',
  160. url: '/referensi/wilayah_kecamatan/update',
  161. data: $.param(lowerCaseKey($scope.data)),
  162. headers: {
  163. 'Content-Type': 'application/x-www-form-urlencoded'
  164. }
  165. }).success(function(response){
  166. if(response.status){
  167. $cookieStore.put('flash_message',{type:'success',title:'Sukses',text:'Perubahan berhasil disimpan'});
  168. $state.go('^',{page:$stateParams.page,search:$stateParams.search || ''},{reload:true});
  169. } else {
  170. toaster.pop('error', 'Error', response.msg, 3000, 'trustedHtml');
  171. }
  172. });
  173. };
  174. $scope.back = function(){
  175. $window.history.back();
  176. };
  177. $scope.info = '';
  178. var page_info = angular.element(document.getElementById('HeaderDD')).scope();
  179. page_info.refresh(function(res){
  180. $scope.info = res.content_help;
  181. });
  182. });
  183. $scope.info_btn = function(){
  184. var modalInstance = $modal.open({
  185. templateUrl: 'info_modal',
  186. controller: 'modal_info',
  187. });
  188. modalInstance.info = $scope.info;
  189. };
  190. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement