Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.39 KB | None | 0 0
  1. mainApp.controller('RegistrationCtrl', function ($scope,$http) {
  2.  
  3. $scope.indexCatalog=0;
  4.  
  5. $scope.rootNodeCatalog="#idnewCatalogTree";
  6.  
  7. // $scope.loadingImg=document.getElementById('namePath').value+"/resources/images/loader.gif";
  8.  
  9. $scope.getDisciplines=function(){
  10. $('#modalLoader').modal('show');
  11. // $http.get('service/subscriber').success(function(data, status, headers, config) {
  12. // MOCK
  13. $http.get(mockPath +'secure.service.subscriber.json').success(function(data, status, headers, config) {
  14. if(data.result.message=='OK'){
  15. var data_render=[];
  16. $(data.response).each(function(index,item){
  17. data_render.push([
  18. item.id,
  19. item.name,
  20. item.description,
  21. 0,
  22. 0,
  23. 0
  24. ]);
  25. });
  26.  
  27. if($.fn.DataTable.isDataTable('#dtEvents')){
  28. $('#dtEvents').DataTable().destroy();
  29. }
  30.  
  31. $('#dtEvents').DataTable({
  32. data: data_render,
  33. "columnDefs": [
  34. {
  35. "render": function ( data, type, row ) {
  36. return "<input type='number' class='input-row input-sm form-control' value='0' />";
  37. },
  38. "targets": [3,4,5]
  39. }
  40. ]
  41.  
  42. });
  43.  
  44. $('#dtEvents tbody').on('click', 'input.input-row', function () {
  45. var indexCell = $(this).parents('td').index();
  46. var indexRow = $(this).parents('tr').index();
  47. var row = $('#dtEvents').DataTable().row( ':eq('+indexRow+')' );
  48. row.data()[indexCell]=parseInt($(this).val());
  49. });
  50.  
  51. $("#confirmEvents").click(function(e){
  52. e.preventDefault();
  53. e.stopImmediatePropagation();
  54. var dataEvents={
  55. "accompanying":{"accompanying":$("#naccpersons").val()},
  56. "discipline":[]
  57. };
  58.  
  59. $($('#dtEvents').DataTable().rows().nodes()).each(function(){
  60. var id=$(this).children("td:nth-child(1)").html();
  61. var athletisFemale=parseInt($(this).children("td:nth-child(4)").children("input").val());
  62. var athletisMale=parseInt($(this).children("td:nth-child(5)").children("input").val());
  63. var official=parseInt($(this).children("td:nth-child(6)").children("input").val());
  64.  
  65. if(athletisFemale>0 || athletisMale>0 || official>0){
  66. dataEvents.discipline.push(
  67. {"id":id,"athletisFemale":athletisFemale,"athletisMale":athletisMale,"official":official}
  68. )
  69. }
  70.  
  71. });
  72.  
  73. $scope.getProducts(dataEvents);
  74. });
  75. $('#modalLoader').modal('hide');
  76. $('#modalRegAthletes').modal('show');
  77. }else{
  78. errorService.showModalError(data.result.message);
  79. }
  80. }).error(function(data, status, headers, config) {
  81. errorService.showModalError();
  82. });
  83. }
  84.  
  85. $scope.navigateCatalog=function(category,parent_index){
  86. for(var i=0;i<category.length;i++){
  87. if(category[i].layout){
  88. $scope.indexCatalog++;
  89. var class_parent="";
  90. if(parent_index>0)
  91. class_parent=" treegrid-parent-"+parent_index;
  92. var description="Additional Info";
  93. if(category[i].description)
  94. description=category[i].description;
  95. $($scope.rootNodeCatalog).append("<tr class='treegrid-"+$scope.indexCatalog+class_parent+"'><td width='50%'>"+category[i].name+"</td><td>"+description+"</td></tr>");
  96. var pindex=$scope.indexCatalog;
  97. }else
  98. var pindex=parent_index;
  99. if(category[i].product){
  100. for(var j=0;j<category[i].product.length;j++){
  101. $scope.indexCatalog++;
  102. $($scope.rootNodeCatalog).append("<tr class='treegrid-"+$scope.indexCatalog+" treegrid-parent-"+pindex+"'><td width='50%'>"+category[i].product[j].name+" &euro; "+category[i].product[j].price+"</td><td><input id='"+category[i].product[j].id+"' style='width: 50%;' type='number' min='0' class='form-control' value='0' placeholder='quantity'></td></tr>");
  103. }
  104. }
  105.  
  106. if(category[i].category){
  107. $scope.navigateCatalog(category[i].category,(category[i].layout)?pindex:parent_index);
  108. }
  109.  
  110. }
  111. }
  112.  
  113. $scope.getReview = function() {
  114. // angular.forEach($scope.response.catalog, function(obj){
  115. // $("#previewStep").append("<p>" + obj + "</p>");
  116. // })
  117. // console.log($scope.response.catalog)
  118. }
  119.  
  120. $scope.getProducts=function(dataEvents){
  121. $('#modalLoader').modal('show');
  122. // $http.post('service/subscriber', JSON.stringify(dataEvents)).success(function(data, status, headers, config) {
  123. // MOCK
  124. $http.get(mockPath +'secure.service.subscriber_post.json').success(function(data, status, headers, config) {
  125. $('#modalLoader').modal('hide');
  126. if(data.result.message=="OK"){
  127.  
  128. $http.get($scope.$parent.pages.wizard.url).success(function(contentWizard, status, headers, config) {
  129. $('#wizard').html(contentWizard);
  130. $($scope.rootNodeCatalog+" tbody").empty();
  131. $scope.response = data.response;
  132. $scope.navigateCatalog(data.response.catalog);
  133. $scope.getReview();
  134. $("#hajdhTotal").val(data.response.total);
  135. $('.tree').treegrid({
  136. expanderExpandedClass: 'glyphicon glyphicon-minus',
  137. expanderCollapsedClass: 'glyphicon glyphicon-plus'
  138. });
  139. $('#wizard').smartWizard();
  140.  
  141. $('#modalRegAthletes').modal('hide');
  142. $('#modalCatalog').modal({
  143. backdrop : 'static',
  144. keyboard : false,
  145. show : true
  146. });
  147.  
  148. $(".payment-block").html(data.response.payment[0].name);
  149. $(".payment-block").data("name",data.response.payment[0].name);
  150. $(".payment-block").data("id",data.response.payment[0].id);
  151. $(".payment-block").click(function(e){
  152. $scope.setPayment($(this).data("id"),$(this).data("name"),data.response.keyOrder);
  153. })
  154. for(var i=1;i<data.response.payment.length;i++){
  155. $paymentBlock=$(".payment-block").clone().appendTo( ".payments-container" );
  156. $paymentBlock.data("name",data.response.payment[i].name);
  157. $paymentBlock.data("id",data.response.payment[i].id);
  158. $paymentBlock.html(data.response.payment[i].name);
  159.  
  160. $paymentBlock.click(function(e){
  161. $scope.setPayment($(this).data("id"),$(this).data("name"),data.response.keyOrder);
  162. })
  163. }
  164.  
  165. })
  166.  
  167.  
  168. }else{
  169. errorService.showModalError(data.result.message);
  170. }
  171.  
  172. }).error(function(data, status, headers, config) {
  173. errorService.showModalError();
  174. });
  175. }
  176.  
  177. $scope.payments=[];
  178.  
  179. $scope.paymentFields={
  180. "banktransfer":{
  181. "iban":"",
  182. "bank":"",
  183. "description":"",
  184. "heading":"",
  185. "total":"",
  186. "partial":""
  187. }
  188. }
  189.  
  190. $scope.setPayment=function(id,type,keyOrder){
  191. var arrayBankChannel = [];
  192. var rowCatalogarrayBankChannel = $("#idnewCatalogTree").find('tr');
  193. $(rowCatalogarrayBankChannel).each(function(index, value){
  194. var inputs = $(this).find("input");
  195. inputs.each(function(index, value) {
  196. var checkifnumber = $(this).val();
  197. var idcheckifnumber = $(this).attr('id');
  198. if(checkifnumber!=0){
  199. arrayBankChannel.push(
  200. {
  201. "id": idcheckifnumber,
  202. "quantity": checkifnumber
  203. }
  204. );
  205. }
  206. });
  207. });
  208.  
  209. var finaltosend = {
  210. "totalMember": $("#hajdhTotal").val(),
  211. "keyOrder": keyOrder,
  212. "payment": {
  213. "id":id
  214. },
  215. "products" : arrayBankChannel
  216. };
  217.  
  218. switch(id){
  219. case 2:
  220.  
  221. $("#loaderWizard").removeClass("hide");
  222. $("#wizard").addClass("hide");
  223. // $http.post('service/order/subscriber', JSON.stringify(finaltosend)).success(function(data, status, headers, config) {
  224. // MOCK
  225. $http.get(mockPath +'secure.service.subscriber_post.json').success(function(data, status, headers, config) {
  226.  
  227. $http.get($scope.$parent.pages.banktransfer.url).success(function(contentWizard, status, headers, config) {
  228. if(data.result.message=='OK'){
  229. $("#loaderWizard").addClass("hide");
  230. $("#wizard").removeClass("hide");
  231. $('#wizard').html(contentWizard);
  232. $("#bt-description").html(data.response.payment.description);
  233. $("#bt-iban").html(data.response.payment.iban);
  234. $("#bt-bank").html(data.response.payment.bank);
  235. $("#bt-event-name").html(data.response.payment.heading);
  236. $("#bt-totalBank").html("&euro; "+data.response.totPayment);
  237. $("#bt-partialBank").html("&euro; "+data.response.payment.amount);
  238. }else{
  239. errorService.showModalError(data.result.message);
  240. $("#loaderWizard").addClass("hide");
  241. $("#wizard").removeClass("hide");
  242. }
  243. }).error(function(data, status, headers, config) {
  244. errorService.showModalError();
  245. $("#loaderWizard").addClass("hide");
  246. $("#wizard").removeClass("hide");
  247. });
  248.  
  249. }).error(function(data, status, headers, config) {
  250. errorService.showModalError();
  251. $("#loaderWizard").addClass("hide");
  252. $("#wizard").removeClass("hide");
  253. });
  254. break;
  255. case 1:
  256. // $http.post('service/order/subscriber', JSON.stringify(finaltosend)).success(function(data, status, headers, config) {
  257. // MOCK
  258. $http.get(mockPath+'service.order.subscriber_post_CC.json', JSON.stringify(finaltosend)).success(function(data, status, headers, config) {
  259. if(data.result.message=='OK'){
  260. var url=data.response.payment.endpoint;
  261. $("#wizard").html('<iframe width="100%" height="1000" frameborder="0" scrolling="yes" allowtransparency="true" src="'+url+'"></iframe>');
  262. }else{
  263. errorService.showModalError(data.result.message);
  264. }
  265. }).error(function(data, status, headers, config) {
  266. errorService.showModalError();
  267. });
  268. break;
  269. }
  270. }
  271.  
  272. $scope.openLoader=function(){
  273. $("#modalCatalog").modal("hide");
  274. }
  275.  
  276. $scope.init=function(){
  277. $scope.getDisciplines();
  278. }
  279.  
  280. $scope.$on('showregistration', function(event, args) {
  281. $scope.init();
  282. });
  283. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement