1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948 |
- var starter = angular.module('starter', ['ionic', 'ngResource', 'underscore', 'ngCordova', 'pascalprecht.translate']);
- starter.run(function ($ionicPlatform, $rootScope, $http, formatFilter, $q, $cordovaPreferences, $ionicLoading, $timeout, $ionicHistory, $cordovaKeyboard, $translate, global, cfg, showPopup) {
- // $ionicLoading.show({
- // template: '数据加载中...'
- // }).then(function () {
- // console.log("loading starter.run");
- // });
- $rootScope.commons = {
- refresh: false,
- upload_maxcount: 10,
- bigImage: undefined, //显示大图
- modal: undefined, //模态窗口
- goBackIsDisable: undefined, //禁用返回键
- isShowPopup: undefined, //加载动画
- fun: null
- };
- $ionicPlatform.ready(function () {
- if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
- cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
- cordova.plugins.Keyboard.disableScroll(true);
- }
- if (window.StatusBar) {
- StatusBar.styleDefault();
- }
- // $ionicLoading.hide();
- if (window.cordovaLinker)
- window.cordovaLinker.loadFinished("", function () {
- }, function () {
- });
- if (typeof navigator.globalization !== "undefined") {
- navigator.globalization.getPreferredLanguage(function (language) {
- console.log("globalization -> " + JSON.stringify(language));
- // alert(JSON.stringify(language))
- var value = (language.value).split('-')[0];
- if ((language.value).split('-')[1] == 'TW') {
- value = language.value
- }
- switch (value) {
- case 'zh-TW':
- value = 'locate-zh_tw';
- break;
- case 'en':
- value = 'locate-en_us';
- break;
- case 'zh':
- default:
- value = 'locate-zh_cn';
- break;
- }
- $translate.use(value).then(function (data) {
- console.log("SUCCESS -> " + data);
- }, function (error) {
- console.log("ERROR -> " + error);
- });
- });
- }
- });
- global.fetch_user = function () {
- var deferred = $q.defer();
- if (global.user && global.user.token) {
- usergot(global.user, deferred)
- } else if (ionic.Platform.platform() == 'win32' || ionic.Platform.platform() == 'linux') {
- $http.post(formatFilter('{0}authcheck/', cfg.api), "imid=zPayHMi6s&password=123456", {
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded'
- }
- }).then(function (response) {
- usergot(response.data, deferred);
- }, function (error) {
- console.log('通过post方式获取用户信息authcheck失败' + error);
- deferred.reject(error);
- })
- } else {
- $ionicPlatform.ready(function () {
- $cordovaPreferences.fetch('user')
- .success(function (value) {
- usergot(ionic.Platform.isAndroid() ? JSON.parse(value) : value, deferred);
- })
- .error(function (error) {
- console.error("通过$cordovaPreferences方式获取用户信息失败: " + error);
- deferred.reject(error);
- });
- });
- }
- return deferred.promise;
- };
- usergot = function (data, deferred) {
- global.user = data;
- if (data.cfg) {
- global.api = data.cfg.api;
- }
- deferred.resolve(data);
- console.warn(JSON.stringify(global.user));
- };
- global.fetch_user();
- global.goBack = function () {
- if (window.cordovaLinker != undefined) {
- if ($ionicHistory.backView()) {
- $ionicHistory.goBack();
- } else {
- window.cordovaLinker.goBack(1, function (s) {
- console.log(s);
- }, function (err) {
- console.error(err);
- });
- }
- }
- }
- function keyboardHideHandler(e) {
- cordova.plugins.Keyboard.isVisible = true;
- $timeout(function () {
- cordova.plugins.Keyboard.isVisible = false;
- }, 100);
- }
- window.addEventListener('native.keyboardhide', keyboardHideHandler);
- $ionicPlatform.registerBackButtonAction(function (e) {
- $timeout(function () {
- if ($rootScope.commons.isShowPopup) {
- showPopup.hideLoading();
- } else if ($rootScope.commons.goBackIsDisable) {
- return false;
- } else if ($cordovaKeyboard.isVisible()) {
- $cordovaKeyboard.close();
- } else if ($rootScope.commons.bigImage) {
- if ($rootScope.commons.fun == null) $rootScope.commons.bigImage = false;
- else {
- $rootScope.commons.fun();
- $rootScope.commons.fun = null;
- }
- } else if ($rootScope.commons.modal != null) {
- if ($rootScope.commons.fun == null) {
- $rootScope.commons.modal.hide();
- $rootScope.commons.modal = null;
- } else {
- $rootScope.commons.fun();
- $rootScope.commons.fun = null;
- }
- } else {
- if ($ionicHistory.backView()) {
- if ($rootScope.commons.fun == null) {
- $ionicHistory.goBack();
- } else {
- $rootScope.commons.fun();
- $rootScope.commons.fun = null;
- }
- } else {
- global.goBack();
- }
- }
- return false;
- })
- }, 201);
- var _user;
- _user = window.localStorage.getItem("global.user");
- if (_user != undefined) {
- console.log("localStorage get: " + _user);
- global.user = JSON.parse(_user);
- }
- })
- .config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider, $httpProvider, $provide, $translateProvider, $resourceProvider, cfg) {
- $ionicConfigProvider.platform.ios.tabs.style('standard');
- $ionicConfigProvider.platform.ios.tabs.position('bottom');
- $ionicConfigProvider.platform.android.tabs.style('standard');
- $ionicConfigProvider.platform.android.tabs.position('bottom');
- $ionicConfigProvider.platform.ios.navBar.alignTitle('center');
- $ionicConfigProvider.platform.android.navBar.alignTitle('center');
- $ionicConfigProvider.platform.ios.backButton.previousTitleText('').icon('ion-ios-arrow-thin-left');
- $ionicConfigProvider.platform.android.backButton.previousTitleText('').icon('ion-android-arrow-back');
- $ionicConfigProvider.platform.ios.views.transition('ios');
- $ionicConfigProvider.platform.android.views.transition('android');
- var regex = new RegExp('\.(html|js|css|png|jpg)$', 'i');
- var isAsset = function (url) {
- return regex.test(url);
- };
- $stateProvider.state('selectmember', {
- url: '/selectmember',
- templateUrl: '/templates/common/selectmember.html',
- controller: 'SelectMemberCtrl'
- })
- .state('selectsinglemember', {
- url: '/selectsinglemember',
- templateUrl: '/templates/common/selectsinglemember.html',
- controller: 'SelectSingleMemberCtrl'
- })
- .state('selectdept', {
- url: '/selectdept/:id',
- templateUrl: '/templates/common/selectdept.html',
- controller: 'SelectDeptCtrl'
- })
- .state('fieldtype', {
- url: '/fieldtype/:id',
- templateUrl: '/templates/common/fieldtype.html',
- controller: 'FormFieldTypeCtrl'
- })
- .state('transfer', {
- url: '/transfer/:module/:id',
- templateUrl: '/templates/common/transfer.html',
- controller: 'TransferCtrl'
- })
- .state('selectsingledept', {
- url: '/selectsingledept',
- templateUrl: '/templates/common/selectsingledept.html',
- controller: 'SelectSingleDeptCtrl'
- })
- $urlRouterProvider.otherwise('/index');
- $translateProvider.useStaticFilesLoader({
- prefix: '/i18n/',
- suffix: '.json'
- });
- $httpProvider.interceptors.push(function ($q, cfg, global) {
- return {
- 'request': function (config) {
- if (!isAsset(config.url) && (global.refresh || global.debug)) { //if the call is not for an asset file
- config.url += (config.url.indexOf("?") === -1 ? "?" : "&") + "v=" + Date.now();
- if (global.refresh)
- global.refresh = false;
- }
- if (config.url.startsWith(cfg.api) || config.url.indexOf(global.api) == 0) {//分页时自带了请求路径
- if (config.url.startsWith(cfg.api)) config.url = global.api + config.url;
- console.log(angular.lowercase(config.method) + " url: " + config.url);
- if (global.user.token) {
- config.headers['authorization'] = 'Token ' + global.user.token;
- console.log(' authorization:' + config.headers['authorization']);
- }
- }
- config.timeout = 10000;
- return config;
- },
- 'responseError': function (rejection) {
- console.error(JSON.stringify(rejection));
- return $q.reject(rejection);
- }
- };
- });
- $resourceProvider.defaults.stripTrailingSlashes = false;
- $resourceProvider.defaults.actions.update = {
- method: 'PUT',
- params: {
- id: "@id"
- }
- };
- $resourceProvider.defaults.actions.patch = {
- method: 'PATCH',
- };
- })
- .constant('cfg', {
- api: '/api/'
- })
- .value('global', {
- user: {
- usrid: "",
- token: "",
- usrname: "",
- compno: "",
- compname: "",
- deptno: "",
- deptname: "",
- roleid: "",
- im_usrid: "",
- cellphone: "",
- password: ""
- },
- api: "",
- debug: true,
- refresh: false
- })
- _.mixin({
- diff: function (_new, _old) {
- var r = {C: [], D: [], U: []};
- list_new = _.pluck(_new, 'id');
- list_old = _.pluck(_old, 'id');
- r.D = _.difference(list_old, list_new).join(',');
- r.C = _.filter(_new, function (item) {
- return item.id == undefined;
- });
- r.U = _.map(_.filter(_new, function (item) {
- return item.isModified && item.id != undefined;
- }), _.clone);
- _.each(r.U, function (item) {
- delete item.isModified;
- });
- _.each(r.C, function (item) {
- delete item.isModified;
- });
- return r;
- }
- });
- //http://stackoverflow.com/questions/33106114/cordova-javascript-error-has-no-method-startswith-android
- if (typeof String.prototype.startsWith != 'function') {
- String.prototype.startsWith = function (str) {
- return this.indexOf(str) === 0;
- };
- }
- starter.controller('SelectParentCtrl', function ($scope, $state, Member) {
- $scope.deptlst = [];
- $scope.emplst = [];
- $scope.index = 0;
- $scope.isUp = false;
- $scope.deptid = 1;
- $scope.titlename = Member.titlename;
- $scope.selectedemplst = Member.selectedemplst;
- $scope.disabled = Member.disabled;
- $scope.showall = Member.showall;
- $scope.showgroup = Member.showgroup;
- $scope.loading = true;
- $scope.leftbtn = [{
- text: '取消',
- click: 'cancel'
- }, {
- text: '上一层',
- click: 'up'
- }];
- })
- .controller('SelectMemberCtrl', function ($scope, $state, $ionicHistory, $rootScope, $ionicModal, $timeout, $controller, Dept, Member) {
- var parentctrl = $controller('SelectParentCtrl', {$scope: $scope});
- var showgroupmodel = $ionicModal.fromTemplateUrl('/templates/common/modal-selectgroup.html', {
- scope: $scope,
- animation: 'slide-in-right'
- });
- var startdept = null;
- $rootScope.commons.goBackIsDisable = true;
- var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
- if (Member.homerenderdata.length != 0) {
- $scope.loading = false;
- _.each(Member.homerenderdata, function (item) {
- $scope.deptlst.push(item);
- });
- init_selected(Member.resourcemember);
- } else {
- Dept.getDep().then(function (data) {
- startdept = _.find(data, function (itemdept) {
- return itemdept.parent == null; //获取公司的顶层部门
- });
- getemp(startdept.id);
- data = _.filter(data, function (item) {
- return item.parent == startdept.id;
- });
- $scope.deptlst = data;
- init_selected(Member.resourcemember);
- }, function (err) {
- alert(JSON.stringify(err))
- });
- }
- });
- $scope.changeindex = function (index, dtid) {
- $scope.index = index;
- $scope.deptid = dtid;
- };
- $scope.change = function (emp) {
- if (emp.selected) {
- $scope.selectedemplst.push(emp);
- Member.selectedemplst = $scope.selectedemplst;
- } else {
- $scope.selectedemplst = _.filter($scope.selectedemplst, function (e) {
- return e.user_id != parseInt(emp.user_id);
- });
- Member.selectedemplst = $scope.selectedemplst;
- }
- setselectedcount();
- };
- $scope.up = function () {
- var dept = undefined;
- if (Member.homerenderdata.length > 0) {
- dept = _.find(Member.homerenderdata, function (item) {
- return item.id == parseInt($scope.deptid);
- })
- }
- if (dept != undefined) {
- $scope.deptlst = $scope.deptlst.concat(Member.homerenderdata);
- $scope.emplst = [];
- $scope.index = 0;
- } else {
- dept = _.find(Dept.all(), function (d) {
- return d.id == parseInt($scope.deptid);
- });
- getdept_emp(dept.parent);
- }
- };
- $scope.cancel = function () {
- Member.selectedemplst = [];
- Member.dialogresult = 0;
- if (Member.cancelroutename != "") {
- $state.go(Member.cancelroutename, Member.cancelrouteparams);
- } else {
- $ionicHistory.goBack();
- }
- };
- var dep = {};
- $scope.changedept = function (dept) {
- dep = dept;
- getdept_emp(dept.id);
- };
- $scope.ok = function () {
- Member.dialogresult = 1;
- Member.all = 0;
- if (Member.routename != '') {
- $state.go(Member.routename, Member.routeparams);
- } else {
- $ionicHistory.goBack(); //todo:带参数跳转
- }
- };
- $scope.selectAll = function () {
- Member.all = 1;
- $state.go(Member.routename, Member.routeparams);
- };
- $scope.back = function () {
- if ($rootScope.commons.modal != null) {
- $rootScope.commons.modal.hide();
- }
- };
- $scope.toselectgroup = function () {
- showgroupmodel.then(function (modal) {
- $rootScope.commons.modal = modal;
- $rootScope.commons.modal.show();
- });
- };
- $scope.$on("$destroy", function () {
- $rootScope.commons.goBackIsDisable = false;
- Member.member = {};
- });
- function init_selected(data) {
- setdeptrighticon($scope.deptlst);
- Member.selectedemplst = [];
- if (!Member.disabled) {
- $scope.selectedemplst = $scope.selectedemplst.concat(data);
- Member.selectedemplst = $scope.selectedemplst;
- }
- setselectedcount();
- }
- function getemp(id) {
- Dept.getEmp(id).then(function (data) {
- console.log(data);
- Member.member[id.toString()] = angular.copy(data);
- $scope.emplst = data;
- setitem();
- $scope.loading = false;
- });
- }
- function getdept_emp(did) {
- if (Member.member[did.toString()]) {
- set_member(did);
- } else {
- $scope.loading = true;
- Dept.getEmp(did).then(function (data) {
- Member.member[did.toString()] = angular.copy(data);
- set_member(did);
- $scope.loading = false;
- }, function (err) {
- $scope.loading = false;
- });
- }
- }
- var set_member = function (did) {
- $scope.deptlst = Dept.getChildDept(did);
- setdeptrighticon($scope.deptlst);
- $scope.emplst = Member.member[did.toString()];
- setitem();
- $scope.deptid = did;
- $scope.index = (startdept && did == startdept.id) ? 0 : 1;
- };
- function setselectedcount() {
- $scope.selectcount = $scope.selectedemplst.length > 0 ? "(" + $scope.selectedemplst.length + ")" : "";
- }
- function setitem() {
- _.each($scope.emplst, function (e) {
- e.selected = false;
- e.disabled = false;
- e.depname = dep.depname;
- set_isenable(e, Member.resourcemember, true);
- set_isenable(e, Member.unenabledata, false);
- var e1 = _.find($scope.selectedemplst, {'user_id': e.user_id});
- if (e1 != undefined) e.selected = true;
- });
- }
- function set_isenable(e, data, op) {
- var p = _.find(data, {'user_id': e.user_id});
- if (p != undefined) {
- e.disabled = e.selected = true;
- if (!Member.disabled && op) e.disabled = false;
- }
- }
- function setdeptrighticon(deptlst) {
- _.each(deptlst, function (d) {
- d.isShow = isShow(d);
- })
- }
- function isShow(dept) {
- var childdepts = Dept.getChildDept(dept.id);
- return !(childdepts.length == 0);
- }
- })
- .controller('SelectSingleMemberCtrl', function ($scope, $ionicHistory, $state, $controller, Dept, Member) {
- var parentctrl = $controller('SelectParentCtrl', {$scope: $scope});
- var startdept = {};
- $scope.init = function () {
- Dept.getDep().then(function (data) {
- startdept = _.find(data, function (itemdept) {
- return itemdept.parent == null; //获取公司的顶层部门
- });
- getemp(startdept.id);
- data = _.filter(data, function (item) {
- return item.parent == startdept.id;
- });
- $scope.deptlst = data;
- setdeptrighticon($scope.deptlst);
- });
- };
- $scope.changeindex = function (index, dtid) {
- $scope.index = index;
- $scope.deptid = dtid;
- };
- $scope.change = function (emp) {
- Member.dialogresult = 1;
- Member.selectedemplst.push(emp);
- if (Member.routename != '') {
- $state.go(Member.routename, Member.routeparams);
- } else {
- $ionicHistory.goBack(); //todo:带参数跳转
- }
- };
- $scope.up = function () {
- var dept = _.find(Dept.all(), function (d) {
- return d.id == parseInt($scope.deptid);
- });
- getdept_emp(dept.parent);
- };
- $scope.cancel = function () {
- Member.dialogresult = 0;
- Member.selectedemplst = [];
- $ionicHistory.goBack();
- };
- var dep = {};
- $scope.changedept = function (dept) {
- dep = dept;
- getdept_emp(dept.id);
- };
- $scope.deptdisplay = function () {
- return $scope.deptlst.length > 0;
- };
- function getemp(deptid) {
- Dept.getEmp(deptid).then(function (data) {
- Member.member[deptid.toString()] = angular.copy(data);
- $scope.emplst = data;
- setitem();
- $scope.loading = false;
- });
- }
- function getdept_emp(did) {
- if (Member.member[did.toString()]) {
- set_member(did);
- } else {
- $scope.loading = true;
- Dept.getEmp(did).then(function (data) {
- Member.member[did.toString()] = angular.copy(data);
- set_member(did);
- $scope.loading = false;
- });
- }
- }
- var set_member = function (did) {
- $scope.deptlst = Dept.getChildDept(did);
- setdeptrighticon($scope.deptlst);
- $scope.emplst = Member.member[did.toString()];
- setitem();
- $scope.deptid = did;
- $scope.index = (startdept && did == startdept.id) ? 0 : 1;
- };
- function setitem() {
- _.each($scope.emplst, function (e) {
- e.selected = false;
- e.disabled = false;
- e.depname = dep.depname;
- _.each(Member.resourcemember, function (p) {
- if (p.user_id == parseInt(e.user_id)) {
- e.disabled = true;
- e.selected = true;
- if (!Member.disabled) e.disabled = false;
- }
- });
- _.each($scope.selectedemplst, function (e1) {
- if (e1.user_id == e.user_id) e.selected = true;
- });
- });
- }
- function setdeptrighticon(deptlst) {
- _.each(deptlst, function (d) {
- d.isShow = isShow(d);
- })
- }
- function isShow(dept) {
- return Dept.getChildDept(dept.id).length != 0;
- }
- $scope.$on("$destroy", function () {
- Member.member = {};
- });
- })
- .controller('SelectDeptCtrl', function ($scope, $state, $ionicHistory, $timeout, $controller, Dept, Member) {
- var parentctrl = $controller('SelectParentCtrl', {$scope: $scope});
- $scope.id = $state.params['id'];
- $scope.selecteddepts = Member.selecteddepts;
- $scope.selectdeptcount = '';
- $scope.isallcheck = Member.isallcheck;
- $scope.flag = 0;
- $scope.isAll = false;
- var deptid = 1;
- var resourcedept = [];
- var startdept = null;
- $scope.isAllCheck = function () {
- Member.dialogresult = 1;
- $scope.isallcheck = !$scope.isallcheck;
- Member.isallcheck = $scope.isallcheck;
- if (Member.isallcheck) {
- Member.selecteddepts = [];
- if (Member.routename != '') {
- $state.go(Member.routename, Member.routeparams);
- } else {
- $ionicHistory.goBack(); //todo:带参数跳转
- }
- }
- };
- $scope.cancel = function () {
- Member.dialogresult = 0;
- Member.selecteddepts = [];
- $ionicHistory.goBack();
- };
- $scope.ok = function () {
- console.log($scope.selecteddepts.length);
- Member.dialogresult = 1;
- Member.all = 0;
- if (Member.routename != '') {
- $state.go(Member.routename, Member.routeparams);
- } else {
- $ionicHistory.goBack(); //todo:带参数跳转
- }
- };
- $scope.up = function () {
- if ($scope.index == 0 && Member.showall) {
- $scope.showall = true;
- }
- var dept = _.find(Dept.all(), function (d) {
- return d.id == parseInt(deptid);
- });
- getChildDept(dept.parent);
- };
- $scope.change = function (dept) {
- if (Member.isallcheck) {
- $scope.isallcheck = !$scope.isallcheck;
- Member.isallcheck = $scope.isallcheck;
- }
- if (dept.selected) {
- $scope.selecteddepts.push(dept);
- Member.selecteddepts = $scope.selecteddepts;
- } else {
- $scope.selecteddepts = _.filter($scope.selecteddepts, function (e) {
- return e.id != parseInt(dept.id);
- });
- Member.selecteddepts = $scope.selecteddepts;
- }
- setselectedcount();
- };
- $scope.tochilddept = function (dept) {
- if ($scope.index == startdept.id) {
- $scope.showall = false;
- }
- getChildDept(dept.id);
- };
- function setdept(data) {
- _.each(data, function (item) {
- item.selected = false;
- item.isdisabled = false;
- item.ishide = false;
- item.disableddesc = '';
- item.isShow = isShow(item);
- if (Member.datatype == 3) {
- if (item.diarymobid != null && $state.params["id"] != item.diarymobid) {
- item.disableddesc = '(已设置)';
- item.isdisabled = true;
- }
- } else if (Member.datatype == 4) {
- if (item.workatdsetid != null && $state.params["id"] != item.workatdsetid) {
- item.disableddesc = '(已设置)';
- item.isdisabled = true;
- }
- }
- if (_.find(Member.resourcemember, function (rsc) {
- return rsc.id == item.id ? true : false
- })) {
- item.selected = true;
- }
- });
- $scope.deptlst = data;
- }
- function getChildDept(did) {
- var childdepts = Dept.getChildDept(did);
- if (childdepts.length > 0) {
- deptid = did;
- if (did == startdept.id) {
- $scope.index = 0;
- } else {
- $scope.index = 1;
- }
- setdept(childdepts);
- }
- }
- function setselectedcount() {
- if (Member.selecteddepts.length > 0) {
- $scope.selectcount = "(" + Member.selecteddepts.length + ")";
- } else {
- $scope.selectcount = "";
- }
- }
- function isShow(dept) {
- var childdepts = Dept.getChildDept(dept.id);
- if (childdepts.length == 0) {
- return false;
- } else {
- return true;
- }
- }
- var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
- $scope.loading = true;
- Dept.getDep().then(function (data) {
- startdept = _.find(data, function (itemdept) {
- return itemdept.parent == null; //获取公司的顶层部门
- });
- Member.selecteddepts = Member.resourcemember;
- $scope.selecteddepts = Member.selecteddepts;
- if (Member.datatype == 3) {
- _.each(data, function (item) {
- if (item.diarymobid != null) {
- $scope.flag++;
- }
- if (item.id == 1 && item.diarymobid != null) {
- $scope.isAll = true;
- }
- })
- } else if (Member.datatype == 4) {
- _.each(data, function (item) {
- if (item.workatdsetid != null) {
- $scope.flag++;
- }
- if (item.id == 1 && item.workatdsetid != null) {
- $scope.isAll = true;
- }
- })
- }
- if ($scope.id == -1) {
- if ($scope.flag == 1 && $scope.isAll) {
- $scope.showall = true;
- } else if ($scope.flag >= 1 && !$scope.isAll) {
- $scope.showall = false;
- }
- if ($scope.flag >= 1 && $scope.flag + 1 == data.length && !$scope.isAll) {
- $scope.isAll = true;
- }
- } else {
- if ($scope.flag == 1 && $scope.isAll) {
- $scope.showall = true;
- } else if ($scope.flag >= 1 && !$scope.isAll && Member.resourcemember.length == 0) {
- $scope.showall = true;
- } else if ($scope.flag >= 1 && !$scope.isAll && $scope.flag == Member.resourcemember.length) {
- $scope.showall = true;
- } else if ($scope.flag >= 1 && !$scope.isAll && $scope.flag != Member.resourcemember.length) {
- $scope.showall = false;
- }
- }
- var rst = _.filter(data, function (a) {
- return (a.level === 1);
- });
- setdept(rst);
- if (!Member.disabled) {
- _.each(Member.resourcemember, function (m) {
- $scope.selecteddepts.push(m);
- });
- Member.selecteddepts = $scope.selecteddepts;
- }
- setselectedcount();
- }).finally(function () {
- $scope.loading = false;
- });
- });
- $scope.$on("$destroy", function () {
- beforeEnter = null;
- })
- })
- .controller('SelectSingleDeptCtrl', function ($scope, $state, $ionicHistory, $timeout, Dept, Member) {
- $scope.titlename = Member.titlename;
- var active_dept_id = 1;
- var startdept = null;
- $scope.leftbtn = [{
- text: '取消',
- click: 'cancel'
- }, {
- text: '上一层',
- click: 'up'
- }];
- var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
- $scope.loading = true;
- Dept.getDep().then(function (data) {
- startdept = _.find(data, {'parent': null});
- $scope.id = Member.resourcemember.length > 0 ? Member.resourcemember[0].id : null;
- getChildDept(startdept.id);
- }).finally(function () {
- $scope.loading = false;
- });
- });
- $scope.cancel = function () {
- Member.dialogresult = 0;
- Member.selecteddepts = [];
- $ionicHistory.goBack();
- };
- $scope.up = function () {
- getChildDept(_.find(Dept.all(), {'id': active_dept_id}).parent);
- };
- $scope.change = function (dept) {
- Member.selecteddepts = [];
- if (dept.selected) {
- Member.selecteddepts.push(dept);
- Member.routename == "" ? $ionicHistory.goBack() : $state.go(Member.routename, Member.routeparams);
- }
- };
- $scope.tochilddept = function (dept) {
- getChildDept(dept.id);
- };
- $scope.is_showright = function (dept) {
- return Dept.getChildDept(dept.id).length > 0;
- };
- function getChildDept(did) {
- var childdepts = Dept.getChildDept(did);
- if (childdepts.length > 0) {
- active_dept_id = did;
- $scope.index = did == startdept.id ? 0 : 1;
- var item = _.find(childdepts, {'id': $scope.id});
- if (item != undefined) item.selected = item != undefined;
- $scope.deptlst = childdepts;
- }
- }
- $scope.$on("$destroy", function () {
- beforeEnter = null;
- })
- })
- .controller('TransferCtrl', function ($scope, $state, $stateParams, $ionicPopup, $ionicHistory, global, Member) {
- $scope.selectmember = function () {
- $scope.isremove = false;
- Member.resourcemember = [];
- Member.resourcemember.push({
- id: global.user.usrid
- });
- Member.routename = '';
- Member.titlename = '选择联系人';
- $state.go('selectmember');
- };
- $scope.goback = function () {
- $ionicHistory.goBack();
- };
- function selectMember() {
- if (Member.selectedemplst.length > 0) {
- $scope.memberlist.push(global.user.imusrid);
- _.each(Member.selectedemplst, function (item) {
- $scope.memberlist.push(item.im_usrid);
- });
- Member.selectedemplst = [];
- if (window.cordovaLinker != undefined) {
- var discussion = {
- name: "讨论组",
- ids: []
- };
- discussion.ids = $scope.memberlist;
- window.cordovaLinker.discuss(discussion, function (s) {
- console.log(s);
- var confirmPopup = $ionicPopup.confirm({
- title: '<br/><div>转发至</div><br/>',
- subTitle: discussion.name,
- okText: '是',
- cancelText: '否'
- });
- confirmPopup.then(function (res) {
- if (res) {
- //:todo转发
- }
- });
- }, function (err) {
- console.error(err);
- });
- }
- Member.resourcemember = [];
- }
- }
- var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
- $scope.module = $stateParams.module;
- $scope.id = $stateParams.id;
- $scope.linkurl = '/tab/app/' + $scope.module + '/' + $scope.id;
- console.log($scope.linkurl);
- $scope.memberlist = [];
- $scope.popup = {
- isPopup: false
- };
- selectMember();
- });
- $scope.$on("$destroy", function () {
- beforeEnter = null;
- })
- })
- starter.directive('itemMember', function (Dept) {
- return {
- restrict: 'E',
- replace: true,
- template: '<div><ion-checkbox ng-model="emp.selected" ng-disabled="emp.disabled" ng-change="change(emp)" class="ion-checkbox-class">' +
- '<img ng-src="../../../img/panda.png" />' +
- '<label class="labelname">{{emp.username}}</label>' +
- '<label class="labelrole">{{emp.degree}}</label>' +
- '</ion-checkbox>' +
- '</div>'
- };
- })
- .directive('itemDept', function (Dept) {
- return {
- restrict: 'E',
- replace: true,
- template: '<div>' +
- '<ion-item class="item item-icon-right" type="item-text-wrap" ng-click="changedept(dept);">' +
- '{{dept.depname}}' +
- '<i class="icon ion-chevron-right icon-accessory" ng-show="dept.isShow"></i>' +
- '</ion-item>' +
- '</div>'
- };
- })
- .directive('footerMember', function (Dept) {
- return {
- restrict: 'E',
- replace: true,
- template: '<div class="bar bar-footer bar-dark footer-div" ng-class={true:"bigview",false:""}[isUp]>' +
- '<i class="cirl-i" ng-class={true:"ion-ios-arrow-down",false:"ion-ios-arrow-up"}[isUp] ng-click="isUp = !isUp"></i>' +
- '<ul class="ul-imgs dept-icon">' +
- '<li ng-repeat="user in selectedemplst">{{user.username}}</li>' +
- '</ul>' +
- '<button ng-disabled="selectedemplst.length==0" ng-click="ok();" class="button pull-right button-calm">确定{{selectcount}}</button>' +
- '</div>'
- };
- })
- .directive('rjCloseBackDrop', [function () {
- return {
- scope: false,
- restrict: 'A',
- replace: false,
- link: function (scope, iElm, iAttrs, controller) {
- var htmlEl = angular.element(document.querySelector('html'));
- htmlEl.unbind("click");
- htmlEl.on("click", function (event) {
- if (event.target.nodeName === "HTML" &&
- scope.popup.optionsPopup &&
- scope.popup.isPopup) {
- scope.popup.optionsPopup.close();
- scope.popup.isPopup = false;
- } else if (event.target.nodeName === "DIV" &&
- scope.popup.optionsPopup &&
- scope.popup.isSetPopup) {
- scope.popup.optionsPopup.close();
- scope.popup.isSetPopup = false;
- }
- });
- }
- };
- }])
- //放大缩小图片
- .directive('ngPinchZoom', [function () {
- var _directive = {
- restrict: 'A',
- scope: false,
- link: _link
- };
- function _link(scope, element, attrs) {
- var elWidth, elHeight;
- // mode : 'pinch' or 'swipe'
- var mode = '';
- // distance between two touche points (mode : 'pinch')
- var distance = 0;
- var initialDistance = 0;
- // image scaling
- var scale = 1;
- var relativeScale = 1;
- var initialScale = 1;
- var maxScale = parseInt(attrs.maxScale, 10);
- if (isNaN(maxScale) || maxScale <= 1) {
- maxScale = 3;
- }
- // position of the upper left corner of the element
- var positionX = 0;
- var positionY = 0;
- var initialPositionX = 0;
- var initialPositionY = 0;
- // central origin (mode : 'pinch')
- var originX = 0;
- var originY = 0;
- // start coordinate and amount of movement (mode : 'swipe')
- var startX = 0;
- var startY = 0;
- var moveX = 0;
- var moveY = 0;
- var image = new Image();
- image.onload = function () {
- elWidth = element[0].clientWidth;
- elHeight = element[0].clientHeight;
- element.css({
- '-webkit-transform-origin': '0 0',
- 'transform-origin': '0 0'
- });
- element.on('touchstart', touchstartHandler);
- element.on('touchmove', touchmoveHandler);
- element.on('touchend', touchendHandler);
- };
- if (attrs.ngSrc) {
- image.src = attrs.ngSrc;
- } else {
- if (attrs.src) {
- image.src = attrs.src;
- }
- }
- /**
- * @param {object} evt
- */
- function touchstartHandler(evt) {
- var touches = evt.originalEvent ? evt.originalEvent.touches : evt.touches;
- startX = touches[0].clientX;
- startY = touches[0].clientY;
- initialPositionX = positionX;
- initialPositionY = positionY;
- moveX = 0;
- moveY = 0;
- }
- /**
- * @param {object} evt
- */
- function touchmoveHandler(evt) {
- var touches = evt.originalEvent ? evt.originalEvent.touches : evt.touches;
- if (mode === '') {
- if (touches.length === 1 && scale > 1) {
- mode = 'swipe';
- } else if (touches.length === 2) {
- mode = 'pinch';
- initialScale = scale;
- initialDistance = getDistance(touches);
- originX = touches[0].clientX -
- parseInt((touches[0].clientX - touches[1].clientX) / 2, 10) -
- element[0].offsetLeft - initialPositionX;
- originY = touches[0].clientY -
- parseInt((touches[0].clientY - touches[1].clientY) / 2, 10) -
- element[0].offsetTop - initialPositionY;
- }
- }
- if (mode === 'swipe') {
- evt.preventDefault();
- moveX = touches[0].clientX - startX;
- moveY = touches[0].clientY - startY;
- positionX = initialPositionX + moveX;
- positionY = initialPositionY + moveY;
- transformElement();
- } else if (mode === 'pinch' && touches.length === 2) {
- evt.preventDefault();
- distance = getDistance(touches);
- relativeScale = distance / initialDistance;
- scale = relativeScale * initialScale;
- positionX = originX * (1 - relativeScale) + initialPositionX + moveX;
- positionY = originY * (1 - relativeScale) + initialPositionY + moveY;
- transformElement();
- }
- }
- /**
- * @param {object} evt
- */
- function touchendHandler(evt) {
- var touches = evt.originalEvent ? evt.originalEvent.touches : evt.touches;
- if (mode === '' || touches.length > 0) {
- return;
- }
- if (scale < 1) {
- scale = 1;
- positionX = 0;
- positionY = 0;
- } else if (scale > maxScale) {
- scale = maxScale;
- relativeScale = scale / initialScale;
- positionX = originX * (1 - relativeScale) + initialPositionX + moveX;
- positionY = originY * (1 - relativeScale) + initialPositionY + moveY;
- } else {
- if (positionX > 0) {
- positionX = 0;
- } else if (positionX < elWidth * (1 - scale)) {
- positionX = elWidth * (1 - scale);
- }
- if (positionY > 0) {
- positionY = 0;
- } else if (positionY < elHeight * (1 - scale)) {
- positionY = elHeight * (1 - scale);
- }
- }
- transformElement(0.1);
- mode = '';
- }
- /**
- * @param {Array} touches
- * @return {number}
- */
- function getDistance(touches) {
- var d = Math.sqrt(Math.pow(touches[0].clientX - touches[1].clientX, 2) +
- Math.pow(touches[0].clientY - touches[1].clientY, 2));
- return parseInt(d, 10);
- }
- /**
- * @param {number} [duration]
- */
- function transformElement(duration) {
- var transition = duration ? 'all cubic-bezier(0,0,.5,1) ' + duration + 's' : '';
- var matrixArray = [scale, 0, 0, scale, positionX, positionY];
- var matrix = 'matrix(' + matrixArray.join(',') + ')';
- element.css({
- '-webkit-transition': transition,
- transition: transition,
- '-webkit-transform': matrix + ' translate3d(0,0,0)',
- transform: matrix
- });
- }
- }
- return _directive;
- }])
- .directive('focusMe', function ($timeout) {
- return {
- scope: {
- trigger: '=focusMe'
- },
- link: function (scope, element) {
- scope.$watch('trigger', function (value) {
- if (value === true) {
- $timeout(function () {
- element[0].focus();
- });
- }
- });
- }
- };
- })
- .directive('imagePopover', [function () {
- return {
- restrict: "E",
- scope: {
- allImages: '='
- },
- template: "<img ng-repeat='img in allImages' ng-click='showImages($index,$event)' ng-src='{{img.file_thumbnail_path}}' class='img-popver-pad'/>",
- controller: function ($scope, $rootScope, $ionicModal) {
- $scope.showImages = function (index, event) {
- if (event != undefined) {
- event.stopPropagation();
- }
- $scope.activeSlide = index;
- $scope.showModal('../../templates/modal-imagepopover.html');
- };
- $scope.bigImage = $rootScope.commons.bigImage;
- $scope.showModal = function (templateUrl) {
- $rootScope.commons.fun = clear_change;
- $rootScope.commons.bigImage = true;
- $ionicModal.fromTemplateUrl(templateUrl, {
- scope: $scope,
- animation: 'slide-in-up'
- }).then(function (modal) {
- $rootScope.commons.modal = modal;
- $rootScope.commons.modal.show();
- });
- };
- $scope.closeModal = function () {
- clear_change();
- $rootScope.commons.fun = null;
- };
- function clear_change() {
- $rootScope.commons.bigImage = false;
- $rootScope.commons.modal.hide();
- $rootScope.commons.modal.remove();
- $rootScope.commons.modal = null;
- }
- }
- }
- }])
- .directive('removePopoverHeader', [function () {
- return {
- restrict: "A",
- link: function (scope, iElm, iAttrs, controller) {
- document.getElementsByClassName('popup')[0].removeChild(document.getElementsByClassName('popup-head')[0]);
- }
- }
- }])
- starter.factory('Tool', function ($http, $q, $translate, $ionicHistory) {
- var tempData = {};
- var translates = {
- "weekdays": ['sundayTitle', 'mondayTitle', 'tuesdayTitle', 'wednesdayTitle', 'thursdayTitle', 'fridayTitle', 'saturdayTitle']
- };
- return {
- trim: function (str) {
- if (str == null) {
- str = "";
- }
- return str.replace(/(^\s*)|(\s*$)/g, "");
- },
- cloneObj: function (obj) {
- if (obj == null) {
- return null
- }
- var str, newobj = obj.constructor === Array ? [] : {};
- if (typeof obj !== 'object') {
- return;
- } else if (window.JSON) {
- str = JSON.stringify(obj), //系列化对象
- newobj = JSON.parse(str); //还原
- } else {
- for (var i in obj) {
- newobj[i] = typeof obj[i] === 'object' ?
- cloneObj(obj[i]) : obj[i];
- }
- }
- return newobj;
- },
- getTempData: function (key) {
- return tempData[key]
- },
- setTempData: function (key) {
- tempData[key] = []
- },
- get: function (url, iscache, key) {
- var deferred = $q.defer();
- iscache = iscache || false;
- $http.get(url).then(function (res) {
- deferred.resolve(res.data);
- if (iscache)
- tempData[key] = res.data;
- },
- function (err) {
- deferred.reject(err);
- });
- return deferred.promise;
- },
- post: function (url, data, isjson) {
- var deferred = $q.defer();
- var header = null;
- if (isjson == false) {
- header = {
- 'Content-Type': 'application/x-www-form-urlencoded'
- };
- }
- $http.post(url, data, {
- headers: header
- }).then(function (res) {
- deferred.resolve(res.data);
- },
- function (err) {
- deferred.reject(err);
- })
- return deferred.promise;
- },
- patch: function (url, data) {
- var deferred = $q.defer();
- $http.patch(url, data).then(function (res) {
- deferred.resolve(res.data);
- }, function (err) {
- deferred.resolve(err);
- });
- return deferred.promise;
- },
- put: function (url, data, iscache) {
- var deferred = $q.defer();
- iscache = iscache || false;
- $http.put(url, data).then(function (res) {
- deferred.resolve(res.data);
- if (iscache)
- tempData = res.data;
- },
- function (err) {
- deferred.reject(err);
- });
- return deferred.promise;
- },
- delete: function (url) {
- var deferred = $q.defer();
- $http.delete(url).then(function (res) {
- deferred.resolve(res.data);
- },
- function (err) {
- deferred.reject(err);
- });
- return deferred.promise;
- },
- getTranslateByKey: function (type, key) {
- if (translates[type] === undefined || translates[type][key] === undefined)
- return null;
- return $translate.instant(translates[type][key]);
- },
- removeBackView: function (routes) {
- var view = $ionicHistory.backView();
- if (!view)
- return;
- if (!(_.isArray(routes)))
- routes = [routes];
- _.find(routes, function (route) {
- if (view.stateName == route) {
- return $ionicHistory.removeBackView();
- }
- });
- }
- }
- })
- .factory('showPopup', function ($timeout, $ionicLoading, $ionicPopup, $rootScope, $ionicModal) {
- var typeArr = [
- '<i class="icon icon-warn" style="font-size:3em;"></i><br/>',
- '<ion-spinner icon="android"></ion-spinner><br/>'
- ];
- function showLoadingToast(type, text, isShowBackDrop) {
- if (isShowBackDrop == undefined) {
- isShowBackDrop = true;
- }
- // Setup the loader
- $ionicLoading.show({
- template: typeArr[type] + text,
- animation: 'fade-in',
- showBackdrop: isShowBackDrop,
- maxWidth: 200,
- Showdelay: 0
- });
- }
- function hideLoadingToast() {
- $ionicLoading.hide();
- }
- function popupInfo(type, text, isShowBackDrop, delay) {
- if (delay == undefined) {
- delay = 1500;
- }
- //弹出缓冲提示
- showLoadingToast(type, text, isShowBackDrop);
- //这里使用定时器是为了缓存一下加载过程,防止加载过快
- $timeout(function () {
- //停止缓冲提示
- hideLoadingToast();
- }, delay);
- }
- return {
- //触发函数
- PopupWindow: function (type, text, isShowBackDrop, delay) {
- popupInfo(type, text, isShowBackDrop, delay);
- },
- hideLoading: function () {
- hideLoadingToast();
- $rootScope.commons.isShowPopup = false;
- },
- showLoading: function (type, text, isShowBackDrop, delay) {
- showLoadingToast(type, text, isShowBackDrop);
- $rootScope.commons.isShowPopup = true;
- delay = delay || 10000;
- $timeout(function () {
- if ($rootScope.commons.isShowPopup) {
- $ionicLoading.hide();
- console.log(self);
- popupInfo(0, '请求超时!', false);
- $rootScope.commons.isShowPopup = false;
- }
- }, delay);
- },
- confirm: function (title, okText, cancelText) {
- var confirmpopup = $ionicPopup.confirm({
- title: '<br/><div>' + title + '</div><br/>',
- okText: okText,
- cancelText: cancelText
- });
- return confirmpopup;
- },
- showSelectImgPopup: function (camera, imagePicker, scope) {
- var optionsPopup = $ionicPopup.show({
- templateUrl: '../../templates/template-selectimg.html',
- scope: scope
- });
- scope.Camera = camera;
- scope.ImagePicker = imagePicker;
- return optionsPopup;
- },
- modalTemplate: function (templateurl, animation, scope) {
- return $ionicModal.fromTemplateUrl(templateurl, {
- scope: scope,
- animation: animation,
- focusFirstInput: true
- })
- }
- }
- })
- .factory('ImageManage', function ($q, $cordovaCamera, $cordovaImagePicker, $cordovaFileTransfer, $cordovaFile, $http, cfg, formatFilter, Tool) {
- var Qiniu_UploadUrl = "http://up.qiniu.com";
- function S4() {
- return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
- }
- function guid() {
- return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
- }
- return {
- ImagePicker_getPictures: function (_imagecount) {
- if (_imagecount == undefined) {
- _imagecount = 1;
- }
- var deferred = $q.defer();
- var options = {
- maximumImagesCount: _imagecount,
- quality: 30
- };
- var promises = [];
- $cordovaImagePicker.getPictures(options).then(function (results) {
- _.each(results, function (res) {
- var deferred1 = $q.defer();
- $cordovaFile.readFileMetadata(cordova.file.cacheDirectory, res.substr(res.lastIndexOf('/') + 1)).then(function (metadata) {
- console.log(metadata);
- }, function (error) {
- console.log(error);
- });
- $cordovaFile.readAsDataURL(cordova.file.cacheDirectory, res.substr(res.lastIndexOf('/') + 1)).then(function (base64) {
- deferred1.resolve(base64);
- }, function (error) {
- deferred1.reject(error);
- console.log(error);
- });
- // deferred1.resolve(res);
- promises.push(deferred1.promise);
- });
- deferred.resolve(promises);
- }, function (err) {
- deferred.reject(err);
- });
- return deferred.promise;
- },
- Camera_getPicture: function (_allowEdit) {
- if (_allowEdit == undefined) {
- _allowEdit = false;
- }
- var deferred = $q.defer();
- var options = {
- quality: 30,
- destinationType: Camera.DestinationType.DATA_URL,
- sourceType: Camera.PictureSourceType.CAMERA,
- allowEdit: _allowEdit,
- encodingType: Camera.EncodingType.JPEG,
- popoverOptions: CameraPopoverOptions,
- saveToPhotoAlbum: true,
- correctOrientation: true
- };
- $cordovaCamera.getPicture(options).then(function (imageData) {
- deferred.resolve("data:image/jpeg;base64," + imageData);
- }, function (err) {
- deferred.reject(err);
- });
- return deferred.promise;
- },
- upload: function (fileurls, token, _filepath) {
- var promises = [];
- var files = fileurls;
- var options = new FileUploadOptions();
- if (!_.isArray(files)) {
- files = [];
- files.push(fileurls);
- }
- _.each(files, function (itemfile) {
- var params = {};
- options.params = params;
- params.token = token;
- params.mimeType = "image/jpg";
- params.key = _filepath + guid() + itemfile.substr(itemfile.lastIndexOf('.'));
- promises.push($cordovaFileTransfer.upload(Qiniu_UploadUrl, itemfile, options, true));
- });
- return $q.all(promises);
- },
- getToken: function (app, id, cls) {
- var url = formatFilter('{0}qiniuupload/?app={1}&cls={2}&pk={3}', cfg.api, app, cls, id);
- return $http.get(url);
- },
- get_upload_Token: function (_url, compid) {
- var url = formatFilter('{0}{1}/{2}/', cfg.api, _url, compid);
- return $http.get(url);
- },
- uploadImage: function (fileurls, app, id, cls) {
- var url = formatFilter('{0}qiniuupload/?app={1}&cls={2}&pk={3}', cfg.api, app, cls, id);
- var defreed1 = $q.defer();
- Tool.get(url).then(function (data) {
- var promises = [];
- var files = fileurls;
- var options = new FileUploadOptions();
- if (!_.isArray(files)) {
- files = [];
- files.push(fileurls);
- }
- _.each(files, function (itemfile) {
- var params = {};
- options.params = params;
- params.token = data.token;
- params.mimeType = "image/jpg";
- params.key = data.filepath + guid() + itemfile.substr(itemfile.lastIndexOf('.'));
- var deferred = $q.defer();
- $cordovaFileTransfer.upload(Qiniu_UploadUrl, itemfile, options, true).then(function (res) {
- deferred.resolve(res);
- }, function (err) {
- deferred.reject(err);
- });
- promises.push(deferred.promise);
- });
- defreed1.resolve(promises);
- }, function (err) {
- defreed1.reject(err);
- alert('get upload token error' + JSON.stringify(err));
- });
- return defreed1.promise;
- }
- }
- })
- .factory('Member', function () {
- var member = {};
- var defaultmember = {};
- member.resourcemember = []; //基础数据
- member.selectedemplst = []; //选中的员工数据
- member.selecteddepts = []; //选中的部门数据
- member.isallcheck = false; //是否选中全部成员(部门)
- member.unenabledata = [];//未启用的数据(禁用的数据)
- member.homerenderdata = []; //目前为展示部门数据
- member.routename = ''; //点击确定后需要跳转的路由名称,默认是goBack();
- member.routeparams = {}; //"确定" 路由参数
- member.cancelroutename = ''; //点击取消后需要跳转的路由名称,默认是goBack();
- member.cancelrouteparams = {}; //"取消" 路由参数
- member.titlename = "选择成员"; //页面显示的标题名称
- member.datatype = ''; //成员类型 0:不计考勤成员 1:可查看考勤统计成员
- member.disabled = true; //是否需要禁用基础数据
- member.hide = false; //是否需要隐藏基础数据
- member.dialogresult = 1; //0:是点击了取消按钮退出,1:点击了确定按钮
- member.showall = false; //默认不显示‘全部成员’栏位
- member.showgroup = false; //默认不显示‘选择小组’栏位
- member.all = 1; // 全部成员/部分成员 : 1/0
- member.customerop = null; //自定义操作
- member.member = {};//用来存放相对应部门的员工数据,一部门ID作为key
- return member;
- })
- .factory('Dept', function ($http, $q, cfg, formatFilter, Tool, global) {
- var deptlst = [];
- var resultdept = new Array();
- var resultemp = new Array();
- return {
- selecteddepts: [], //存放被选中的部门集合
- titleName: {
- name: ''
- },
- save: function (up_depts, del_deptids, add_depts, compid) {
- var datas = [];
- if (del_deptids.length > 0) {
- datas.push({
- "op": "del",
- "values": del_deptids
- });
- }
- if (add_depts.length > 0) {
- datas.push({
- "op": "add",
- "values": add_depts
- });
- }
- if (up_depts.length > 0) {
- datas.push({
- "op": "up",
- "values": up_depts
- });
- }
- var url = formatFilter('{0}depts/?compid={1}', cfg.api, compid);
- return Tool.patch(url, datas)
- },
- all: function () {
- deptlst = Tool.getTempData('deptlist') || [];
- return deptlst;
- },
- setdeptlst: function (data) {
- deptlst = data;
- Tool.setTempData('deptlist')
- },
- getDep: function (compid) {
- var url = formatFilter('{0}depts/', cfg.api);
- if (compid) {
- url = formatFilter('{0}depts/?compid={1}', cfg.api, compid);
- }
- return Tool.get(url, true, 'deptlist')
- },
- getEmp: function (deptid, compid) {
- var url = formatFilter('{0}usrs/', cfg.api);
- if (deptid != undefined) {
- url = formatFilter('{0}usrs/?deptid={1}', cfg.api, deptid);
- }
- if (compid != undefined && deptid != undefined) {
- url = formatFilter('{0}usrs/?compid={1}&deptid={2}', cfg.api, compid, deptid);
- }
- return Tool.get(url)
- },
- getChildDept: function (pid) {
- return _.filter(this.all(), function (dept) {
- return parseInt(dept.parent) == parseInt(pid);
- });
- },
- getUsrDetail: function () {
- return Tool.get(formatFilter('{0}usrs/{1}/?compid={2}', cfg.api, global.user.usrid, global.user.compno), true, 'userinfo');
- },
- putUsrInfo: function (data) {
- data.dept = data.dept_id;
- data = _.pick(data, 'username', 'sex', 'dept', 'degree', 'email');
- return Tool.put(formatFilter('{0}usrs/{1}/', cfg.api, global.user.usrid), data)
- }
- };
- })
- .factory('General', function ($http, $q, cfg, global, formatFilter) {
- var Comment = {};
- var Read = {};
- return {
- getComment: function (id, module) {
- var url = formatFilter('{0}{1}/comments/?{2}id={3}', cfg.api, module, module, id);
- var deferred = $q.defer();
- $http.get(url).then(function (res) {
- deferred.resolve(res.data);
- Comment = res.data;
- },
- function (err) {
- deferred.reject(err);
- });
- return deferred.promise;
- },
- getRead: function (id, module, type) {
- var url = formatFilter('{0}{1}/readeds/?{2}id={3}', cfg.api, module, module, id);
- if (type != undefined) {
- url += '&type=unreads'
- }
- var deferred = $q.defer();
- $http.get(url).then(function (res) {
- deferred.resolve(res.data);
- },
- function (err) {
- deferred.reject(err);
- });
- return deferred.promise;
- },
- postComment: function (data, module) {
- var url = formatFilter('{0}{1}/comment/', cfg.api, module);
- var deferred = $q.defer();
- $http.post(url, data, {
- headers: {
- 'Content-Type': 'application/json'
- }
- }).then(function (res) {
- console.log(res.data)
- deferred.resolve(res.data);
- res.data.user__username = global.user.usrname;
- res.data.user_id = global.user.usrid;
- res.data.create_dd = new Date();
- Comment.splice(0, 0, res.data);
- },
- function (err) {
- deferred.reject(err);
- });
- return deferred.promise;
- },
- postRead: function (data, module) {
- console.log(Read)
- var url = formatFilter('{0}{1}/readeds/', cfg.api, module);
- var deferred = $q.defer();
- $http.post(url, data, {
- headers: {
- 'Content-Type': 'application/json'
- }
- }).then(function (res) {
- deferred.resolve(res.data);
- },
- function (err) {
- deferred.reject(err);
- });
- return deferred.promise;
- },
- deleteComment: function (id, module) {
- var comment = _.find(Comment, function (item) {
- if (item.id === parseInt(id)) {
- return item;
- }
- })
- if (comment != undefined) {
- Comment.splice(Comment.indexOf(comment), 1);
- var url = formatFilter('{0}{1}/comment/{2}/', cfg.api, module, id);
- return $http.delete(url);
- }
- }
- }
- })
- starter.filter("format", function () {
- return function (input) {
- var args = arguments;
- return input.replace(/\{(\d+)\}/g, function (match, capture) {
- return args[1 * capture + 1];
- });
- };
- })
- .filter('getDateDiff', function () {
- return function (dateTimeStamp) {
- if (dateTimeStamp == null) {
- return null;
- }
- var minute = 1000 * 60;
- var hour = minute * 60;
- var day = hour * 24;
- var week = day * 7;
- var month = day * 30;
- var year = day * 365;
- var now = new Date().getTime();
- var datetime = new Date(dateTimeStamp).getTime()
- var diffValue = now - datetime;
- if (diffValue + 10000 < 0) {
- //非法操作
- return false;
- }
- var yearC = diffValue / year;
- var monthC = diffValue / month;
- var weekC = diffValue / week;
- var dayC = diffValue / day;
- var hourC = diffValue / hour;
- var minC = diffValue / minute;
- if (yearC >= 1) {
- result = parseInt(yearC) + "年前";
- } else if (monthC >= 1) {
- result = parseInt(monthC) + "个月前";
- } else if (weekC >= 1) {
- result = parseInt(weekC) + "周前";
- } else if (dayC >= 1) {
- result = parseInt(dayC) + "天前";
- } else if (hourC >= 1) {
- result = parseInt(hourC) + "小时前";
- } else if (minC >= 1) {
- result = parseInt(minC) + "分钟前";
- } else
- result = "刚刚";
- return result;
- }
- })
- .filter('SwitchHtmlContent', function () {
- return function (content) {
- if (content != null) {
- content = content.replace(/\n/g, '<br/>');
- if (typeof ioNull != 'undefined') {
- return ioNull.emoji.parse(content);
- }
- }
- return content;
- }
- })
- .filter('percentage', function ($window) {
- return function (input, decimals, suffix) {
- decimals = angular.isNumber(decimals) ? decimals : 2;
- suffix = suffix || '%';
- if ($window.isNaN(input)) {
- return '';
- }
- return Math.round(input * Math.pow(10, decimals + 2)) / Math.pow(10, decimals) + suffix
- };
- })
- .filter('strtimeformat', function ($filter) {
- var dateFilter = $filter('date');
- function formatter(value) {
- return dateFilter(value, 'HH:mm'); //format
- }
- return function (str) {
- if (str == null)
- return null;
- str = new Date('2016/10/1 ' + str);
- return formatter(str);
- };
- })
|