Advertisement
Guest User

Untitled

a guest
May 6th, 2017
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.75 KB | None | 0 0
  1. openFB.init({appId: '522196301254895'});
  2. angular.module('starter.controllers', ['ionic', 'firebase', 'ionic.rating', 'ngCordova'])
  3. .factory('formDataObject', function() {
  4. return function(data) {
  5. var fd = new FormData();
  6. angular.forEach(data, function(value, key) {
  7. if(key == "file"){
  8. fd.append(key, new Blob([ value ], { type: "image/jpeg" }),"image.jpeg");
  9. }else{
  10. fd.append(key, value);
  11. }
  12.  
  13. });
  14. return fd;
  15. };
  16. }).factory('fileReader', function($q) {
  17.  
  18. return {
  19. readAsDataUrl: function(filePath) {
  20.  
  21. var deferred = $q.defer();
  22.  
  23. function gotFileEntry(fileEntry) {
  24. fileEntry.file(gotFile, fail);
  25. }
  26.  
  27. function gotFile(file){
  28. readDataUrl(file);
  29. }
  30.  
  31. function readDataUrl(file) {
  32. var reader = new FileReader();
  33. reader.onloadend = function(evt) {
  34. console.log("Read as data URL");
  35. fileContent = evt.target.result;
  36. deferred.resolve(fileContent);
  37.  
  38. };
  39. reader.readAsArrayBuffer(file);
  40. }
  41.  
  42. function fail(evt) {
  43. console.log(evt.target.error.code);
  44. }
  45.  
  46. // window.resolveLocalFileSystemURI(filePath, gotFileEntry, fail);
  47. window.resolveLocalFileSystemURL(filePath, gotFileEntry, fail);
  48.  
  49. return deferred.promise;
  50. }
  51. };
  52. })
  53. .factory('chek_image_url', function($q) {
  54. return {
  55. chek : function(src) {
  56.  
  57. var deferred = $q.defer();
  58.  
  59. var image = new Image();
  60. image.onerror = function() {
  61. deferred.resolve(false);
  62. };
  63. image.onload = function() {
  64. deferred.resolve(true);
  65. };
  66. image.src = src;
  67. return deferred.promise;
  68. }
  69. }
  70. })
  71. .controller('MainCtrl', function($scope, $http, $rootScope, chek_image_url, $q, $state, $cordovaToast, $rootScope, $ionicModal, $ionicPopup, $ionicLoading, $localstorage, formDataObject, $cordovaCamera, fileReader, $ionicSideMenuDelegate, Firebase, $ionicPopup) {
  72. console.log($localstorage.get('is_device'));
  73. $ionicLoading.hide();
  74. $scope.gambar = "";
  75. $scope.ambil_gambar=false;
  76. $scope.photo="";
  77. $scope.cekphoto=function(){
  78. console.log($localstorage.get('photo'));
  79. console.log(1);
  80. if($localstorage.get('join_by')=='facebook'){
  81. console.log(2);
  82. $scope.photo=$localstorage.get('photo');
  83. console.log($scope.photo);
  84. }else{
  85. $scope.photo=base_url+'photo_barber/'+$localstorage.get('photo');
  86. }
  87. chek_image_url.chek($scope.photo).then(function(test) {
  88. if(test){
  89. $scope.photo=$scope.photo;
  90. }else{
  91. $scope.photo="";
  92. }
  93. });
  94.  
  95. }
  96. $scope.$on( "$ionicView.enter", function( scopes, states ) {
  97. console.log($localstorage.get('login')=='false');
  98. $scope.cekphoto();
  99. });
  100. $rootScope.$on('gantiphoto', function(e, data){
  101. $scope.cekphoto();
  102. });
  103. $rootScope.$on('devtoken', function(){
  104. $rootScope.checkdevice();
  105. });
  106. $rootScope.$on('adapesan2', function(){
  107. $rootScope.cekpesan();
  108. });
  109.  
  110. $scope.pop;
  111. $scope.openModal = function() {
  112. $scope.pop=$ionicPopup.show({
  113. title:'Edit Photo',
  114. template:'<center><label><button class="button" ng-click="openPhotoLibrary();" ><i class="icon ion-images" ></i></button></label>&nbsp;&nbsp;'+
  115. '<label><button class="button" ng-click="takePicture();"><i class="icon ion-android-camera" ></i></button></label></center>',
  116. scope:$scope,
  117. buttons: [
  118. {
  119. text: 'Cancel',
  120. type: 'button-positive'
  121. }
  122. ]
  123. });
  124. };
  125. $scope.simpan_photo=function(){
  126. $ionicLoading.show();
  127. if($scope.ambil_gambar){
  128. fileReader.readAsDataUrl($scope.gambar).then(function(fileInfo) {
  129. ////console.log(fileInfo);
  130. return $http({
  131. method: 'POST',
  132. url: rest_url+'edit_photo',
  133. headers: {
  134. 'Content-Type':undefined,
  135. //'Authorization': 'Basic ' + btoa("user:password")
  136. },
  137. data: {
  138. file: fileInfo,
  139. email:$localstorage.get('email'),
  140. },
  141. transformRequest: formDataObject
  142. })
  143. .success(function(data, status, headers, config) {
  144. $ionicLoading.hide();
  145. $scope.pop.close();
  146. if(data.code=='1'){
  147. $localstorage.set('photo', data.photo);
  148. $rootScope.$broadcast('gantiphoto', data.photo);
  149. }else{
  150.  
  151. }
  152. })
  153. .error(function(data, status, headers, config) {
  154. if($localstorage.get('is_device')!=undefined){
  155. $cordovaToast.show('Sorry system fail, please try again', 'long', 'center')
  156. }else{
  157. alert('Sorry system fail, please try again');
  158. }
  159. $ionicLoading.hide();
  160. $scope.pop.close();
  161. });
  162.  
  163. }, function(err) {
  164. });
  165. }
  166. }
  167.  
  168. $scope.openPhotoLibrary = function() {
  169. var options = {
  170. quality: 75,
  171. destinationType: Camera.DestinationType.FILE_URI,
  172. sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
  173. allowEdit: true,
  174. encodingType: Camera.EncodingType.JPEG,
  175. targetWidth: 300,
  176. targetHeight: 300,
  177. popoverOptions: CameraPopoverOptions,
  178. saveToPhotoAlbum: false
  179. };
  180.  
  181. $cordovaCamera.getPicture(options).then(function (imageData) {
  182. ////console.log(imageData);
  183. $scope.gambar = imageData;
  184. $scope.ambil_gambar=true;
  185. $scope.simpan_photo();
  186. }, function (err) {
  187. ////console.log(err);
  188. });
  189. }
  190. $scope.takePicture = function() {
  191. //alert('ambil gambar');
  192. var options = {
  193. quality: 75,
  194. destinationType: Camera.DestinationType.FILE_URI,
  195. sourceType: Camera.PictureSourceType.CAMERA,
  196. allowEdit: true,
  197. encodingType: Camera.EncodingType.JPEG,
  198. targetWidth: 300,
  199. targetHeight: 300,
  200. popoverOptions: CameraPopoverOptions,
  201. saveToPhotoAlbum: false
  202. };
  203. /* var options = {
  204. quality: 75,
  205. destinationType: Camera.DestinationType.FILE_URL,
  206. sourceType: Camera.PictureSourceType.CAMERA,
  207. allowEdit: true,
  208.  
  209. encodingType: Camera.EncodingType.JPEG,
  210. popoverOptions: CameraPopoverOptions,
  211. saveToPhotoAlbum: false
  212. }; */
  213.  
  214. $cordovaCamera.getPicture(options).then(function(imageData) {
  215. $scope.gambar= imageData;
  216. $scope.ambil_gambar=true;
  217. $scope.simpan_photo();
  218. }, function(err) {
  219. // error
  220. //////console.log(err);
  221. });
  222. }
  223.  
  224.  
  225. $rootScope.goparent=function(){
  226. stat=$state.current.name;
  227. if(stat=='newsdetail') $state.go('news');
  228. if(stat=='storedetail') $state.go('store');
  229. }
  230. $scope.$watch(function () {
  231. return $ionicSideMenuDelegate.isOpen();
  232. },
  233. function (isOpen) {
  234. if (isOpen){
  235. //console.log("open");
  236. $rootScope.menu_open=false;
  237. }else{
  238. //console.log('close');
  239. $rootScope.menu_open=true;
  240. }
  241.  
  242. });
  243. $rootScope.menu_open=true;
  244. $scope.go_setting=function(){
  245. $state.go('setting');
  246. }
  247.  
  248. $scope.toggleLeft = function() {
  249. $ionicSideMenuDelegate.toggleLeft();
  250. };
  251.  
  252. $scope.goto=function(state){
  253. $state.go(state);
  254. }
  255.  
  256.  
  257.  
  258.  
  259. })
  260. .controller('NewsCtrl', function($scope, $rootScope, $http, $ionicModal, $ionicLoading, $state) {
  261. $scope.news={};
  262. $scope.newsd={};
  263. $scope.url=base_url;
  264. $scope.get_news=function(){
  265. $ionicLoading.show();
  266. $http.post(rest_url+'get_news', {})
  267. .success(function(data){
  268. $ionicLoading.hide();
  269. $scope.news=data;
  270. });
  271. }
  272. $scope.get_news();
  273. $rootScope.$on('refresh.news', function(){
  274. $scope.get_news();
  275. });
  276. $ionicModal.fromTemplateUrl('templates/news-detail.html', {
  277. scope: $scope,
  278. cssClass:'ModalProduct',
  279. }).then(function(modal) {
  280. $scope.modalnewsdetail = modal;
  281. });
  282. $scope.show_berita=function(data){
  283. $scope.newsd=data;
  284. $scope.modalnewsdetail.show();
  285. }
  286.  
  287. })
  288. .controller('SettingCtrl', function($rootScope, $state, $cordovaToast, $http, $ionicLoading, $scope, $localstorage, Firebase, Auth) {
  289. if($localstorage.get('email')==undefined){
  290. $rootScope.logout();
  291. }
  292. $scope.user={};
  293. $scope.$on( "$ionicView.enter", function( scopes, states ) {
  294. $scope.user.email=$localstorage.get('email');
  295. $scope.user.phone=parseInt($localstorage.get('phone'));
  296. $scope.user.name_customer=$localstorage.get('name_customer');
  297. });
  298. $scope.register=function(form){
  299. $scope.error="";
  300. if(form.$error.compareTo){
  301. $scope.error="Re Password didn't match to password";
  302. }
  303. if(!form.$valid){
  304. return false;
  305. }
  306. $ionicLoading.show();
  307. //var user = firebase.auth().currentUser;
  308. //Auth.$updatePassword($scope.user.password).then(function() {
  309. $http.post(rest_url+'update_user', {data: $scope.user})
  310. .success(function(data){
  311. $ionicLoading.hide();
  312. if(data.code==1){
  313. if($localstorage.get('is_device')!=undefined){
  314. $cordovaToast.show(data.msg, 'long', 'center')
  315. }else{
  316. alert(data.msg);
  317. }
  318.  
  319. form.$setPristine(true);
  320. $localstorage.set('name_customer', data.user[0].name_customer);
  321. $localstorage.set('phone', data.user[0].phone);
  322. $scope.user.phone=parseInt($localstorage.get('phone'));
  323. $scope.user.name_customer=$localstorage.get('name_customer');
  324. $scope.user.password="";
  325. $scope.user.repassword="";
  326. }
  327. })
  328. .error(function(data){
  329. $ionicLoading.hide();
  330.  
  331. });
  332. //}, function(error) {
  333. //console.log(error.message);
  334. // $scope.error=error.message;
  335. //});
  336. //return false;
  337. }
  338.  
  339. })
  340. .controller('NewsDetailCtrl', function($scope, $stateParams) {
  341.  
  342. })
  343. .filter('toArray', function () {
  344. return function (obj, addKey) {
  345. if (!angular.isObject(obj)) return obj;
  346. if ( addKey === false ) {
  347. return Object.keys(obj).map(function(key) {
  348. return obj[key];
  349. });
  350. } else {
  351. return Object.keys(obj).map(function (key) {
  352. var value = obj[key];
  353. return angular.isObject(value) ?
  354. Object.defineProperty(value, '$key', { enumerable: false, value: key}) :
  355. { $key: key, $value: value };
  356. });
  357. }
  358. }
  359. })
  360. .controller('BookingCtrl', function($scope, $http, $ionicModal, $ionicLoading, $state, $cordovaToast, $ionicPopover, $rootScope, $q, $timeout, $localstorage) {
  361. $scope.url=base_url;
  362. $scope.time={};
  363. // --- service
  364. $scope.service={};
  365. $scope.total_order=0;
  366. $scope.c_service={};
  367. $scope.code_service="";
  368. $scope.price_service;
  369. // --- product
  370. $scope.code_product="";
  371. $scope.price_product;
  372. $scope.product={};
  373. $scope.c_product={};
  374. // --- barber
  375. $scope.code_barber="";
  376. $scope.barber={};
  377. $scope.c_barber={};
  378. // --- store
  379. $scope.stores={};
  380. $scope.c_stores={};
  381. $scope.pilihstore={};
  382. $scope.code_store="";
  383. $scope.status_submit=false;
  384. $scope.phase=1;
  385. var Myform;
  386. // get product data
  387. $scope.get_product=function(){
  388. $http.post(rest_url+'get_product', {})
  389. .success(function(data){
  390. $scope.product=data;
  391. });
  392. }
  393. $scope.get_product();
  394. // get barber data
  395. $scope.get_barber=function(){
  396. $http.post(rest_url+'get_barber', {})
  397. .success(function(data){
  398. $scope.barber=data;
  399. });
  400. }
  401. $scope.get_barber();
  402. // get servic data
  403. $scope.get_service=function(){
  404. $ionicLoading.show();
  405. $http.post(rest_url+'get_service', {})
  406. .success(function(data){
  407. $ionicLoading.hide();
  408. $scope.service=data;
  409. }).error(function(data){
  410. $ionicLoading.hide();
  411. });
  412. }
  413. $scope.get_service();
  414. // get servic data
  415. $scope.get_store=function(){
  416. //$ionicLoading.show();
  417. $http.post(rest_url+'get_store', {})
  418. .success(function(data){
  419. // $ionicLoading.hide();
  420. $scope.stores=data;
  421. }).error(function(data){
  422. //$ionicLoading.hide();
  423. });
  424. }
  425. $scope.get_store();
  426. // click pilih event
  427. $scope.pilih_code_service=function(code){
  428. console.log(code);
  429. $scope.code_service=code.code_service;
  430. $scope.c_service=code;
  431. //$scope.price_service=code.price;
  432. $scope.c_product.price=$scope.c_product.price!=undefined ? $scope.c_product.price : 0;
  433. $scope.total_order=parseInt($scope.c_product.price)+parseInt($scope.c_service.price);
  434. console.log($scope.total_order);
  435. }
  436. // $scope.pilih_store=function(){
  437. // console.log($scope.time.store);
  438. // }
  439. $scope.belum_pilih_product=false;
  440. $scope.pilih_product=function(code){
  441. $scope.belum_pilih_product=true;
  442. $scope.code_product=code.code_product;
  443. $scope.c_product=code;
  444. $scope.c_product.price=$scope.c_product.price!=undefined ? $scope.c_product.price : 0;
  445. $scope.total_order=parseInt($scope.c_product.price)+parseInt($scope.c_service.price);
  446. //$scope.price_product=code.price;
  447. console.log($scope.total_order);
  448. }
  449. $scope.pilih_barber=function(code){
  450. console.log(code);
  451. $scope.code_barber=code.code_barber;
  452. $scope.c_barber=code;
  453. //$scope.price_product=code.price;
  454. }
  455. $scope.checked=false;
  456. $scope.next_service=function(page){
  457. $scope.phase=page!=undefined ? page : 1;
  458. switch($scope.phase){
  459. case 1 :
  460. if($scope.code_service==""){
  461. if($localstorage.get('is_device')!=undefined){
  462. $cordovaToast.show('Please Choose service', 'long', 'center')
  463. }else{
  464. alert('Please choose service');
  465. }
  466.  
  467. return;
  468. }
  469. //$scope.belum_pilih_product=false;
  470. break;
  471. case 2 :
  472. // if($scope.code_product==""){
  473. // alert('Please Choose Product');
  474. // return;
  475. // }
  476. break;
  477. case 3 :
  478. if($scope.code_barber==""){
  479. if($localstorage.get('is_device')!=undefined){
  480. $cordovaToast.show('Please choose barber', 'long', 'center')
  481. }else{
  482. alert('Please choose barber');
  483. }
  484. return;
  485. }
  486. break;
  487. case 4 :
  488. console.log(phase);
  489. break;
  490. }
  491. if($scope.phase!=4 && $scope.phase!=5){
  492. $scope.phase+=1;
  493. }
  494. console.log($scope.phase);
  495. //$scope.modalproduct.show();
  496. }
  497. $scope.cancel_product=function(){
  498. $scope.belum_pilih_product=false;
  499. $scope.code_product="";
  500. $scope.c_product={};
  501. $scope.c_product.price=$scope.c_product.price!=undefined ? $scope.c_product.price : 0;
  502. $scope.total_order=parseInt($scope.c_product.price)+parseInt($scope.c_service.price);
  503. console.log($scope.total_order);
  504. $scope.product.forEach(function (item, i) {
  505. item.check = false;
  506. });
  507. }
  508. $scope.go_back=function(phase){
  509. if(phase==1){
  510. $scope.phase=1;
  511. $rootScope.goroothome();
  512.  
  513. }else if(phase==5){
  514. if($scope.status_submit==true){
  515. $state.go('history');
  516. $rootScope.$broadcast('refresh.history');
  517. $scope.phase=1;
  518. $scope.total_order=0;
  519. $scope.status_submit=false;
  520. $scope.c_barber={}
  521. $scope.code_barber="";
  522. $scope.c_service={};
  523. $scope.code_product="";
  524. $scope.c_product={};
  525. $scope.code_service=false;
  526. $scope.c_store={};
  527. $scope.code_booking="";
  528. $scope.pilihstore="";
  529. $scope.belum_pilih_product=false;
  530. $scope.product.forEach(function (item, i) {
  531. item.check = false;
  532. });
  533. $scope.service.forEach(function (item, i) {
  534. item.check = false;
  535. });
  536. $scope.barber.forEach(function (item, i) {
  537. item.check = false;
  538. });
  539. $scope.time={};
  540. //Myform.$setPristine();
  541. }else{
  542. $scope.next_service(phase-2);
  543. }
  544. }else{
  545. $scope.next_service(phase-2);
  546. }
  547. }
  548. $scope.next_barber=function(){
  549. if($scope.code_product==""){
  550. if($localstorage.get('is_device')!=undefined){
  551. $cordovaToast.show('Please Choose Product', 'long', 'center')
  552. }else{
  553. alert('Please Choose Product');
  554. }
  555. return;
  556. }
  557. $scope.modalproduct.hide();
  558. //$state.go('history');
  559. $scope.modalbarber.show();
  560. }
  561. $scope.next_timebooking=function(){
  562.  
  563. if($scope.code_barber==""){
  564. if($scope.code_barber==""){
  565. if($localstorage.get('is_device')!=undefined){
  566. $cordovaToast.show('Please choose barber', 'short', 'center')
  567. }else{
  568. alert('Please Choose Barber');
  569. }
  570. return;
  571. }
  572. return;
  573. }
  574. $scope.modalbarber.hide();
  575. $scope.modaltimebooking.show();
  576.  
  577. }
  578. $scope.next_submitbooking=function(form){
  579. console.log(form.$valid);
  580.  
  581. if(!form.$valid) return false;
  582. Myform=form;
  583. $scope.next_service(5);
  584. //console.log(form.$valid);
  585. //$scope.modaltimebooking.hide();
  586. //$state.go('history', {param:'booking'});
  587. //$scope.submitbooking.show();
  588. }
  589. $scope.$on('modal.hidden', function(e) {
  590. // $scope.submitbooking.remove();
  591. // $scope.modaltimebooking.remove();
  592. // $scope.modalproduct.remove();
  593. // $scope.modalbarber.remove();
  594. });
  595. $ionicModal.fromTemplateUrl('templates/productbooking.html', {
  596. scope: $scope,
  597. cssClass:'ModalProduct',
  598. }).then(function(modal) {
  599. $scope.modalproduct = modal;
  600. });
  601. $ionicModal.fromTemplateUrl('templates/barberbooking.html', {
  602. scope: $scope,
  603. cssClass:'ModalProduct',
  604. }).then(function(modal) {
  605. $scope.modalbarber = modal;
  606. });
  607. $ionicModal.fromTemplateUrl('templates/timebooking.html', {
  608. scope: $scope,
  609. cssClass:'ModalProduct',
  610. }).then(function(modal) {
  611. $scope.modaltimebooking = modal;
  612. });
  613. $ionicModal.fromTemplateUrl('templates/submitbooking.html', {
  614. scope: $scope,
  615. cssClass:'ModalProduct',
  616. }).then(function(modal) {
  617. $scope.submitbooking = modal;
  618. });
  619.  
  620. $scope.$on('$destroy', function() {
  621. $scope.popover.remove();
  622. // $scope.submitbooking.remove();
  623. // $scope.modaltimebooking.remove();
  624. // $scope.modalproduct.remove();
  625. // $scope.modalbarber.remove();
  626. });
  627.  
  628. $scope.key="3";
  629. var template =
  630. '<ion-popover-view style="margin-top:10px;"><ion-content style="height:auto;" >'+
  631. '<div class="list"><a class="item" ng-click="pilih_store(item)" ng-repeat="item in data.airlines | toArray:false | filter:time.store" ><h2>{{item.name_store}}</h2><p>{{time.address}}</p></></div>'+
  632. '</ion-content></ion-popover-view>';
  633.  
  634. $scope.popover = $ionicPopover.fromTemplate(template, {
  635. scope: $scope
  636. });
  637. var searchAirlines = function(searchFilter) {
  638.  
  639. console.log('Searching airlines for ' + searchFilter);
  640.  
  641. var deferred = $q.defer();
  642.  
  643. var matches = $scope.stores.filter( function(airline) {
  644. if(airline.name_store.toLowerCase().indexOf(searchFilter.toLowerCase()) !== -1 ) return true;
  645. })
  646.  
  647. $timeout( function(){
  648.  
  649. deferred.resolve( matches );
  650.  
  651. }, 100);
  652.  
  653. return deferred.promise;
  654.  
  655. };
  656. $scope.data = { "airlines" : [], "search" : '' };
  657.  
  658. $scope.pilih_store=function(data){
  659. //data=$scope.pilihstore;
  660. console.log(data);
  661. $scope.code_store=data.code_store;
  662. $scope.c_store=data;
  663. $scope.time.store=data.name_store;
  664. //console.log(data);
  665. $scope.popover.hide();
  666. }
  667.  
  668. $scope.search = function($event) {
  669. $scope.time.store = $scope.time.store!=undefined ? $scope.time.store : '';
  670. if($scope.time.store!=''){
  671. $scope.popover.show(document.querySelector('.keystore'));
  672. searchAirlines($scope.time.store).then(
  673. function(matches) {
  674. console.log(matches);
  675. $scope.data.airlines = matches;
  676. }
  677. )
  678. }else{
  679. $scope.popover.hide();
  680. $scope.data.airlines=[];
  681. }
  682. //}
  683. console.log($scope.data.airlines);
  684. }
  685.  
  686. $scope.submit_booking=function(){
  687. $ionicLoading.show();
  688. $http.post(rest_url+'submit_booking',
  689. {
  690. //email:$rootScope.datauserlogin.email,
  691. email:$localstorage.get('email'),
  692. code_barber:$scope.c_barber.code_barber,
  693. code_product:$scope.c_product.code_product,
  694. code_service:$scope.c_service.code_service,
  695. date_booking:$scope.time.date_booking,
  696. time_booking:$scope.time.time_booking,
  697. code_store:$scope.c_store.code_store,
  698. price_service:$scope.c_service.price,
  699. price_product:$scope.c_product.price,
  700. total:$scope.total_order,
  701. time_service:$scope.c_service.time_estimation
  702. }
  703. ).success(function(dats){
  704. //$scope.status_submit=true;
  705. $ionicLoading.hide();
  706. if(dats.code==1){
  707. $scope.code_booking=dats.code_booking;
  708. $scope.status_submit=true;
  709. }if(dats.code==3){
  710. if($scope.code_barber==""){
  711. if($localstorage.get('is_device')!=undefined){
  712. $cordovaToast.show(dats.msg, 'long', 'center')
  713. }else{
  714. alert(dats.msg);
  715. }
  716. return;
  717. }
  718. $rootScope.logout();
  719. }else{
  720. //alert(dats.msg);
  721. }
  722. }).error(function(data){
  723. $ionicLoading.hide();
  724. if($scope.code_barber==""){
  725. if($localstorage.get('is_device')!=undefined){
  726. $cordovaToast.show('Sorry system fail, please try again', 'short', 'center')
  727. }else{
  728. alert('Sorry System was Failure, please try again later');
  729. }
  730. return;
  731. }
  732. });
  733. }
  734. $scope.clear_booking=function(){
  735. $scope.submitbooking.hide(true);
  736. $scope.modaltimebooking.hide(true);
  737. $scope.modalproduct.hide(true);
  738. $scope.modalbarber.hide(true);
  739. $state.go('history');
  740. /* $scope.total_order=0;
  741. $scope.status_submit=false;
  742. $scope.c_barber={}
  743. $scope.code_barber="";
  744. $scope.c_service={};
  745. $scope.code_product="";
  746. $scope.c_product={};
  747. $scope.code_service="";
  748. $scope.c_store={};
  749. $scope.code_booking=""; */
  750.  
  751. // $state.go($state.current, {}, {reload: true});
  752. }
  753. })
  754. .directive("extSubmit", ['$timeout',function($timeout){
  755. return {
  756. link: function($scope, $el, $attr) {
  757.  
  758. $scope.$on('makeSubmit', function(event, data){
  759. console.log($attr.name);
  760. console.log($el);
  761. if(data.formName === $attr.name) {
  762. console.log('benar');
  763. $timeout(function() {
  764. $el.triggerHandler('submit'); //<<< This is Important
  765. //$el[0].dispatchEvent(new Event('submit')) //equivalent with native event
  766. }, 0, false);
  767. }
  768. })
  769. }
  770. };
  771. }])
  772. .controller('LoginCtrl', function($scope, $state, $cordovaToast, Firebase, Auth, $http,$localstorage, $ionicLoading, $rootScope) {
  773. $scope.user={};
  774. $scope.datauser={};
  775.  
  776. $rootScope.loginyuk=function(vvvv, type){
  777. $ionicLoading.hide();
  778. $localstorage.set('status', '');
  779. $http.post(rest_url+'login', {param:vvvv})
  780. .success(function(data3){
  781. if(data3.code==4){
  782. // if(type=='firebase'){
  783. // alert(data3.msg);
  784. // $localstorage.set('status', 'tidak.aktif');
  785. // }else
  786. if(type=='register'){
  787. if($localstorage.get('is_device')!=undefined){
  788. $cordovaToast.show(data3.msg, 'long', 'center');
  789. }else{
  790. alert(data3.msg);
  791. }
  792. }else{
  793. if($localstorage.get('is_device')!=undefined){
  794. $cordovaToast.show(data3.msg, 'long', 'center');
  795. }else{
  796. alert(data3.msg);
  797. }
  798. }
  799. $rootScope.logout();
  800. }else if(data3.code==1){
  801. if(type=='register'){
  802. if($localstorage.get('is_device')!=undefined){
  803. $cordovaToast.show(data3.msg, 'long', 'center');
  804. }else{
  805. alert(data3.msg);
  806. }
  807. $rootScope.logout();
  808. }else
  809. $localstorage.set('status', 'aktif');
  810. $localstorage.set('email', data3.user[0].email);
  811. $localstorage.set('login', 'true');
  812. $localstorage.set('name_customer', data3.user[0].name_customer);
  813. $localstorage.set('phone', data3.user[0].phone);
  814. $localstorage.set('photo', data3.user[0].photo);
  815. inifoto=data3.user[0].photo;
  816. $localstorage.set('join_by', data3.user[0].join_by);
  817. $rootScope.checkdevice();
  818. $rootScope.$broadcast('gantiphoto', {photo:data3.user[0].photo});
  819. $state.go('eventmenu.home');
  820. $rootScope.cekpesan();
  821. // }
  822. }
  823. //}
  824. });
  825. }
  826. $rootScope.checkdevice=function(){
  827. console.log('device');
  828. $http.post(rest_url+'daftar_device_token', {token : $localstorage.get('device_token'), email : $localstorage.get('email'), 'type': 'check'})
  829. .success(function(data){
  830. // if(data.code==1){
  831. // $localstorage.set('device_token', token);
  832. // }
  833. });
  834. }
  835. $rootScope.cekpesan=function(){
  836. console.log($localstorage.get('adapesan'));
  837. console.log($localstorage.getObject('pesannya'));
  838.  
  839. if($localstorage.get('adapesan')=='ada' && $localstorage.get('login')=='true'){
  840. if($localstorage.getObject('pesannya').type=='popup'){
  841. $ionicPopup.alert({
  842. title:$localstorage.getObject('pesannya').title,
  843. template:'<div style="text-align:justify">'+$localstorage.getObject('pesannya').message+'</div>'
  844. }).then(function(){
  845. if($localstorage.getObject('pesannya').state!=""){
  846. $state.go($localstorage.getObject('pesannya').state);
  847. $localstorage.set('adapesan', 'tidak')
  848. }
  849. });
  850. }else{
  851. $rootScope.$broadcast('refresh.'+$localstorage.getObject('pesannya').state);
  852. if($localstorage.getObject('pesannya').state!=undefined){
  853. $state.go($localstorage.getObject('pesannya').state);
  854. }
  855. $localstorage.set('adapesan', 'tidak')
  856. }
  857. }
  858. }
  859. $scope.login_email = function(form) {
  860. if(!form.$valid) return;
  861. $ionicLoading.show();
  862. Auth.$signInWithEmailAndPassword($scope.user.email, "maricoy")
  863. .then(function(authData) {
  864. }).catch(function(error) {
  865. if(error.code=='auth/user-not-found'){
  866. Auth.$createUserWithEmailAndPassword($scope.user.email, "maricoy")
  867. .then(function(data) {
  868. }).catch(function(error) {
  869. });
  870. }
  871. });
  872. $scope.datauser.join_by='email';
  873. $scope.user.type='login';
  874. $rootScope.loginyuk($scope.user);
  875. }
  876.  
  877.  
  878. $scope.login_fb=function(){
  879. openFB.login(
  880. function (response) {
  881. console.log(response);
  882. if (response.status === 'connected') {
  883. $ionicLoading.show();
  884.  
  885. //console.log('Facebook login succeeded', response);
  886. openFB.api({path: '/me', success: function(data){
  887. $scope.datauser=data;
  888. console.log(data);
  889. $scope.datauser.join_by='facebook';
  890. openFB.api({
  891. path: '/me/picture/',
  892. params: {redirect:false, type:'small'},
  893. success: function(data2) {
  894. $scope.datauser.poto=data2.data.url;
  895. $rootScope.loginyuk($scope.datauser);
  896. }
  897. });
  898. }});
  899. var credential = firebase.auth.FacebookAuthProvider.credential(
  900. response.authResponse.accessToken);
  901. Auth.$signInWithCredential(credential).catch(function (error) {
  902. });
  903. } else {
  904. $ionicLoading.hide();
  905. }
  906. }
  907. );
  908. }
  909. //var flaglogin=false;
  910.  
  911. // $rootScope.ceklogin2=function(){
  912. // console.log($localstorage.get('name_customer'));
  913. // console.log($localstorage.get('phone'));
  914. // console.log($localstorage.get('email'));
  915. // console.log($localstorage.get('photo'));
  916. // console.log($localstorage.get('join_by'));
  917. // console.log($localstorage.get('login'));
  918. // console.log($localstorage.get('status'));
  919. // if($localstorage.get('login')=='true'){
  920. // console.log('a');
  921. // $state.go('eventmenu.home');
  922. // }else{
  923. // console.log('b');
  924. // $state.go('login');
  925. // }
  926. // }
  927. $scope.go_register=function(){
  928. $state.go('register');
  929. }
  930.  
  931. })
  932.  
  933. .controller('AccountCtrl', function($scope) {
  934. $scope.settings = {
  935. enableFriends: true
  936. };
  937. })
  938.  
  939. .controller('StoreDetailCtrl', function($scope, $stateParams, $compile, Chats) {
  940. /* function initialize() {
  941. var myLatlng = new google.maps.LatLng(43.07493,-89.381388);
  942.  
  943. var mapOptions = {
  944. center: myLatlng,
  945. zoom: 16,
  946. mapTypeId: google.maps.MapTypeId.ROADMAP
  947. };
  948. var map = new google.maps.Map(document.getElementById("map"),
  949. mapOptions);
  950.  
  951. //Marker + infowindow + angularjs compiled ng-click
  952. var contentString = "<div><a ng-click='clickTest()'>Click me!</a></div>";
  953. var compiled = $compile(contentString)($scope);
  954.  
  955. var infowindow = new google.maps.InfoWindow({
  956. content: compiled[0]
  957. });
  958.  
  959. var marker = new google.maps.Marker({
  960. position: myLatlng,
  961. map: map,
  962. title: 'Uluru (Ayers Rock)'
  963. });
  964.  
  965. google.maps.event.addListener(marker, 'click', function() {
  966. infowindow.open(map,marker);
  967. });
  968.  
  969. $scope.map = map;
  970. }
  971. google.maps.event.addDomListener(window, 'load', initialize);
  972.  
  973. $scope.centerOnMe = function() {
  974. if(!$scope.map) {
  975. return;
  976. }
  977.  
  978. $scope.loading = $ionicLoading.show({
  979. content: 'Getting current location...',
  980. showBackdrop: false
  981. });
  982.  
  983. navigator.geolocation.getCurrentPosition(function(pos) {
  984. $scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
  985. $scope.loading.hide();
  986. }, function(error) {
  987. alert('Unable to get location: ' + error.message);
  988. });
  989. }; */
  990. $scope.user=Chats.get($stateParams.id);
  991. //console.log($scope.data);
  992. $scope.clickTest = function() {
  993. alert('Example of infowindow with ng-click')
  994. };
  995. })
  996. .controller('RegisterCtrl', function($scope, $ionicLoading, Firebase, $localstorage, Auth, $state, $cordovaToast, $rootScope, $http) {
  997. $scope.user={};
  998.  
  999. // form={email:$scope.user.email, password:$scope.user.password};
  1000. $scope.register=function(form){
  1001.  
  1002. $scope.error="";
  1003. if(form.$error.compareTo){
  1004. $scope.error="Re Password didn't match to password";
  1005. }
  1006. if(!form.$valid) return;
  1007. $ionicLoading.show();
  1008. $scope.user.join_by='email';
  1009. $scope.user.type='register';
  1010. $http.post(rest_url+'login', {param:$scope.user})
  1011. .success(function(data){
  1012. $ionicLoading.hide();
  1013. if(data.code==1){
  1014. $scope.user={};
  1015. form.$setPristine(true);
  1016. if($localstorage.get('is_device')!=undefined){
  1017. $cordovaToast.show(data.msg, 'long', 'center').then(function(){
  1018. $rootScope.logout();
  1019. });
  1020. }else{
  1021. alert(data.msg);
  1022. $rootScope.logout();
  1023. }
  1024. }else{
  1025. if($localstorage.get('is_device')!=undefined){
  1026. $cordovaToast.show(data.msg, 'long', 'center').then(function(){
  1027. $rootScope.logout();
  1028. });
  1029. }else{
  1030. alert(data.msg);
  1031. $rootScope.logout();
  1032. }
  1033.  
  1034. }
  1035. }).error(function(){
  1036. $ionicLoading.hide();
  1037. });
  1038. Auth.$createUserWithEmailAndPassword($scope.user.email, "maricoy")
  1039. .then(function(data) {
  1040. }).catch(function(error) {
  1041. });
  1042. }
  1043. })
  1044. .controller('ForgotCtrl', function($scope, Auth, Firebase, $state, $localstorage, $ionicLoading, $cordovaToast, $rootScope, $http) {
  1045. $scope.user={};
  1046. $scope.error="";
  1047. // form={email:$scope.user.email, password:$scope.user.password};
  1048. $scope.forgotpassword=function(form){
  1049.  
  1050. if(form.$error.compareTo){
  1051. $scope.error="Re Password didn't match to password";
  1052. }
  1053. if(!form.$valid) return;
  1054. $ionicLoading.show();
  1055. $http.post(rest_url+'reset_password', {param:$scope.user})
  1056. .success(function(data){
  1057. $ionicLoading.hide();
  1058. if(data.code=='1'){
  1059. $scope.user={};
  1060. form.$setPristine(true);
  1061. if($localstorage.get('is_device')!=undefined){
  1062. $cordovaToast.show(data.msg, 'long', 'center').then(function(){ $state.go('login') });
  1063. }else{
  1064. alert(data.msg);
  1065. $state.go('login');
  1066. }
  1067. }else{
  1068. if($localstorage.get('is_device')!=undefined){
  1069. $cordovaToast.show(data.msg, 'long', 'center');
  1070. }else{
  1071. alert(data.msg);
  1072. }
  1073. }
  1074. }).error(function(){
  1075. $ionicLoading.hide();
  1076. });
  1077.  
  1078. // firebase.auth().sendPasswordResetEmail($scope.user.email).then(function(data) {
  1079. // alert('Please check your email, and click link reset email');
  1080. // $state.go('login');
  1081. // }).catch(function(error) {
  1082. // console.log(error);
  1083. // $scope.error=error.message;
  1084. // });
  1085. }
  1086. })
  1087. .controller('HistoryCtrl', function($scope, $rootScope, $ionicLoading, $stateParams, $state, $cordovaToast, $http, $localstorage) {
  1088.  
  1089. $scope.shistory={};
  1090. $scope.url=base_url;
  1091. //$email=$rootScope.datauserlogin.email;
  1092. $email=$localstorage.get('email');
  1093. $scope.get_history=function(){
  1094. $ionicLoading.show();
  1095. $http.post(rest_url+'get_history', {email:$email})
  1096. .success(function(data){
  1097. $scope.shistory=data;
  1098. $ionicLoading.hide();
  1099. }).error(function(data){
  1100. $ionicLoading.hide();
  1101. if($localstorage.get('is_device')!=undefined){
  1102. $cordovaToast.show('System fail, please try again later', 'long', 'center');
  1103. }else{
  1104. alert('System fail, please try again later');
  1105. }
  1106. });
  1107. }
  1108. $scope.get_history();
  1109. $rootScope.$on('refresh.history', function(){
  1110. $scope.get_history();
  1111. });
  1112. })
  1113. .controller('StoreCtrl', function($scope, $rootScope, $ionicLoading, $state, $cordovaToast, $http, $localstorage, $ionicModal, $sce, $compile) {
  1114. $scope.store={};
  1115. $scope.url=base_url;
  1116. //$email=$rootScope.datauserlogin.email;
  1117. $email=$localstorage.get('email');
  1118. $scope.get_store=function(){
  1119. $ionicLoading.show();
  1120. $http.post(rest_url+'get_store', {})
  1121. .success(function(data){
  1122. $scope.store=data;
  1123. $ionicLoading.hide();
  1124. }).error(function(data){
  1125. $ionicLoading.hide();
  1126. if($localstorage.get('is_device')!=undefined){
  1127. $cordovaToast.show('System fail, please try again later', 'long', 'center');
  1128. }else{
  1129. alert('System fail, please try again later');
  1130. }
  1131. });
  1132. }
  1133. $scope.get_store();
  1134. $rootScope.$on('refresh.history', function(){
  1135. $scope.get_store();
  1136. });
  1137. $scope.show_detail=function(data){
  1138. console.log('bc');
  1139. $scope.det=data;
  1140. $scope.modalstore.show();
  1141. function initialize() {
  1142. var myLatlng = new google.maps.LatLng(data.latitude,data.longitude);
  1143. // -6.2940106,
  1144.  
  1145. var mapOptions = {
  1146. center: myLatlng,
  1147. zoom: 16,
  1148. mapTypeId: google.maps.MapTypeId.ROADMAP
  1149. };
  1150. var map = new google.maps.Map(document.getElementById("map"),
  1151. mapOptions);
  1152.  
  1153. //Marker + infowindow + angularjs compiled ng-click
  1154. var contentString = "<div><a ng-click='clickTest()'>Click me!</a></div>";
  1155. var compiled = $compile(contentString)($scope);
  1156.  
  1157. var infowindow = new google.maps.InfoWindow({
  1158. content: compiled[0]
  1159. });
  1160.  
  1161. var marker = new google.maps.Marker({
  1162. position: myLatlng,
  1163. map: map,
  1164. title: ''
  1165. });
  1166.  
  1167. google.maps.event.addListener(marker, 'click', function() {
  1168. infowindow.open(map,marker);
  1169. });
  1170.  
  1171. $scope.map = map;
  1172. }
  1173. console.log(initialize());
  1174. google.maps.event.addDomListener(window, 'load', initialize); //$scope.det.src=$sce.trustAsResourceUrl("https://www.google.com/maps/embed/v1/view?key=AIzaSyAK_5oFa-BhzWjdBvbVy_909rrQDX9Chhg&center="+data.latitude+","+data.longitude+"&zoom=15");
  1175. }
  1176. $ionicModal.fromTemplateUrl('templates/store-detail.html', {
  1177. scope: $scope,
  1178. cssClass:'ModalProduct',
  1179. }).then(function(modal) {
  1180. $scope.modalstore = modal;
  1181. });
  1182. })
  1183. .controller('BarberDetailCtrl', function($scope, $stateParams) {
  1184. //console.log($stateParams.id_barber);
  1185. $scope.user = { name:'fadli', profile : 'fadli adalah orang yang sangat bagus sekali dalam menjalankan perintah atasan ', img : 'img/perry.png' }
  1186. })
  1187. .controller('BarberCtrl', function($ionicLoading, $scope, $http, $ionicModal, $rootScope, $state) {
  1188. $scope.barber={};
  1189. $scope.url=base_url;
  1190. $scope.user={};
  1191. $scope.get_barber=function(){
  1192. $ionicLoading.show();
  1193. $http.post(rest_url+'get_barber', {})
  1194. .success(function(data){
  1195. $ionicLoading.hide();
  1196. $scope.barber=data;
  1197. });
  1198. }
  1199. $scope.get_barber();
  1200. $scope.rating = {};
  1201. $scope.rating.rate = 3;
  1202. $scope.rating.max = 5;
  1203. $scope.detail_barber=function(data){
  1204. $scope.user=data;
  1205. $scope.modalbarber.show();
  1206. $scope.rating.rate=data.total_star;
  1207. }
  1208. $ionicModal.fromTemplateUrl('templates/barber-detail.html', {
  1209. scope: $scope,
  1210. cssClass:'ModalProduct',
  1211. }).then(function(modal) {
  1212. $scope.modalbarber = modal;
  1213. });
  1214. $rootScope.$on('refresh.barber', function(){
  1215. $scope.get_barber();
  1216. });
  1217. })
  1218. .controller('ProductCtrl', function($scope, $ionicLoading, $http, $ionicModal,$rootScope, $state) {
  1219. $scope.product={};
  1220. $scope.url=base_url;
  1221. $scope.get_product=function(){
  1222. $ionicLoading.show();
  1223. $http.post(rest_url+'get_product', {})
  1224. .success(function(data){
  1225. $ionicLoading.hide();
  1226. $scope.product=data;
  1227. });
  1228. }
  1229. $scope.get_product();
  1230. $rootScope.$on('refresh.product', function(){
  1231. $scope.get_product();
  1232. });
  1233. $ionicModal.fromTemplateUrl('templates/product-detail.html', {
  1234. scope: $scope
  1235. }).then(function(modal) {
  1236. $scope.modalproduct = modal;
  1237. });
  1238. $scope.show_product=function(data){
  1239. $scope.det=data;
  1240. $scope.modalproduct.show();
  1241. }
  1242. })
  1243. .controller('GalleryCtrl', function($scope, $ionicLoading, $rootScope, $http, $ionicModal, $state) {
  1244. $scope.gallery={};
  1245. $scope.url=base_url;
  1246. $scope.get_gallery=function(){
  1247. $ionicLoading.show();
  1248. $http.post(rest_url+'get_gallery', {})
  1249. .success(function(data){
  1250. $scope.gallery=data;
  1251. $ionicLoading.hide();
  1252. });
  1253. }
  1254. $scope.get_gallery();
  1255. $rootScope.$on('refresh.history', function(){
  1256. $scope.get_gallery();
  1257. });
  1258.  
  1259. $scope.showImages = function(index) {
  1260. $scope.activeSlide = index;
  1261. $scope.showModal('templates/imagepop.html');
  1262. }
  1263.  
  1264. $scope.showModal = function(templateUrl) {
  1265. $ionicModal.fromTemplateUrl(templateUrl, {
  1266. scope: $scope,
  1267. animation: 'slide-in-up'
  1268. }).then(function(modal) {
  1269. $scope.modal = modal;
  1270. $scope.modal.show();
  1271. });
  1272. }
  1273.  
  1274. // Close the modal
  1275. $scope.closeModal = function() {
  1276. $scope.modal.hide();
  1277. $scope.modal.remove()
  1278. };
  1279.  
  1280. })
  1281. .controller('ProductDetailCtrl', function($scope, $http, $ionicLoading, $rootScope, $state) {
  1282. })
  1283. .controller('HelpCtrl', function($scope, $http, $rootScope, $ionicLoading, $state) {
  1284. $scope.help={};
  1285. $scope.url=base_url;
  1286. $scope.get_help=function(){
  1287. $ionicLoading.show();
  1288. $http.post(rest_url+'get_config', {type:'help'})
  1289. .success(function(data){
  1290. $scope.help=data[0];
  1291. $ionicLoading.hide();
  1292. });
  1293. }
  1294. $scope.goLogin=function(){
  1295. $state.go('login');
  1296. }
  1297. $scope.get_help();
  1298. $rootScope.$on('refresh.help', function(){
  1299. $scope.get_help();
  1300. });
  1301. })
  1302. .controller('AboutCtrl', function($scope, $http, $rootScope, $ionicLoading, $state) {
  1303. $scope.about={};
  1304. $scope.url=base_url;
  1305. $scope.get_about=function(){
  1306. $ionicLoading.show();
  1307. $http.post(rest_url+'get_config', {type:'about'})
  1308. .success(function(data){
  1309. $scope.about=data[0];
  1310. $ionicLoading.hide();
  1311. });
  1312. }
  1313. $scope.get_about();
  1314. $rootScope.$on('refresh.about', function(){
  1315. $scope.get_about();
  1316. });
  1317. })
  1318. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement