Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var rest_url='http://mobiloutlet.id/panel/Api/';
- angular.module('starter.controllers', ['ionic','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;
- }
- };
- })
- .controller('AppCtrl', function($scope, $ionicModal, $timeout, $ionicLoading, $http) {
- // With the new view caching in Ionic, Controllers are only called
- // when they are recreated or on app start, instead of every page change.
- // To listen for when this page is active (for example, to refresh data),
- // listen for the $ionicView.enter event:
- //$scope.$on('$ionicView.enter', function(e) {
- //});
- // Form data for the login modal
- $scope.loginData = {};
- // Create the login modal that we will use later
- $ionicModal.fromTemplateUrl('templates/login.html', {
- scope: $scope
- }).then(function(modal) {
- $scope.modal = modal;
- });
- // Triggered in the login modal to close it
- $scope.closeLogin = function() {
- $scope.modal.hide();
- };
- // Open the login modal
- $scope.login = function() {
- $scope.modal.show();
- };
- // Perform the login action when the user submits the login form
- $scope.doLogin = function() {
- console.log('Doing login', $scope.loginData);
- // Simulate a login delay. Remove this and replace with your login
- // code if using a login system
- $timeout(function() {
- $scope.closeLogin();
- }, 1000);
- };
- $scope.saveConn = function() {
- // $scope.config = {};
- // $scope.username = this.config.username;
- // $scope.password = this.config.password;
- $ionicLoading.show({
- template: 'Checking server connection...',
- showBackdrop: true
- });
- // var somplak = {
- // method: 'POST',
- // url: 'http://mobiloutlet.id/panel/Api/Login',
- // headers: {
- // 'Content-Type': 'application/json'
- // },
- // timeout: 5000,
- // data: $scope.config,
- // };
- $http({
- url: 'http://mobiloutlet.id/panel/Api/Login',
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- data: {username:this.username,password:this.password}
- }).
- then(function(response) {
- // $ionicLoading.hide();
- if (response.Success == 'true') {
- $location.path("/home");
- } else {
- $ionicLoading.show({
- template: 'Username and Password Missmatch',
- showBackdrop: true
- });
- }
- });
- }
- })
- .controller('HomeCtrl', function($scope, $state, $ionicSideMenuDelegate, $http, $ionicLoading, $location, $timeout, $cordovaFileTransfer, $cordovaCamera, $cordovaFile, $cordovaDevice, $ionicPopup, $cordovaActionSheet, formDataObject, $cordovaCamera, fileReader, fileUpload) {
- $scope.gambar=[];
- $scope.baseimage=[];
- $scope.uploadFile = function () {
- var files = $scope.myFile,
- uploadUrl = "http://httpbin.org/post";
- function callback(data, status, headers, config) {
- if (status == 200) console.log('Success!');
- else console.log('Error!');
- }
- if (files !==undefined) {
- for (var i = 0; i < files.length; i++) {
- var file = files[i];
- console.log('file is ' + JSON.stringify(file.name));
- fileUpload.uploadFileToUrl(file, uploadUrl, callback);
- }
- }
- };
- $scope.upload=function(files){
- $scope.files = files;
- if (files && files.length) {
- Upload.upload({
- url: '/upload_image',
- method: 'POST',
- data: {
- files: files
- }
- }).then(function (response) {
- $timeout(function () {
- $scope.result = response.data;
- });
- }, function (response) {
- if (response.status > 0) {
- $scope.errorMsg = response.status + ': ' + response.data;
- }
- }, function (evt) {
- $scope.progress =
- Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
- });
- }
- };
- $ionicSideMenuDelegate.canDragContent(false);
- $http.get('http://mobiloutlet.id/panel/Api/getVehicleBrands').then(function(result){
- $scope.items = result.data.content;
- console.log(result.data.content);
- });
- $http.get('http://mobiloutlet.id/panel/Api/getVehicleCategory').then(function(result){
- $scope.category = result.data.content;
- console.log(result.data.content);
- });
- $scope.saveProspect = function(config) {
- $scope.config = {};
- $scope.config.VehicleProspectBrandId = config.VehicleProspectBrandId;
- $scope.config.VehicleProspectCategoryId = config.VehicleProspectCategoryId;
- $scope.config.VehicleProspectName = config.VehicleProspectName;
- $scope.config.VehicleProspectModels = config.VehicleProspectModels;
- $scope.config.VehicleProspectColor = config.VehicleProspectColor;
- $scope.config.VehicleProspectTransmision = config.VehicleProspectTransmision;
- $scope.config.VehicleProspectBuildYear = config.VehicleProspectBuildYear;
- $scope.config.VehicleProspectLastKm = config.VehicleProspectLastKm;
- $scope.config.VehicleProspectPrice = config.VehicleProspectPrice;
- $scope.config.VehicleProspectOfferPrice = config.VehicleProspectOfferPrice;
- $scope.config.VehicleProspectSalesName = config.VehicleProspectSalesName;
- $scope.config.VehicleProspectSalesPhone = config.VehicleProspectSalesPhone;
- $scope.config.VehicleProspectSalesDealer = config.VehicleProspectSalesDealer;
- $scope.config.VehicleProspectCreateDate = config.VehicleProspectCreateDate;
- $scope.config.VehicleProspectUserId = '30';
- $scope.config.VehiclePhotoProspectPhotoPath = config.file;
- $ionicLoading.show({
- template: 'Menyimpan...',
- showBackdrop: true
- });
- $http({
- method: 'POST',
- url: 'http://mobiloutlet.id/panel/Api/saveProspect',
- headers: {
- 'Content-Type': 'application/json'
- },
- data: {
- data:$scope.config
- },
- //transformRequest: formDataObject
- }).
- then(function(response) {
- if (response.data.Success == true) {
- $ionicLoading.show({
- template: 'Data Tersimpan',
- showBackdrop: true
- });
- if($scope.gambar!=""){
- $scope.simpan_photo(response.data.id_prospect);
- }
- $location.path("app/data");
- $ionicLoading.hide();
- } else {
- console.log(response.data.Success);
- $ionicLoading.show({
- template: 'Error Menyimpan Data',
- showBackdrop: true
- });
- $ionicLoading.hide();
- $location.path("app/home");
- }
- });
- }
- $scope.test=function(){
- fd=new FormData();
- fd.append('sabar', 'sabar');
- $http({
- method: 'POST',
- url: 'http://mobiloutlet.id/panel/Api/simpanPhoto',
- headers: {
- 'Content-Type':'application/json'
- },
- data: fd,
- //transformRequest: formDataObject
- })
- .success(function(data, status, headers, config) {
- console.log(data);
- })
- .error(function(data, status, headers, config) {
- $ionicLoading.hide();
- });
- }
- $scope.simpan_photo=function($id){
- fd=new FormData();
- fd.append('id', $id);
- angular.forEach($scope.baseimage, function(value, i){
- fd.append(i, new Blob([ value ], { type: "image/jpeg" }),"image.jpeg");
- });
- $http({
- method: 'POST',
- url: 'http://mobiloutlet.id/panel/Api/simpanPhoto',
- headers: {
- 'Content-Type':'application/json'
- },
- data: fd
- })
- .success(function(data, status, headers, config) {
- $scope.baseimage=[];
- $scope.gambar=[];
- })
- .error(function(data, status, headers, config) {
- $ionicLoading.hide();
- });
- $ionicLoading.hide();
- }
- $scope.openPhotoLibrary = function() {
- $scope.imgtmp="";
- $scope.imgtmp1="";
- 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) {
- fileReader.readAsDataUrl(imageData).then(function(fileInfo) {
- console.log(fileInfo);
- $scope.imgtmp1=fileInfo;
- $scope.baseimage.push($scope.imgtmp1);
- }, function(err) {
- });
- $scope.imgtmp=imageData;
- $scope.gambar.push($scope.imgtmp);
- console.log($scope.gambar);
- console.log($scope.baseimage);
- }, function (err) {
- });
- }
- })
- .controller('DataCtrl', function($scope, $http, $ionicNavBarDelegate, $timeout, $location) {
- $scope.doRefresh = function() {
- console.log('Refreshing!');
- $timeout( function() {
- //simulate async response
- $location.path("app/data");
- //Stop the ion-refresher from spinning
- $scope.$broadcast('scroll.refreshComplete');
- }, 1000);
- };
- $ionicNavBarDelegate.showBackButton(false);
- $http.get("http://mobiloutlet.id/panel/Api/getProspect")
- .success(function (response)
- {
- $scope.names = response.content;
- });
- })
- .controller('ViewCtrl', function($scope, $http, $stateParams, $ionicNavBarDelegate) {
- $ionicNavBarDelegate.showBackButton(false);
- $http.get("http://mobiloutlet.id/panel/Api/getSelected_Prospect/"+$stateParams.VehicleProspectId)
- .success(function (response)
- {
- $scope.names = response.content;
- });
- $http.get("http://mobiloutlet.id/panel/Api/getSelected_PhotoProspect/"+$stateParams.VehicleProspectId)
- .success(function (response)
- {
- $scope.photo = response.content;
- });
- })
- .controller('PlaylistsCtrl', function($scope) {
- $scope.playlists = [
- { title: 'Reggae', id: 1 },
- { title: 'Chill', id: 2 },
- { title: 'Dubstep', id: 3 },
- { title: 'Indie', id: 4 },
- { title: 'Rap', id: 5 },
- { title: 'Cowbell', id: 6 }
- ];
- })
- .controller('PlaylistCtrl', function($scope, $stateParams) {
- })
- .controller('LoginCtrl', function($scope, $ionicModal, $timeout, $ionicLoading, $http, $location) {
- event.preventDefault();
- $scope.saveConn = function(config) {
- $scope.config = {};
- $ionicLoading.show({
- template: 'Checking server connection...',
- showBackdrop: true
- });
- console.log($scope.config);
- $http({
- url: 'http://mobiloutlet.id/panel/Api/Login',
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- timeout: 5000,
- data: {username:config.username,password:config.password}
- }).
- then(function(response) {
- if (response.data.hasil == 'benar') {
- $ionicLoading.hide();
- $location.path("app/home");
- } else {
- // $ionicLoading.hide();
- console.log(response.data.Success);
- $ionicLoading.show({
- template: 'Username atau Password Salah',
- showBackdrop: true
- });
- $location.path("app/home");
- }
- // }
- });
- }
- })
- .directive('fileModel', ['$parse', function ($parse) {
- return {
- restrict: 'A',
- link: function (scope, element, attrs) {
- var model = $parse(attrs.fileModel);
- var modelSetter = model.assign;
- element.bind('change', function () {
- scope.$apply(function () {
- modelSetter(scope, element[0].files);
- });
- });
- }
- };
- }])
- .service('fileUpload', ['$http', function ($http) {
- this.uploadFileToUrl = function (file, uploadUrl, callback) {
- var fd = new FormData();
- var files = file;
- fd.append('file', file);
- $http.post(uploadUrl, fd, {
- transformRequest: angular.identity,
- headers: {
- 'Content-Type': 'application/json'
- }
- })
- .success(callback)
- .error(callback);
- };
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement