UNPKG

unserver-unify

Version:

109 lines (107 loc) 3.8 kB
'use strict'; angular.module('bamboo.help').controller('ContactCtrl', function($scope, ApiService, CommonService, loginService, AppConfig, $state, $stateParams, $timeout, $http, $translate) { this.id = $stateParams.id || loginService.school._id; this.info = {}; this.config = AppConfig; this.item = {}; this.tab = {}; this.postcode = null; $scope.submitted = false; $scope.pdfUrl = 'init'; $scope.isopen = true; $scope.options = [{ value: 'Question', text: 'Platform Question' }, { value: 'Suggestion', text: 'Suggestion ' }, { value: 'Complain', text: 'Complain ' }, { value: 'Others', text: 'Others' }]; var _self = this; getInfo(); function getInfo() { ApiService.get("/schools/" + _self.id).then(function(result) { // console.log(result); if (result.data.success) { _self.school = result.data.data.school; console.log(_self.school); $scope.school = result.data.data.school; _self.postcode = $scope.school.postcode; _self.user = loginService.user; if (_self.school.lat && _self.school.lng && _self.school.mapType == 'baidu') { _self.baiduMapUrl = "http://api.map.baidu.com/staticimage?width=400&height=300&center=" + _self.school.lng + ',' + _self.school.lat + "&zoom=17&markers=" + _self.school.lng + ',' + _self.school.lat + "&markerStyles=l,0"; console.log(_self.baiduMapUrl); } _self.keyUrl="https://maps.googleapis.com/maps/api/js?key=AIzaSyCDpjAui7Bp-lfs3akUG4zGId3RAyhGA1M"; // if(_self.school.mapType=='googlesg'||!_self.school.mapType){ // searchostcode(); // } // searchostcode(); } }); } this.createContact = function(form) { $scope.submitted = true; console.log(form); if (form.$invalid) { $scope.shaking = true; $timeout(function() { $scope.shaking = false; }, 500); return; } _self.info.action = "createrecord"; console.log(_self.tab); _self.info.tab = _self.tab.value; console.log(_self.info); ApiService.post('/logs', _self.info).then(function(result) { //console.log(result); if (result.data.success) { // CommonService.showInfo($translate.instant('Your message sent successfully, We will get back to you soon.'),function(res){ // console.log("survey submited"); // $state.reload(); // }); _self.showMessage = true; //$state.go('index.home'); } else { CommonService.showError(result.data.error || result.data.info); } }); }; function searchostcode() { if (!_self.postcode || _self.postcode.length < 4) { CommonService.showError('Invalid postcode'); return; } if (loginService.subDomain == 'aou') { var url = "https://maps.google.com/maps/api/geocode/json?key=AIzaSyCDpjAui7Bp-lfs3akUG4zGId3RAyhGA1M&&address=MALAYSIA+" + _self.postcode; } else { var url = "https://maps.google.com/maps/api/geocode/json?address=" + _self.school.address+"+SG&&key=AIzaSyCDpjAui7Bp-lfs3akUG4zGId3RAyhGA1M"; } var params = { url: url, method: 'GET', headers: { 'Content-Type': 'application/json' }, timeout: 1200000, // async: false, }; console.log(url); _self.school.lat=0; $http.defaults.useXDomain = true; $http(params).then(function(result) { console.log(result); if (result.status == '200' && result.data.status == 'OK') { var location = result.data.results[0].geometry.location; _self.school.lat = location.lat; _self.school.lng = location.lng; } }) } });