Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- openFB.init({appId: '522196301254895'});
- angular.module('starter.controllers', ['ionic', 'firebase', 'ionic.rating', 'ngCordova'])
- .factory('formDataObject', function() {
- return function(data) {
- var fd = new FormData();
- angular.forEach(data, function(value, key) {
- if(key == "file"){
- fd.append(key, new Blob([ value ], { type: "image/jpeg" }),"image.jpeg");
- }else{
- fd.append(key, value);
- }
- });
- return fd;
- };
- }).factory('fileReader', function($q) {
- return {
- readAsDataUrl: function(filePath) {
- var deferred = $q.defer();
- function gotFileEntry(fileEntry) {
- fileEntry.file(gotFile, fail);
- }
- function gotFile(file){
- readDataUrl(file);
- }
- function readDataUrl(file) {
- var reader = new FileReader();
- reader.onloadend = function(evt) {
- console.log("Read as data URL");
- fileContent = evt.target.result;
- deferred.resolve(fileContent);
- };
- reader.readAsArrayBuffer(file);
- }
- function fail(evt) {
- console.log(evt.target.error.code);
- }
- // window.resolveLocalFileSystemURI(filePath, gotFileEntry, fail);
- window.resolveLocalFileSystemURL(filePath, gotFileEntry, fail);
- return deferred.promise;
- }
- };
- })
- .factory('chek_image_url', function($q) {
- return {
- chek : function(src) {
- var deferred = $q.defer();
- var image = new Image();
- image.onerror = function() {
- deferred.resolve(false);
- };
- image.onload = function() {
- deferred.resolve(true);
- };
- image.src = src;
- return deferred.promise;
- }
- }
- })
- .controller('MainCtrl', function($scope, $http, $rootScope, chek_image_url, $q, $state, $cordovaToast, $rootScope, $ionicModal, $ionicPopup, $ionicLoading, $localstorage, formDataObject, $cordovaCamera, fileReader, $ionicSideMenuDelegate, Firebase, $ionicPopup) {
- console.log($localstorage.get('is_device'));
- $ionicLoading.hide();
- $scope.gambar = "";
- $scope.ambil_gambar=false;
- $scope.photo="";
- $scope.cekphoto=function(){
- console.log($localstorage.get('photo'));
- console.log(1);
- if($localstorage.get('join_by')=='facebook'){
- console.log(2);
- $scope.photo=$localstorage.get('photo');
- console.log($scope.photo);
- }else{
- $scope.photo=base_url+'photo_barber/'+$localstorage.get('photo');
- }
- chek_image_url.chek($scope.photo).then(function(test) {
- if(test){
- $scope.photo=$scope.photo;
- }else{
- $scope.photo="";
- }
- });
- }
- $scope.$on( "$ionicView.enter", function( scopes, states ) {
- console.log($localstorage.get('login')=='false');
- $scope.cekphoto();
- });
- $rootScope.$on('gantiphoto', function(e, data){
- $scope.cekphoto();
- });
- $rootScope.$on('devtoken', function(){
- $rootScope.checkdevice();
- });
- $rootScope.$on('adapesan2', function(){
- $rootScope.cekpesan();
- });
- $scope.pop;
- $scope.openModal = function() {
- $scope.pop=$ionicPopup.show({
- title:'Edit Photo',
- template:'<center><label><button class="button" ng-click="openPhotoLibrary();" ><i class="icon ion-images" ></i></button></label> '+
- '<label><button class="button" ng-click="takePicture();"><i class="icon ion-android-camera" ></i></button></label></center>',
- scope:$scope,
- buttons: [
- {
- text: 'Cancel',
- type: 'button-positive'
- }
- ]
- });
- };
- $scope.simpan_photo=function(){
- $ionicLoading.show();
- if($scope.ambil_gambar){
- fileReader.readAsDataUrl($scope.gambar).then(function(fileInfo) {
- ////console.log(fileInfo);
- return $http({
- method: 'POST',
- url: rest_url+'edit_photo',
- headers: {
- 'Content-Type':undefined,
- //'Authorization': 'Basic ' + btoa("user:password")
- },
- data: {
- file: fileInfo,
- email:$localstorage.get('email'),
- },
- transformRequest: formDataObject
- })
- .success(function(data, status, headers, config) {
- $ionicLoading.hide();
- $scope.pop.close();
- if(data.code=='1'){
- $localstorage.set('photo', data.photo);
- $rootScope.$broadcast('gantiphoto', data.photo);
- }else{
- }
- })
- .error(function(data, status, headers, config) {
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show('Sorry system fail, please try again', 'long', 'center')
- }else{
- alert('Sorry system fail, please try again');
- }
- $ionicLoading.hide();
- $scope.pop.close();
- });
- }, function(err) {
- });
- }
- }
- $scope.openPhotoLibrary = function() {
- var options = {
- quality: 75,
- destinationType: Camera.DestinationType.FILE_URI,
- sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
- allowEdit: true,
- encodingType: Camera.EncodingType.JPEG,
- targetWidth: 300,
- targetHeight: 300,
- popoverOptions: CameraPopoverOptions,
- saveToPhotoAlbum: false
- };
- $cordovaCamera.getPicture(options).then(function (imageData) {
- ////console.log(imageData);
- $scope.gambar = imageData;
- $scope.ambil_gambar=true;
- $scope.simpan_photo();
- }, function (err) {
- ////console.log(err);
- });
- }
- $scope.takePicture = function() {
- //alert('ambil gambar');
- var options = {
- quality: 75,
- destinationType: Camera.DestinationType.FILE_URI,
- sourceType: Camera.PictureSourceType.CAMERA,
- allowEdit: true,
- encodingType: Camera.EncodingType.JPEG,
- targetWidth: 300,
- targetHeight: 300,
- popoverOptions: CameraPopoverOptions,
- saveToPhotoAlbum: false
- };
- /* var options = {
- quality: 75,
- destinationType: Camera.DestinationType.FILE_URL,
- sourceType: Camera.PictureSourceType.CAMERA,
- allowEdit: true,
- encodingType: Camera.EncodingType.JPEG,
- popoverOptions: CameraPopoverOptions,
- saveToPhotoAlbum: false
- }; */
- $cordovaCamera.getPicture(options).then(function(imageData) {
- $scope.gambar= imageData;
- $scope.ambil_gambar=true;
- $scope.simpan_photo();
- }, function(err) {
- // error
- //////console.log(err);
- });
- }
- $rootScope.goparent=function(){
- stat=$state.current.name;
- if(stat=='newsdetail') $state.go('news');
- if(stat=='storedetail') $state.go('store');
- }
- $scope.$watch(function () {
- return $ionicSideMenuDelegate.isOpen();
- },
- function (isOpen) {
- if (isOpen){
- //console.log("open");
- $rootScope.menu_open=false;
- }else{
- //console.log('close');
- $rootScope.menu_open=true;
- }
- });
- $rootScope.menu_open=true;
- $scope.go_setting=function(){
- $state.go('setting');
- }
- $scope.toggleLeft = function() {
- $ionicSideMenuDelegate.toggleLeft();
- };
- $scope.goto=function(state){
- $state.go(state);
- }
- })
- .controller('NewsCtrl', function($scope, $rootScope, $http, $ionicModal, $ionicLoading, $state) {
- $scope.news={};
- $scope.newsd={};
- $scope.url=base_url;
- $scope.get_news=function(){
- $ionicLoading.show();
- $http.post(rest_url+'get_news', {})
- .success(function(data){
- $ionicLoading.hide();
- $scope.news=data;
- });
- }
- $scope.get_news();
- $rootScope.$on('refresh.news', function(){
- $scope.get_news();
- });
- $ionicModal.fromTemplateUrl('templates/news-detail.html', {
- scope: $scope,
- cssClass:'ModalProduct',
- }).then(function(modal) {
- $scope.modalnewsdetail = modal;
- });
- $scope.show_berita=function(data){
- $scope.newsd=data;
- $scope.modalnewsdetail.show();
- }
- })
- .controller('SettingCtrl', function($rootScope, $state, $cordovaToast, $http, $ionicLoading, $scope, $localstorage, Firebase, Auth) {
- if($localstorage.get('email')==undefined){
- $rootScope.logout();
- }
- $scope.user={};
- $scope.$on( "$ionicView.enter", function( scopes, states ) {
- $scope.user.email=$localstorage.get('email');
- $scope.user.phone=parseInt($localstorage.get('phone'));
- $scope.user.name_customer=$localstorage.get('name_customer');
- });
- $scope.register=function(form){
- $scope.error="";
- if(form.$error.compareTo){
- $scope.error="Re Password didn't match to password";
- }
- if(!form.$valid){
- return false;
- }
- $ionicLoading.show();
- //var user = firebase.auth().currentUser;
- //Auth.$updatePassword($scope.user.password).then(function() {
- $http.post(rest_url+'update_user', {data: $scope.user})
- .success(function(data){
- $ionicLoading.hide();
- if(data.code==1){
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show(data.msg, 'long', 'center')
- }else{
- alert(data.msg);
- }
- form.$setPristine(true);
- $localstorage.set('name_customer', data.user[0].name_customer);
- $localstorage.set('phone', data.user[0].phone);
- $scope.user.phone=parseInt($localstorage.get('phone'));
- $scope.user.name_customer=$localstorage.get('name_customer');
- $scope.user.password="";
- $scope.user.repassword="";
- }
- })
- .error(function(data){
- $ionicLoading.hide();
- });
- //}, function(error) {
- //console.log(error.message);
- // $scope.error=error.message;
- //});
- //return false;
- }
- })
- .controller('NewsDetailCtrl', function($scope, $stateParams) {
- })
- .filter('toArray', function () {
- return function (obj, addKey) {
- if (!angular.isObject(obj)) return obj;
- if ( addKey === false ) {
- return Object.keys(obj).map(function(key) {
- return obj[key];
- });
- } else {
- return Object.keys(obj).map(function (key) {
- var value = obj[key];
- return angular.isObject(value) ?
- Object.defineProperty(value, '$key', { enumerable: false, value: key}) :
- { $key: key, $value: value };
- });
- }
- }
- })
- .controller('BookingCtrl', function($scope, $http, $ionicModal, $ionicLoading, $state, $cordovaToast, $ionicPopover, $rootScope, $q, $timeout, $localstorage) {
- $scope.url=base_url;
- $scope.time={};
- // --- service
- $scope.service={};
- $scope.total_order=0;
- $scope.c_service={};
- $scope.code_service="";
- $scope.price_service;
- // --- product
- $scope.code_product="";
- $scope.price_product;
- $scope.product={};
- $scope.c_product={};
- // --- barber
- $scope.code_barber="";
- $scope.barber={};
- $scope.c_barber={};
- // --- store
- $scope.stores={};
- $scope.c_stores={};
- $scope.pilihstore={};
- $scope.code_store="";
- $scope.status_submit=false;
- $scope.phase=1;
- var Myform;
- // get product data
- $scope.get_product=function(){
- $http.post(rest_url+'get_product', {})
- .success(function(data){
- $scope.product=data;
- });
- }
- $scope.get_product();
- // get barber data
- $scope.get_barber=function(){
- $http.post(rest_url+'get_barber', {})
- .success(function(data){
- $scope.barber=data;
- });
- }
- $scope.get_barber();
- // get servic data
- $scope.get_service=function(){
- $ionicLoading.show();
- $http.post(rest_url+'get_service', {})
- .success(function(data){
- $ionicLoading.hide();
- $scope.service=data;
- }).error(function(data){
- $ionicLoading.hide();
- });
- }
- $scope.get_service();
- // get servic data
- $scope.get_store=function(){
- //$ionicLoading.show();
- $http.post(rest_url+'get_store', {})
- .success(function(data){
- // $ionicLoading.hide();
- $scope.stores=data;
- }).error(function(data){
- //$ionicLoading.hide();
- });
- }
- $scope.get_store();
- // click pilih event
- $scope.pilih_code_service=function(code){
- console.log(code);
- $scope.code_service=code.code_service;
- $scope.c_service=code;
- //$scope.price_service=code.price;
- $scope.c_product.price=$scope.c_product.price!=undefined ? $scope.c_product.price : 0;
- $scope.total_order=parseInt($scope.c_product.price)+parseInt($scope.c_service.price);
- console.log($scope.total_order);
- }
- // $scope.pilih_store=function(){
- // console.log($scope.time.store);
- // }
- $scope.belum_pilih_product=false;
- $scope.pilih_product=function(code){
- $scope.belum_pilih_product=true;
- $scope.code_product=code.code_product;
- $scope.c_product=code;
- $scope.c_product.price=$scope.c_product.price!=undefined ? $scope.c_product.price : 0;
- $scope.total_order=parseInt($scope.c_product.price)+parseInt($scope.c_service.price);
- //$scope.price_product=code.price;
- console.log($scope.total_order);
- }
- $scope.pilih_barber=function(code){
- console.log(code);
- $scope.code_barber=code.code_barber;
- $scope.c_barber=code;
- //$scope.price_product=code.price;
- }
- $scope.checked=false;
- $scope.next_service=function(page){
- $scope.phase=page!=undefined ? page : 1;
- switch($scope.phase){
- case 1 :
- if($scope.code_service==""){
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show('Please Choose service', 'long', 'center')
- }else{
- alert('Please choose service');
- }
- return;
- }
- //$scope.belum_pilih_product=false;
- break;
- case 2 :
- // if($scope.code_product==""){
- // alert('Please Choose Product');
- // return;
- // }
- break;
- case 3 :
- if($scope.code_barber==""){
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show('Please choose barber', 'long', 'center')
- }else{
- alert('Please choose barber');
- }
- return;
- }
- break;
- case 4 :
- console.log(phase);
- break;
- }
- if($scope.phase!=4 && $scope.phase!=5){
- $scope.phase+=1;
- }
- console.log($scope.phase);
- //$scope.modalproduct.show();
- }
- $scope.cancel_product=function(){
- $scope.belum_pilih_product=false;
- $scope.code_product="";
- $scope.c_product={};
- $scope.c_product.price=$scope.c_product.price!=undefined ? $scope.c_product.price : 0;
- $scope.total_order=parseInt($scope.c_product.price)+parseInt($scope.c_service.price);
- console.log($scope.total_order);
- $scope.product.forEach(function (item, i) {
- item.check = false;
- });
- }
- $scope.go_back=function(phase){
- if(phase==1){
- $scope.phase=1;
- $rootScope.goroothome();
- }else if(phase==5){
- if($scope.status_submit==true){
- $state.go('history');
- $rootScope.$broadcast('refresh.history');
- $scope.phase=1;
- $scope.total_order=0;
- $scope.status_submit=false;
- $scope.c_barber={}
- $scope.code_barber="";
- $scope.c_service={};
- $scope.code_product="";
- $scope.c_product={};
- $scope.code_service=false;
- $scope.c_store={};
- $scope.code_booking="";
- $scope.pilihstore="";
- $scope.belum_pilih_product=false;
- $scope.product.forEach(function (item, i) {
- item.check = false;
- });
- $scope.service.forEach(function (item, i) {
- item.check = false;
- });
- $scope.barber.forEach(function (item, i) {
- item.check = false;
- });
- $scope.time={};
- //Myform.$setPristine();
- }else{
- $scope.next_service(phase-2);
- }
- }else{
- $scope.next_service(phase-2);
- }
- }
- $scope.next_barber=function(){
- if($scope.code_product==""){
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show('Please Choose Product', 'long', 'center')
- }else{
- alert('Please Choose Product');
- }
- return;
- }
- $scope.modalproduct.hide();
- //$state.go('history');
- $scope.modalbarber.show();
- }
- $scope.next_timebooking=function(){
- if($scope.code_barber==""){
- if($scope.code_barber==""){
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show('Please choose barber', 'short', 'center')
- }else{
- alert('Please Choose Barber');
- }
- return;
- }
- return;
- }
- $scope.modalbarber.hide();
- $scope.modaltimebooking.show();
- }
- $scope.next_submitbooking=function(form){
- console.log(form.$valid);
- if(!form.$valid) return false;
- Myform=form;
- $scope.next_service(5);
- //console.log(form.$valid);
- //$scope.modaltimebooking.hide();
- //$state.go('history', {param:'booking'});
- //$scope.submitbooking.show();
- }
- $scope.$on('modal.hidden', function(e) {
- // $scope.submitbooking.remove();
- // $scope.modaltimebooking.remove();
- // $scope.modalproduct.remove();
- // $scope.modalbarber.remove();
- });
- $ionicModal.fromTemplateUrl('templates/productbooking.html', {
- scope: $scope,
- cssClass:'ModalProduct',
- }).then(function(modal) {
- $scope.modalproduct = modal;
- });
- $ionicModal.fromTemplateUrl('templates/barberbooking.html', {
- scope: $scope,
- cssClass:'ModalProduct',
- }).then(function(modal) {
- $scope.modalbarber = modal;
- });
- $ionicModal.fromTemplateUrl('templates/timebooking.html', {
- scope: $scope,
- cssClass:'ModalProduct',
- }).then(function(modal) {
- $scope.modaltimebooking = modal;
- });
- $ionicModal.fromTemplateUrl('templates/submitbooking.html', {
- scope: $scope,
- cssClass:'ModalProduct',
- }).then(function(modal) {
- $scope.submitbooking = modal;
- });
- $scope.$on('$destroy', function() {
- $scope.popover.remove();
- // $scope.submitbooking.remove();
- // $scope.modaltimebooking.remove();
- // $scope.modalproduct.remove();
- // $scope.modalbarber.remove();
- });
- $scope.key="3";
- var template =
- '<ion-popover-view style="margin-top:10px;"><ion-content style="height:auto;" >'+
- '<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>'+
- '</ion-content></ion-popover-view>';
- $scope.popover = $ionicPopover.fromTemplate(template, {
- scope: $scope
- });
- var searchAirlines = function(searchFilter) {
- console.log('Searching airlines for ' + searchFilter);
- var deferred = $q.defer();
- var matches = $scope.stores.filter( function(airline) {
- if(airline.name_store.toLowerCase().indexOf(searchFilter.toLowerCase()) !== -1 ) return true;
- })
- $timeout( function(){
- deferred.resolve( matches );
- }, 100);
- return deferred.promise;
- };
- $scope.data = { "airlines" : [], "search" : '' };
- $scope.pilih_store=function(data){
- //data=$scope.pilihstore;
- console.log(data);
- $scope.code_store=data.code_store;
- $scope.c_store=data;
- $scope.time.store=data.name_store;
- //console.log(data);
- $scope.popover.hide();
- }
- $scope.search = function($event) {
- $scope.time.store = $scope.time.store!=undefined ? $scope.time.store : '';
- if($scope.time.store!=''){
- $scope.popover.show(document.querySelector('.keystore'));
- searchAirlines($scope.time.store).then(
- function(matches) {
- console.log(matches);
- $scope.data.airlines = matches;
- }
- )
- }else{
- $scope.popover.hide();
- $scope.data.airlines=[];
- }
- //}
- console.log($scope.data.airlines);
- }
- $scope.submit_booking=function(){
- $ionicLoading.show();
- $http.post(rest_url+'submit_booking',
- {
- //email:$rootScope.datauserlogin.email,
- email:$localstorage.get('email'),
- code_barber:$scope.c_barber.code_barber,
- code_product:$scope.c_product.code_product,
- code_service:$scope.c_service.code_service,
- date_booking:$scope.time.date_booking,
- time_booking:$scope.time.time_booking,
- code_store:$scope.c_store.code_store,
- price_service:$scope.c_service.price,
- price_product:$scope.c_product.price,
- total:$scope.total_order,
- time_service:$scope.c_service.time_estimation
- }
- ).success(function(dats){
- //$scope.status_submit=true;
- $ionicLoading.hide();
- if(dats.code==1){
- $scope.code_booking=dats.code_booking;
- $scope.status_submit=true;
- }if(dats.code==3){
- if($scope.code_barber==""){
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show(dats.msg, 'long', 'center')
- }else{
- alert(dats.msg);
- }
- return;
- }
- $rootScope.logout();
- }else{
- //alert(dats.msg);
- }
- }).error(function(data){
- $ionicLoading.hide();
- if($scope.code_barber==""){
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show('Sorry system fail, please try again', 'short', 'center')
- }else{
- alert('Sorry System was Failure, please try again later');
- }
- return;
- }
- });
- }
- $scope.clear_booking=function(){
- $scope.submitbooking.hide(true);
- $scope.modaltimebooking.hide(true);
- $scope.modalproduct.hide(true);
- $scope.modalbarber.hide(true);
- $state.go('history');
- /* $scope.total_order=0;
- $scope.status_submit=false;
- $scope.c_barber={}
- $scope.code_barber="";
- $scope.c_service={};
- $scope.code_product="";
- $scope.c_product={};
- $scope.code_service="";
- $scope.c_store={};
- $scope.code_booking=""; */
- // $state.go($state.current, {}, {reload: true});
- }
- })
- .directive("extSubmit", ['$timeout',function($timeout){
- return {
- link: function($scope, $el, $attr) {
- $scope.$on('makeSubmit', function(event, data){
- console.log($attr.name);
- console.log($el);
- if(data.formName === $attr.name) {
- console.log('benar');
- $timeout(function() {
- $el.triggerHandler('submit'); //<<< This is Important
- //$el[0].dispatchEvent(new Event('submit')) //equivalent with native event
- }, 0, false);
- }
- })
- }
- };
- }])
- .controller('LoginCtrl', function($scope, $state, $cordovaToast, Firebase, Auth, $http,$localstorage, $ionicLoading, $rootScope) {
- $scope.user={};
- $scope.datauser={};
- $rootScope.loginyuk=function(vvvv, type){
- $ionicLoading.hide();
- $localstorage.set('status', '');
- $http.post(rest_url+'login', {param:vvvv})
- .success(function(data3){
- if(data3.code==4){
- // if(type=='firebase'){
- // alert(data3.msg);
- // $localstorage.set('status', 'tidak.aktif');
- // }else
- if(type=='register'){
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show(data3.msg, 'long', 'center');
- }else{
- alert(data3.msg);
- }
- }else{
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show(data3.msg, 'long', 'center');
- }else{
- alert(data3.msg);
- }
- }
- $rootScope.logout();
- }else if(data3.code==1){
- if(type=='register'){
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show(data3.msg, 'long', 'center');
- }else{
- alert(data3.msg);
- }
- $rootScope.logout();
- }else
- $localstorage.set('status', 'aktif');
- $localstorage.set('email', data3.user[0].email);
- $localstorage.set('login', 'true');
- $localstorage.set('name_customer', data3.user[0].name_customer);
- $localstorage.set('phone', data3.user[0].phone);
- $localstorage.set('photo', data3.user[0].photo);
- inifoto=data3.user[0].photo;
- $localstorage.set('join_by', data3.user[0].join_by);
- $rootScope.checkdevice();
- $rootScope.$broadcast('gantiphoto', {photo:data3.user[0].photo});
- $state.go('eventmenu.home');
- $rootScope.cekpesan();
- // }
- }
- //}
- });
- }
- $rootScope.checkdevice=function(){
- console.log('device');
- $http.post(rest_url+'daftar_device_token', {token : $localstorage.get('device_token'), email : $localstorage.get('email'), 'type': 'check'})
- .success(function(data){
- // if(data.code==1){
- // $localstorage.set('device_token', token);
- // }
- });
- }
- $rootScope.cekpesan=function(){
- console.log($localstorage.get('adapesan'));
- console.log($localstorage.getObject('pesannya'));
- if($localstorage.get('adapesan')=='ada' && $localstorage.get('login')=='true'){
- if($localstorage.getObject('pesannya').type=='popup'){
- $ionicPopup.alert({
- title:$localstorage.getObject('pesannya').title,
- template:'<div style="text-align:justify">'+$localstorage.getObject('pesannya').message+'</div>'
- }).then(function(){
- if($localstorage.getObject('pesannya').state!=""){
- $state.go($localstorage.getObject('pesannya').state);
- $localstorage.set('adapesan', 'tidak')
- }
- });
- }else{
- $rootScope.$broadcast('refresh.'+$localstorage.getObject('pesannya').state);
- if($localstorage.getObject('pesannya').state!=undefined){
- $state.go($localstorage.getObject('pesannya').state);
- }
- $localstorage.set('adapesan', 'tidak')
- }
- }
- }
- $scope.login_email = function(form) {
- if(!form.$valid) return;
- $ionicLoading.show();
- Auth.$signInWithEmailAndPassword($scope.user.email, "maricoy")
- .then(function(authData) {
- }).catch(function(error) {
- if(error.code=='auth/user-not-found'){
- Auth.$createUserWithEmailAndPassword($scope.user.email, "maricoy")
- .then(function(data) {
- }).catch(function(error) {
- });
- }
- });
- $scope.datauser.join_by='email';
- $scope.user.type='login';
- $rootScope.loginyuk($scope.user);
- }
- $scope.login_fb=function(){
- openFB.login(
- function (response) {
- console.log(response);
- if (response.status === 'connected') {
- $ionicLoading.show();
- //console.log('Facebook login succeeded', response);
- openFB.api({path: '/me', success: function(data){
- $scope.datauser=data;
- console.log(data);
- $scope.datauser.join_by='facebook';
- openFB.api({
- path: '/me/picture/',
- params: {redirect:false, type:'small'},
- success: function(data2) {
- $scope.datauser.poto=data2.data.url;
- $rootScope.loginyuk($scope.datauser);
- }
- });
- }});
- var credential = firebase.auth.FacebookAuthProvider.credential(
- response.authResponse.accessToken);
- Auth.$signInWithCredential(credential).catch(function (error) {
- });
- } else {
- $ionicLoading.hide();
- }
- }
- );
- }
- //var flaglogin=false;
- // $rootScope.ceklogin2=function(){
- // console.log($localstorage.get('name_customer'));
- // console.log($localstorage.get('phone'));
- // console.log($localstorage.get('email'));
- // console.log($localstorage.get('photo'));
- // console.log($localstorage.get('join_by'));
- // console.log($localstorage.get('login'));
- // console.log($localstorage.get('status'));
- // if($localstorage.get('login')=='true'){
- // console.log('a');
- // $state.go('eventmenu.home');
- // }else{
- // console.log('b');
- // $state.go('login');
- // }
- // }
- $scope.go_register=function(){
- $state.go('register');
- }
- })
- .controller('AccountCtrl', function($scope) {
- $scope.settings = {
- enableFriends: true
- };
- })
- .controller('StoreDetailCtrl', function($scope, $stateParams, $compile, Chats) {
- /* function initialize() {
- var myLatlng = new google.maps.LatLng(43.07493,-89.381388);
- var mapOptions = {
- center: myLatlng,
- zoom: 16,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- };
- var map = new google.maps.Map(document.getElementById("map"),
- mapOptions);
- //Marker + infowindow + angularjs compiled ng-click
- var contentString = "<div><a ng-click='clickTest()'>Click me!</a></div>";
- var compiled = $compile(contentString)($scope);
- var infowindow = new google.maps.InfoWindow({
- content: compiled[0]
- });
- var marker = new google.maps.Marker({
- position: myLatlng,
- map: map,
- title: 'Uluru (Ayers Rock)'
- });
- google.maps.event.addListener(marker, 'click', function() {
- infowindow.open(map,marker);
- });
- $scope.map = map;
- }
- google.maps.event.addDomListener(window, 'load', initialize);
- $scope.centerOnMe = function() {
- if(!$scope.map) {
- return;
- }
- $scope.loading = $ionicLoading.show({
- content: 'Getting current location...',
- showBackdrop: false
- });
- navigator.geolocation.getCurrentPosition(function(pos) {
- $scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
- $scope.loading.hide();
- }, function(error) {
- alert('Unable to get location: ' + error.message);
- });
- }; */
- $scope.user=Chats.get($stateParams.id);
- //console.log($scope.data);
- $scope.clickTest = function() {
- alert('Example of infowindow with ng-click')
- };
- })
- .controller('RegisterCtrl', function($scope, $ionicLoading, Firebase, $localstorage, Auth, $state, $cordovaToast, $rootScope, $http) {
- $scope.user={};
- // form={email:$scope.user.email, password:$scope.user.password};
- $scope.register=function(form){
- $scope.error="";
- if(form.$error.compareTo){
- $scope.error="Re Password didn't match to password";
- }
- if(!form.$valid) return;
- $ionicLoading.show();
- $scope.user.join_by='email';
- $scope.user.type='register';
- $http.post(rest_url+'login', {param:$scope.user})
- .success(function(data){
- $ionicLoading.hide();
- if(data.code==1){
- $scope.user={};
- form.$setPristine(true);
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show(data.msg, 'long', 'center').then(function(){
- $rootScope.logout();
- });
- }else{
- alert(data.msg);
- $rootScope.logout();
- }
- }else{
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show(data.msg, 'long', 'center').then(function(){
- $rootScope.logout();
- });
- }else{
- alert(data.msg);
- $rootScope.logout();
- }
- }
- }).error(function(){
- $ionicLoading.hide();
- });
- Auth.$createUserWithEmailAndPassword($scope.user.email, "maricoy")
- .then(function(data) {
- }).catch(function(error) {
- });
- }
- })
- .controller('ForgotCtrl', function($scope, Auth, Firebase, $state, $localstorage, $ionicLoading, $cordovaToast, $rootScope, $http) {
- $scope.user={};
- $scope.error="";
- // form={email:$scope.user.email, password:$scope.user.password};
- $scope.forgotpassword=function(form){
- if(form.$error.compareTo){
- $scope.error="Re Password didn't match to password";
- }
- if(!form.$valid) return;
- $ionicLoading.show();
- $http.post(rest_url+'reset_password', {param:$scope.user})
- .success(function(data){
- $ionicLoading.hide();
- if(data.code=='1'){
- $scope.user={};
- form.$setPristine(true);
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show(data.msg, 'long', 'center').then(function(){ $state.go('login') });
- }else{
- alert(data.msg);
- $state.go('login');
- }
- }else{
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show(data.msg, 'long', 'center');
- }else{
- alert(data.msg);
- }
- }
- }).error(function(){
- $ionicLoading.hide();
- });
- // firebase.auth().sendPasswordResetEmail($scope.user.email).then(function(data) {
- // alert('Please check your email, and click link reset email');
- // $state.go('login');
- // }).catch(function(error) {
- // console.log(error);
- // $scope.error=error.message;
- // });
- }
- })
- .controller('HistoryCtrl', function($scope, $rootScope, $ionicLoading, $stateParams, $state, $cordovaToast, $http, $localstorage) {
- $scope.shistory={};
- $scope.url=base_url;
- //$email=$rootScope.datauserlogin.email;
- $email=$localstorage.get('email');
- $scope.get_history=function(){
- $ionicLoading.show();
- $http.post(rest_url+'get_history', {email:$email})
- .success(function(data){
- $scope.shistory=data;
- $ionicLoading.hide();
- }).error(function(data){
- $ionicLoading.hide();
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show('System fail, please try again later', 'long', 'center');
- }else{
- alert('System fail, please try again later');
- }
- });
- }
- $scope.get_history();
- $rootScope.$on('refresh.history', function(){
- $scope.get_history();
- });
- })
- .controller('StoreCtrl', function($scope, $rootScope, $ionicLoading, $state, $cordovaToast, $http, $localstorage, $ionicModal, $sce, $compile) {
- $scope.store={};
- $scope.url=base_url;
- //$email=$rootScope.datauserlogin.email;
- $email=$localstorage.get('email');
- $scope.get_store=function(){
- $ionicLoading.show();
- $http.post(rest_url+'get_store', {})
- .success(function(data){
- $scope.store=data;
- $ionicLoading.hide();
- }).error(function(data){
- $ionicLoading.hide();
- if($localstorage.get('is_device')!=undefined){
- $cordovaToast.show('System fail, please try again later', 'long', 'center');
- }else{
- alert('System fail, please try again later');
- }
- });
- }
- $scope.get_store();
- $rootScope.$on('refresh.history', function(){
- $scope.get_store();
- });
- $scope.show_detail=function(data){
- console.log('bc');
- $scope.det=data;
- $scope.modalstore.show();
- function initialize() {
- var myLatlng = new google.maps.LatLng(data.latitude,data.longitude);
- // -6.2940106,
- var mapOptions = {
- center: myLatlng,
- zoom: 16,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- };
- var map = new google.maps.Map(document.getElementById("map"),
- mapOptions);
- //Marker + infowindow + angularjs compiled ng-click
- var contentString = "<div><a ng-click='clickTest()'>Click me!</a></div>";
- var compiled = $compile(contentString)($scope);
- var infowindow = new google.maps.InfoWindow({
- content: compiled[0]
- });
- var marker = new google.maps.Marker({
- position: myLatlng,
- map: map,
- title: ''
- });
- google.maps.event.addListener(marker, 'click', function() {
- infowindow.open(map,marker);
- });
- $scope.map = map;
- }
- console.log(initialize());
- 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¢er="+data.latitude+","+data.longitude+"&zoom=15");
- }
- $ionicModal.fromTemplateUrl('templates/store-detail.html', {
- scope: $scope,
- cssClass:'ModalProduct',
- }).then(function(modal) {
- $scope.modalstore = modal;
- });
- })
- .controller('BarberDetailCtrl', function($scope, $stateParams) {
- //console.log($stateParams.id_barber);
- $scope.user = { name:'fadli', profile : 'fadli adalah orang yang sangat bagus sekali dalam menjalankan perintah atasan ', img : 'img/perry.png' }
- })
- .controller('BarberCtrl', function($ionicLoading, $scope, $http, $ionicModal, $rootScope, $state) {
- $scope.barber={};
- $scope.url=base_url;
- $scope.user={};
- $scope.get_barber=function(){
- $ionicLoading.show();
- $http.post(rest_url+'get_barber', {})
- .success(function(data){
- $ionicLoading.hide();
- $scope.barber=data;
- });
- }
- $scope.get_barber();
- $scope.rating = {};
- $scope.rating.rate = 3;
- $scope.rating.max = 5;
- $scope.detail_barber=function(data){
- $scope.user=data;
- $scope.modalbarber.show();
- $scope.rating.rate=data.total_star;
- }
- $ionicModal.fromTemplateUrl('templates/barber-detail.html', {
- scope: $scope,
- cssClass:'ModalProduct',
- }).then(function(modal) {
- $scope.modalbarber = modal;
- });
- $rootScope.$on('refresh.barber', function(){
- $scope.get_barber();
- });
- })
- .controller('ProductCtrl', function($scope, $ionicLoading, $http, $ionicModal,$rootScope, $state) {
- $scope.product={};
- $scope.url=base_url;
- $scope.get_product=function(){
- $ionicLoading.show();
- $http.post(rest_url+'get_product', {})
- .success(function(data){
- $ionicLoading.hide();
- $scope.product=data;
- });
- }
- $scope.get_product();
- $rootScope.$on('refresh.product', function(){
- $scope.get_product();
- });
- $ionicModal.fromTemplateUrl('templates/product-detail.html', {
- scope: $scope
- }).then(function(modal) {
- $scope.modalproduct = modal;
- });
- $scope.show_product=function(data){
- $scope.det=data;
- $scope.modalproduct.show();
- }
- })
- .controller('GalleryCtrl', function($scope, $ionicLoading, $rootScope, $http, $ionicModal, $state) {
- $scope.gallery={};
- $scope.url=base_url;
- $scope.get_gallery=function(){
- $ionicLoading.show();
- $http.post(rest_url+'get_gallery', {})
- .success(function(data){
- $scope.gallery=data;
- $ionicLoading.hide();
- });
- }
- $scope.get_gallery();
- $rootScope.$on('refresh.history', function(){
- $scope.get_gallery();
- });
- $scope.showImages = function(index) {
- $scope.activeSlide = index;
- $scope.showModal('templates/imagepop.html');
- }
- $scope.showModal = function(templateUrl) {
- $ionicModal.fromTemplateUrl(templateUrl, {
- scope: $scope,
- animation: 'slide-in-up'
- }).then(function(modal) {
- $scope.modal = modal;
- $scope.modal.show();
- });
- }
- // Close the modal
- $scope.closeModal = function() {
- $scope.modal.hide();
- $scope.modal.remove()
- };
- })
- .controller('ProductDetailCtrl', function($scope, $http, $ionicLoading, $rootScope, $state) {
- })
- .controller('HelpCtrl', function($scope, $http, $rootScope, $ionicLoading, $state) {
- $scope.help={};
- $scope.url=base_url;
- $scope.get_help=function(){
- $ionicLoading.show();
- $http.post(rest_url+'get_config', {type:'help'})
- .success(function(data){
- $scope.help=data[0];
- $ionicLoading.hide();
- });
- }
- $scope.goLogin=function(){
- $state.go('login');
- }
- $scope.get_help();
- $rootScope.$on('refresh.help', function(){
- $scope.get_help();
- });
- })
- .controller('AboutCtrl', function($scope, $http, $rootScope, $ionicLoading, $state) {
- $scope.about={};
- $scope.url=base_url;
- $scope.get_about=function(){
- $ionicLoading.show();
- $http.post(rest_url+'get_config', {type:'about'})
- .success(function(data){
- $scope.about=data[0];
- $ionicLoading.hide();
- });
- }
- $scope.get_about();
- $rootScope.$on('refresh.about', function(){
- $scope.get_about();
- });
- })
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement