123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- (function (app) {
- app.controller('addCtrl', ["$scope", "$state", "dreamService", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate", "$ionicModal", "$ionicHistory", "common", "config"
- , function ($scope, $state, dreamService, msg, $ionicTabsDelegate, $ionicNavBarDelegate, $ionicModal, $ionicHistory, common, config) {
- $ionicModal.fromTemplateUrl('my-modal.html', {
- scope: $scope,
- animation: 'slide-in-up'
- }).then(function (modal) {
- $scope.modal = modal;
- });
- $scope.openModal = function () {
- $scope.modal.show();
- };
- $scope.closeModal = function () {
- $scope.modal.hide();
- };
- $scope.vm={
- dream:'',
- about:'',
- money:""
- };
- $scope.imgServer = config.imgServer;
- $scope.imgs = [];
- $scope.video = {
- isOK: false,
- path: '',
- server:''
- }
-
- $scope.addpict = function () {
- common.chooseImage().then(function (img) {
- common.uploadFiles(img,1).then(function (result) {
- var response = JSON.parse(result.response);
- var file = response.data.file;
- $scope.imgs.push(file);
- }, function (error) {
- msg.error('图片上传失败');
- });
- }, function (error) {
- msg.error('图片选择失败');
- });
- }
- $scope.addvideo = function () {
- var options = { limit: 1, duration:20};
- navigator.device.capture.captureVideo(function (videos) {
- $scope.video.path = videos[0].fullPath;
- $scope.video.isOK = true;
- common.uploadFiles(videos[0].fullPath, 2).then(function (result) {
- var response = JSON.parse(result.response);
- var file = response.data.file;
- $scope.video.server = file;
- }, function (error) {
- msg.error('视频上传失败');
- });
- }, function (error) {
- msg.error('视频上传失败');
- }, options);
- }
- $scope.deletefile = function (file) {
- var index = $scope.imgs.indexOf(file);
- $scope.imgs.splice(index, 1);
- common.deletefile(file).then(function () {
- })
- }
- $scope.add = function () {
- var data = {
- pics: $scope.imgs,
- video:$scope.video.server,
- dream: $scope.vm.dream,
- about: $scope.vm.about,
- time: 21, //默认21
- money: $scope.vm.money
- };
- msg.loading('保存中...');
- dreamService.addDream(data).then(function (result) {
- msg.hide();
- $state.go('app.home');
- }, function (error) {
- msg.hide();
- msg.error(error.data.message);
- });
- }
- $scope.$on('$ionicView.beforeEnter', function (viewResult) {
- $ionicTabsDelegate.showBar(false);
- $ionicNavBarDelegate.showBackButton(true);
- });
- $scope.$on('$ionicView.leave', function () {
- $ionicTabsDelegate.showBar(true);
- });
- }]);
- })(angular.module('app.controllers'));
|