Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.   'use strict';
  3.  
  4.   var app = ons.bootstrap('app', ['onsen', 'angular-images-loaded', 'ngMap', 'angular-carousel', 'LocalStorageModule']);
  5.  
  6. // app.config(['$httpProvider', function($httpProvider) {
  7. //         $httpProvider.defaults.useXDomain = true;
  8. //         delete $httpProvider.defaults.headers.common['X-Requested-With'];
  9. //     }
  10. // ]);  already tried
  11.  
  12.  
  13.   app.filter('htmlToPlaintext', function() {
  14.       return function(text) {
  15.         return String(text).replace(/<[^>]+>/gm, '');
  16.       };
  17.     }
  18.   );
  19.  
  20.   app.directive('datePicker', function () {
  21.       return {
  22.           link: function postLink(scope, element, attrs) {
  23.               scope.$watch(attrs.datePicker, function () {
  24.                   if (attrs.datePicker === 'start') {
  25.                       //element.pickadate();
  26.                   }
  27.               });
  28.           }
  29.       };
  30.   });  
  31.  
  32.   app.controller('pushController', function($scope){
  33.  
  34.   });
  35.  
  36.   app.controller('ContactController', function($scope, $http) {
  37.       $scope.formData = {};
  38.  
  39.     $scope.processForm = function() {
  40.       $http.post('http://myapi.example/api/contact', $scope.formData).then(function(data) {
  41.         $scope.message = 'Mensagem enviada com sucesso.';
  42.         console.log(data);
  43.       }, function(data) {
  44.         $scope.message = 'Ocorreu um erro. Tente novamente mais tarde ou ligue para uma loja.';
  45.         console.log(data);
  46.       });
  47.     };
  48.  
  49.  
  50.   });
  51.  
  52.   app.controller('menuController', function($scope, $window, localStorageService) {
  53.     if(window.localStorage["user_id"]) {
  54.       $scope.is_logged = 1;
  55.     }
  56.     $scope.x_user_id = window.localStorage["user_id"];
  57.     $scope.user_name = window.localStorage["user_name"];
  58.     $scope.logout = function() {
  59.       localStorage.removeItem('user_id');
  60.       localStorage.removeItem('user_name');
  61.       $window.location.reload();
  62.     };
  63.   });
  64.  
  65.   app.controller('networkController', function($scope){
  66.  
  67.  
  68.     document.addEventListener("offline", function(){
  69.  
  70.       offlineMessage.show();
  71.       setTimeout('offlineMessage.hide()', 8000);  
  72.  
  73.     }, false);
  74.  
  75.  
  76.   });
  77.  
  78.  
  79.  
  80.   Storage.prototype.setObject = function(key, value) {
  81.       this.setItem(key, JSON.stringify(value));
  82.   };
  83.  
  84.   Storage.prototype.getObject = function(key) {
  85.       var value = this.getItem(key);
  86.       return value && JSON.parse(value);
  87.   };
  88.  
  89.  
  90.   app.directive('imgCache', ['$document', function ($document) {
  91.     return {
  92.       link: function (scope, ele, attrs) {
  93.         var target = $(ele);
  94.  
  95.         scope.$on('ImgCacheReady', function () {
  96.  
  97.           ImgCache.isCached(attrs.src, function(path, success){
  98.             if(success){
  99.               ImgCache.useCachedFile(target);
  100.             } else {
  101.               ImgCache.cacheFile(attrs.src, function(){
  102.                 ImgCache.useCachedFile(target);
  103.               });
  104.             }
  105.           });
  106.         }, false);
  107.  
  108.       }
  109.     };
  110.   }]);    
  111.  
  112.  
  113.  
  114.  
  115.   app.controller('newsController', [ '$http', '$scope', '$rootScope', function($http, $scope, localStorageService){
  116.  
  117.       $scope.yourAPI = 'http://myapi.example/api/appointments/user';
  118.       $scope.items = [];
  119.       $scope.confirmado = '<span style="color: green">Confirmado</span>';
  120.       $scope.n_confirmado = '<span style="color: red">Não confirmado</span>';
  121.       $scope.my_id = window.localStorage["user_id"];
  122.  
  123.       $scope.getItems = function() {
  124.         $scope.isFetching = true;
  125.         $http({method: 'GET', url: 'http://myapi.example/api/appointments/user?user_id='+$scope.my_id})
  126.           .success(function(data) {
  127.             $scope.items = data;
  128.             $scope.isFetching = false;
  129.           })
  130.           .error(function(data) {
  131.             alert('error');
  132.             $scope.isFetching = false;
  133.           });
  134.       };
  135.  
  136.  
  137.   }]);
  138.  
  139.   app.controller('obsController', [ '$http', '$scope', '$rootScope', function($http, $scope, localStorageService){
  140.  
  141.       $scope.yourAPI = 'http://myapi.example/api/obs/user?user_id=1';
  142.       $scope.items = [];
  143.       $scope.confirmado = '<span style="color: green">Confirmado</span>';
  144.       $scope.n_confirmado = '<span style="color: red">Não confirmado</span>';
  145.       $scope.my_id = window.localStorage["user_id"];
  146.  
  147.       $scope.getItems = function() {
  148.         $scope.isFetching = true;
  149.         $http({method: 'GET', url: 'http://myapi.example/api/obs/user?user_id='+$scope.my_id})
  150.           .success(function(data) {
  151.             $scope.items = data;
  152.             $scope.isFetching = false;
  153.           })
  154.           .error(function(data) {
  155.             alert('error');
  156.             $scope.isFetching = false;
  157.           });
  158.       }
  159.  
  160.  
  161.   }]);
  162.  
  163.  
  164.   app.controller('bookingController', function($scope, $http, $compile, $filter, localStorageService){
  165.  
  166.     if(window.localStorage["user_id"]) {
  167.       $scope.is_logged = 1;
  168.     }
  169.     $scope.user_id = window.localStorage["user_id"];
  170.     $scope.bookdate = 'Selecione uma data';
  171.     $scope.booktime = 'Selecione um horário';
  172.  
  173.     $scope.formData = {};
  174.     $scope.formData.user_id = window.localStorage["user_id"];
  175.  
  176.     // duplicate inputs
  177.     $scope.inputCounter = 0;
  178.     $scope.inputs = [{
  179.       id: 'input',
  180.       idCounter: '0',
  181.     }];
  182.     $scope.add = function() {
  183.       $scope.inputTemplate = {
  184.         id: 'input-' + $scope.inputCounter,
  185.         name: '',
  186.         idCounter: $scope.inputCounter + 1,
  187.  
  188.       };
  189.       $scope.inputCounter += 1;
  190.       $scope.inputs.push($scope.inputTemplate);
  191.     };
  192.  
  193.     $scope.processForm = function() {
  194.       $http({
  195.       method  : 'POST',
  196.       url     : 'http://myapi.example/api/appointments/new',
  197.       data    : $.param($scope.formData),  // pass in data as strings
  198.       headers : { 'Content-Type': 'application/x-www-form-urlencoded' }  // set the headers so angular passing info as form data (not request payload)
  199.      })
  200.       .success(function(data) {
  201.           $scope.message = 'Marcação feita com sucesso.';
  202.        
  203.       }).error(function(data) {
  204.         $scope.message = 'Ocorreu um erro. Tente novamente ou ligue para uma loja.';
  205.       });
  206.     };
  207.  
  208.  
  209.  
  210.     $scope.chooseDate = function(){
  211.      
  212.       var options = {
  213.         date: new Date(),
  214.         mode: 'date'
  215.       };
  216.  
  217.       datePicker.show(options, function(date){
  218.        
  219.         var day   = date.getDate();
  220.           var month   = date.getMonth() + 1;
  221.           var year  = date.getFullYear();
  222.  
  223.           $scope.$apply(function(){
  224.             $scope.bookdate = $filter('date')(date, 'MMMM d, yyyy');      
  225.           });
  226.  
  227.       });
  228.  
  229.     };
  230.  
  231.     $scope.chooseTime = function(){
  232.      
  233.       var options = {
  234.         date: new Date(),
  235.         mode: 'time'
  236.       };
  237.  
  238.       datePicker.show(options, function(time){
  239.           $scope.$apply(function(){
  240.             $scope.booktime = $filter('date')(time, 'hh:mm a');
  241.           });
  242.       });
  243.  
  244.     };
  245.  
  246.   });
  247.  
  248.   app.controller('postsController', [ '$http', '$scope', '$rootScope', function($http, $scope, localStorageService){
  249.  
  250.       $scope.yourAPI = 'http://myapi.example/api/appointments/user';
  251.       $scope.items = [];
  252.  
  253.       $scope.getItems = function(cat) {
  254.             console.log('ajaxing');
  255.  
  256.             $http.get('http://myapi.example/api/posts/category/'+cat).then(function(response) {
  257.               console.log('ajaxed');
  258.               $scope.isFetching = false;
  259.               $scope.items = response.data;
  260.             }, function(response) {
  261.               console.log('uhh something went wrong');
  262.               $scope.isFetching = false;
  263.               console.log(response);
  264.             });
  265.       };
  266.  
  267.  
  268.   }]);
  269.  
  270. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement