123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- angular.module('push')
- .controller('newNotificationCtrl', function ($scope, $sce, $stateParams, ResourceLibraryService, $ionicPopup, UserService, CommentService, AccountService, $ionicActionSheet, UtilService, $timeout, CommonService) {
- //$scope.notice为空即新增,非空即编辑
- $scope.notice = $stateParams.notice;
- $scope.noticecontent = $sce.trustAsHtml($scope.notice.content);
- ResourceLibraryService.getPictureList($scope.notice.unique, $scope.notice.creator).then(function (res) {
- if(res.code == 3350) {
- $scope.picturelist = res.data;
- angular.forEach($scope.picturelist, function(picture){
- angular.forEach($scope.formList, function(form){
- if(form.doctype == picture.doctype){
- form.imageSaveList.push(picture);
- }
- })
- })
- }
- })
- //富文本
- var editor = CKEDITOR.replace('editor');
- $scope.notification = {};
- $scope.notification.title = $scope.notice.newtitle;
- $scope.notification.region = $scope.notice.address;
- $scope.params = {};
- //发送通知公告
- $scope.sendNotice = function () {
- if (!$scope.notification.title) {
- $ionicPopup.alert({
- title: '提示',
- template: "请填写通知公告标题"
- })
- return;
- }
- //notice.snowflakeID存在,即代表编辑功能
- if ($stateParams.notice.snowflakeID) {
- $scope.params.resid = $stateParams.notice.unique;
- }
- $scope.notification.context = editor.getData();
- $scope.notification.summary = editor.document.getBody().getText();
- $scope.params.data = $scope.notification;
- $scope.params.userid = UserService.id;
- $scope.params.node = UserService.node;
- $scope.params.formList = $scope.formList;
- AccountService.publicNotification($scope.params).then(function (res) {
- if (res.code == 3350) {
- if($scope.notice.title){
- $scope.template = '编辑成功';
- }else{
- $scope.template = '发布成功';
- }
- $ionicPopup.alert({
- title: '提示',
- template: $scope.template
- })
- $scope.go("notification");
- }
- })
- }
- //以下皆为添加附件相关方法
- $scope.formList = [{
- title: '附件',
- content: '[]',
- type: 'upload',
- needed: true,
- imagelist: [],
- imageSaveList: [],
- imageDeleteList: [],
- doctype: 4902,
- remarkType: 'normal',
- rowMargin: true
- }, {
- title: '图片',
- content: '[]',
- type: 'upload',
- needed: false,
- imagelist: [],
- imageSaveList: [],
- imageDeleteList: [],
- doctype: 4901,
- remarkType: 'add'
- }
- ];
- $scope.addImage = function (index) {
- listIndex = index;
- if ($scope.app) {
- var list = [
- {text: '<a class="action-sheet-push">拍照</a>'},
- {text: '<a class="action-sheet-push">从相册上传</a>'},
- ];
- var clickfunction = function (indx) {
- if (indx == 0) {
- $scope.openCamera();
- } else {
- getPictures();
- }
- return true;
- }
- } else {
- // var list = [
- // {text: '<a class="action-sheet-push">从相册上传</a>'},
- // ];
- // var clickfunction = function (indx) {
- // if (indx == 0) {
- var files;
- if (index == 0) {
- files = document.getElementById('file');
- } else {
- files = document.getElementById('img');
- }
- files.click();
- $(files).unbind().on('change', function (e) {
- // console.log(e);
- if (index == 1) {
- var str=document.getElementById('img').value.split('.');
- if(str&&str.length>0&&str[1]!='jpg'&&str[1]!='gif'&&str[1]!='bmp'&&str[1]!='png'&&str[1]!='jpeg'&&str[1]!='tiff'&&str[1]!='pjp'&& str[1]!='pjpeg'&&str[1]!='jfif'&&str[1]!='tif'&&str[1]!='svg'&&str[1]!='svgz'&&str[1]!='webp'&&str[1]!='ico'&&str[1]!='xbm'&&str[1]!='dib') {
- $ionicPopup.alert({
- title: '提示',
- template: '请上传图片!'
- });
- return;
- }
- }
- $.each(e.target.files, function (i, file) {
- var url = null;
- if (window.createObjectURL != undefined) { // basic
- url = window.createObjectURL(file);
- } else if (window.URL != undefined) { // mozilla(firefox)
- url = window.URL.createObjectURL(file);
- } else if (window.webkitURL != undefined) { // webkit or chrome
- url = window.webkitURL.createObjectURL(file);
- }
- $scope.formList[listIndex].imagelist.push({photoName: url, originalName: url});
- })
- $.each(e.target.files, function (i, file) {
- var data = new FormData();
- data.append('file', file);
- CommonService.webUploadImage(data).then(function (res) {
- var temp = {
- id: 0,
- title: res.title,
- doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
- isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
- photoName: res.photoName,
- originalName: res.originalName,
- sourceName: res.sourceName,
- sourceSize: res.sourceSize
- }
- $scope.formList[listIndex].imageSaveList.push(temp);
- // console.log(temp);
- // console.log($scope.formList[listIndex]);
- })
- });
- })
- // }
- return true;
- // }
- }
- $ionicActionSheet.show({
- buttons: list,
- cancelText: '取消',
- buttonClicked: clickfunction
- })
- }
- $scope.openCamera = function () {
- if ($scope.formList[listIndex].imagelist.length >= 9) {
- if ($scope.app) {
- UtilService.showMess("最多选取9张图片");
- } else {
- CommonService.showMessage("最多选取9张图片", $scope)
- }
- return;
- }
- UtilService.getPicture(1).then(function (results) {
- $scope.showLoadingToast();
- $scope.formList[listIndex].imagelist.push({photoName: results, originalName: results})
- UtilService.uploadFile([results], 0, "image/jpeg").then(function (response) {
- angular.forEach(response, function (value) {
- $scope.formList[listIndex].imageSaveList.push({
- id: 0,
- title: response.getTitle(),
- doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
- isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
- photoName: value.photoName,
- originalName: value.originalName,
- sourceName: value.sourceName,
- sourceSize: value.sourceSize
- })
- })
- $scope.hideLoadingToast();
- }, function () {
- $scope.hideLoadingToast();
- if ($scope.app) {
- UtilService.showMess("网络不给力,请重试");
- } else {
- CommonService.showMessage("网络不给力,请重试", $scope)
- }
- });
- $ionicScrollDelegate.$getByHandle("scrollimage").resize();
- }, function (err) {
- });
- }
- var getPictures = function () {
- if (device.platform == "Android") {
- verifyStorage();
- } else {
- getPic();
- }
- };
- var verifyStorage = function () {
- window.imagePicker.verifyStorage(
- function (results) {
- if (results == "1") {
- getPic();
- }
- }, function (error) {
- }
- );
- };
- var getPic = function () {
- var imagelistLength = $scope.formList[listIndex].imagelist.length;
- if (imagelistLength >= 9) {
- if ($scope.app) {
- UtilService.showMess("最多选取9张图片");
- } else {
- CommonService.showMessage("最多选取9张图片", $scope)
- }
- return;
- }
- UtilService.getPictureList(9 - imagelistLength).then(function (results) {
- $scope.showLoadingToast();
- angular.forEach(results, function (val, i) {
- $scope.formList[listIndex].imagelist.push({photoName: val, originalName: val});
- })
- UtilService.uploadFile(results, 0, "image/jpeg").then(function (response) {
- angular.forEach(response, function (value) {
- if (value.status) {
- $scope.formList[listIndex].imageSaveList.push({
- id: 0,
- title: response.getTitle(),
- doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
- isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
- photoName: value.photoName,
- originalName: value.originalName,
- sourceName: value.sourceName,
- sourceSize: value.sourceSize
- });
- }
- })
- $scope.hideLoadingToast();
- }, function () {
- $scope.hideLoadingToast();
- if ($scope.app) {
- UtilService.showMess("网络不给力,请重试");
- } else {
- CommonService.showMessage("网络不给力,请重试", $scope)
- }
- });
- $ionicScrollDelegate.$getByHandle("scrollimage").resize();
- }, function (err) {
- });
- };
- //删除图片
- $scope.deletePhoto = function (index, outerIndex) {
- console.log($scope.formList[outerIndex]);
- if ($scope.formList[outerIndex].imageSaveList[index].id != 0) {
- $scope.formList[outerIndex].imageSaveList[index].isenabled = 2;
- $scope.formList[outerIndex].imageDeleteList.push($scope.formList[outerIndex].imageSaveList[index]);
- }
- $scope.formList[outerIndex].imagelist.splice(index, 1);
- $scope.formList[outerIndex].imageSaveList.splice(index, 1);
- // console.log($scope.formList[outerIndex].imagelist);
- // console.log($scope.formList[outerIndex].imageSaveList);
- // console.log($scope.formList[outerIndex].imageDeleteList);
- }
- $scope.uploadPic = function (e) {
- // console.log(2);
- // console.log(e.target);
- }
- })
- ;
|