Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- 'use strict';
- var app = ons.bootstrap('app', ['onsen', 'angular-images-loaded', 'ngMap', 'angular-carousel', 'LocalStorageModule']);
- // app.config(['$httpProvider', function($httpProvider) {
- // $httpProvider.defaults.useXDomain = true;
- // delete $httpProvider.defaults.headers.common['X-Requested-With'];
- // }
- // ]); already tried
- app.filter('htmlToPlaintext', function() {
- return function(text) {
- return String(text).replace(/<[^>]+>/gm, '');
- };
- }
- );
- app.directive('datePicker', function () {
- return {
- link: function postLink(scope, element, attrs) {
- scope.$watch(attrs.datePicker, function () {
- if (attrs.datePicker === 'start') {
- //element.pickadate();
- }
- });
- }
- };
- });
- app.controller('pushController', function($scope){
- });
- app.controller('ContactController', function($scope, $http) {
- $scope.formData = {};
- $scope.processForm = function() {
- $http.post('http://myapi.example/api/contact', $scope.formData).then(function(data) {
- $scope.message = 'Mensagem enviada com sucesso.';
- console.log(data);
- }, function(data) {
- $scope.message = 'Ocorreu um erro. Tente novamente mais tarde ou ligue para uma loja.';
- console.log(data);
- });
- };
- });
- app.controller('menuController', function($scope, $window, localStorageService) {
- if(window.localStorage["user_id"]) {
- $scope.is_logged = 1;
- }
- $scope.x_user_id = window.localStorage["user_id"];
- $scope.user_name = window.localStorage["user_name"];
- $scope.logout = function() {
- localStorage.removeItem('user_id');
- localStorage.removeItem('user_name');
- $window.location.reload();
- };
- });
- app.controller('networkController', function($scope){
- document.addEventListener("offline", function(){
- offlineMessage.show();
- setTimeout('offlineMessage.hide()', 8000);
- }, false);
- });
- Storage.prototype.setObject = function(key, value) {
- this.setItem(key, JSON.stringify(value));
- };
- Storage.prototype.getObject = function(key) {
- var value = this.getItem(key);
- return value && JSON.parse(value);
- };
- app.directive('imgCache', ['$document', function ($document) {
- return {
- link: function (scope, ele, attrs) {
- var target = $(ele);
- scope.$on('ImgCacheReady', function () {
- ImgCache.isCached(attrs.src, function(path, success){
- if(success){
- ImgCache.useCachedFile(target);
- } else {
- ImgCache.cacheFile(attrs.src, function(){
- ImgCache.useCachedFile(target);
- });
- }
- });
- }, false);
- }
- };
- }]);
- app.controller('newsController', [ '$http', '$scope', '$rootScope', function($http, $scope, localStorageService){
- $scope.yourAPI = 'http://myapi.example/api/appointments/user';
- $scope.items = [];
- $scope.confirmado = '<span style="color: green">Confirmado</span>';
- $scope.n_confirmado = '<span style="color: red">Não confirmado</span>';
- $scope.my_id = window.localStorage["user_id"];
- $scope.getItems = function() {
- $scope.isFetching = true;
- $http({method: 'GET', url: 'http://myapi.example/api/appointments/user?user_id='+$scope.my_id})
- .success(function(data) {
- $scope.items = data;
- $scope.isFetching = false;
- })
- .error(function(data) {
- alert('error');
- $scope.isFetching = false;
- });
- };
- }]);
- app.controller('obsController', [ '$http', '$scope', '$rootScope', function($http, $scope, localStorageService){
- $scope.yourAPI = 'http://myapi.example/api/obs/user?user_id=1';
- $scope.items = [];
- $scope.confirmado = '<span style="color: green">Confirmado</span>';
- $scope.n_confirmado = '<span style="color: red">Não confirmado</span>';
- $scope.my_id = window.localStorage["user_id"];
- $scope.getItems = function() {
- $scope.isFetching = true;
- $http({method: 'GET', url: 'http://myapi.example/api/obs/user?user_id='+$scope.my_id})
- .success(function(data) {
- $scope.items = data;
- $scope.isFetching = false;
- })
- .error(function(data) {
- alert('error');
- $scope.isFetching = false;
- });
- }
- }]);
- app.controller('bookingController', function($scope, $http, $compile, $filter, localStorageService){
- if(window.localStorage["user_id"]) {
- $scope.is_logged = 1;
- }
- $scope.user_id = window.localStorage["user_id"];
- $scope.bookdate = 'Selecione uma data';
- $scope.booktime = 'Selecione um horário';
- $scope.formData = {};
- $scope.formData.user_id = window.localStorage["user_id"];
- // duplicate inputs
- $scope.inputCounter = 0;
- $scope.inputs = [{
- id: 'input',
- idCounter: '0',
- }];
- $scope.add = function() {
- $scope.inputTemplate = {
- id: 'input-' + $scope.inputCounter,
- name: '',
- idCounter: $scope.inputCounter + 1,
- };
- $scope.inputCounter += 1;
- $scope.inputs.push($scope.inputTemplate);
- };
- $scope.processForm = function() {
- $http({
- method : 'POST',
- url : 'http://myapi.example/api/appointments/new',
- data : $.param($scope.formData), // pass in data as strings
- headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload)
- })
- .success(function(data) {
- $scope.message = 'Marcação feita com sucesso.';
- }).error(function(data) {
- $scope.message = 'Ocorreu um erro. Tente novamente ou ligue para uma loja.';
- });
- };
- $scope.chooseDate = function(){
- var options = {
- date: new Date(),
- mode: 'date'
- };
- datePicker.show(options, function(date){
- var day = date.getDate();
- var month = date.getMonth() + 1;
- var year = date.getFullYear();
- $scope.$apply(function(){
- $scope.bookdate = $filter('date')(date, 'MMMM d, yyyy');
- });
- });
- };
- $scope.chooseTime = function(){
- var options = {
- date: new Date(),
- mode: 'time'
- };
- datePicker.show(options, function(time){
- $scope.$apply(function(){
- $scope.booktime = $filter('date')(time, 'hh:mm a');
- });
- });
- };
- });
- app.controller('postsController', [ '$http', '$scope', '$rootScope', function($http, $scope, localStorageService){
- $scope.yourAPI = 'http://myapi.example/api/appointments/user';
- $scope.items = [];
- $scope.getItems = function(cat) {
- console.log('ajaxing');
- $http.get('http://myapi.example/api/posts/category/'+cat).then(function(response) {
- console.log('ajaxed');
- $scope.isFetching = false;
- $scope.items = response.data;
- }, function(response) {
- console.log('uhh something went wrong');
- $scope.isFetching = false;
- console.log(response);
- });
- };
- }]);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement