starter.js 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948
  1. var starter = angular.module('starter', ['ionic', 'ngResource', 'underscore', 'ngCordova', 'pascalprecht.translate']);
  2. starter.run(function ($ionicPlatform, $rootScope, $http, formatFilter, $q, $cordovaPreferences, $ionicLoading, $timeout, $ionicHistory, $cordovaKeyboard, $translate, global, cfg, showPopup) {
  3. // $ionicLoading.show({
  4. // template: '数据加载中...'
  5. // }).then(function () {
  6. // console.log("loading starter.run");
  7. // });
  8. $rootScope.commons = {
  9. refresh: false,
  10. upload_maxcount: 10,
  11. bigImage: undefined, //显示大图
  12. modal: undefined, //模态窗口
  13. goBackIsDisable: undefined, //禁用返回键
  14. isShowPopup: undefined, //加载动画
  15. fun: null
  16. };
  17. $ionicPlatform.ready(function () {
  18. if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
  19. cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  20. cordova.plugins.Keyboard.disableScroll(true);
  21. }
  22. if (window.StatusBar) {
  23. StatusBar.styleDefault();
  24. }
  25. // $ionicLoading.hide();
  26. if (window.cordovaLinker)
  27. window.cordovaLinker.loadFinished("", function () {
  28. }, function () {
  29. });
  30. if (typeof navigator.globalization !== "undefined") {
  31. navigator.globalization.getPreferredLanguage(function (language) {
  32. console.log("globalization -> " + JSON.stringify(language));
  33. // alert(JSON.stringify(language))
  34. var value = (language.value).split('-')[0];
  35. if ((language.value).split('-')[1] == 'TW') {
  36. value = language.value
  37. }
  38. switch (value) {
  39. case 'zh-TW':
  40. value = 'locate-zh_tw';
  41. break;
  42. case 'en':
  43. value = 'locate-en_us';
  44. break;
  45. case 'zh':
  46. default:
  47. value = 'locate-zh_cn';
  48. break;
  49. }
  50. $translate.use(value).then(function (data) {
  51. console.log("SUCCESS -> " + data);
  52. }, function (error) {
  53. console.log("ERROR -> " + error);
  54. });
  55. });
  56. }
  57. });
  58. global.fetch_user = function () {
  59. var deferred = $q.defer();
  60. if (global.user && global.user.token) {
  61. usergot(global.user, deferred)
  62. } else if (ionic.Platform.platform() == 'win32' || ionic.Platform.platform() == 'linux') {
  63. $http.post(formatFilter('{0}authcheck/', cfg.api), "imid=zPayHMi6s&password=123456", {
  64. headers: {
  65. 'Content-Type': 'application/x-www-form-urlencoded'
  66. }
  67. }).then(function (response) {
  68. usergot(response.data, deferred);
  69. }, function (error) {
  70. console.log('通过post方式获取用户信息authcheck失败' + error);
  71. deferred.reject(error);
  72. })
  73. } else {
  74. $ionicPlatform.ready(function () {
  75. $cordovaPreferences.fetch('user')
  76. .success(function (value) {
  77. usergot(ionic.Platform.isAndroid() ? JSON.parse(value) : value, deferred);
  78. })
  79. .error(function (error) {
  80. console.error("通过$cordovaPreferences方式获取用户信息失败: " + error);
  81. deferred.reject(error);
  82. });
  83. });
  84. }
  85. return deferred.promise;
  86. };
  87. usergot = function (data, deferred) {
  88. global.user = data;
  89. if (data.cfg) {
  90. global.api = data.cfg.api;
  91. }
  92. deferred.resolve(data);
  93. console.warn(JSON.stringify(global.user));
  94. };
  95. global.fetch_user();
  96. global.goBack = function () {
  97. if (window.cordovaLinker != undefined) {
  98. if ($ionicHistory.backView()) {
  99. $ionicHistory.goBack();
  100. } else {
  101. window.cordovaLinker.goBack(1, function (s) {
  102. console.log(s);
  103. }, function (err) {
  104. console.error(err);
  105. });
  106. }
  107. }
  108. }
  109. function keyboardHideHandler(e) {
  110. cordova.plugins.Keyboard.isVisible = true;
  111. $timeout(function () {
  112. cordova.plugins.Keyboard.isVisible = false;
  113. }, 100);
  114. }
  115. window.addEventListener('native.keyboardhide', keyboardHideHandler);
  116. $ionicPlatform.registerBackButtonAction(function (e) {
  117. $timeout(function () {
  118. if ($rootScope.commons.isShowPopup) {
  119. showPopup.hideLoading();
  120. } else if ($rootScope.commons.goBackIsDisable) {
  121. return false;
  122. } else if ($cordovaKeyboard.isVisible()) {
  123. $cordovaKeyboard.close();
  124. } else if ($rootScope.commons.bigImage) {
  125. if ($rootScope.commons.fun == null) $rootScope.commons.bigImage = false;
  126. else {
  127. $rootScope.commons.fun();
  128. $rootScope.commons.fun = null;
  129. }
  130. } else if ($rootScope.commons.modal != null) {
  131. if ($rootScope.commons.fun == null) {
  132. $rootScope.commons.modal.hide();
  133. $rootScope.commons.modal = null;
  134. } else {
  135. $rootScope.commons.fun();
  136. $rootScope.commons.fun = null;
  137. }
  138. } else {
  139. if ($ionicHistory.backView()) {
  140. if ($rootScope.commons.fun == null) {
  141. $ionicHistory.goBack();
  142. } else {
  143. $rootScope.commons.fun();
  144. $rootScope.commons.fun = null;
  145. }
  146. } else {
  147. global.goBack();
  148. }
  149. }
  150. return false;
  151. })
  152. }, 201);
  153. var _user;
  154. _user = window.localStorage.getItem("global.user");
  155. if (_user != undefined) {
  156. console.log("localStorage get: " + _user);
  157. global.user = JSON.parse(_user);
  158. }
  159. })
  160. .config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider, $httpProvider, $provide, $translateProvider, $resourceProvider, cfg) {
  161. $ionicConfigProvider.platform.ios.tabs.style('standard');
  162. $ionicConfigProvider.platform.ios.tabs.position('bottom');
  163. $ionicConfigProvider.platform.android.tabs.style('standard');
  164. $ionicConfigProvider.platform.android.tabs.position('bottom');
  165. $ionicConfigProvider.platform.ios.navBar.alignTitle('center');
  166. $ionicConfigProvider.platform.android.navBar.alignTitle('center');
  167. $ionicConfigProvider.platform.ios.backButton.previousTitleText('').icon('ion-ios-arrow-thin-left');
  168. $ionicConfigProvider.platform.android.backButton.previousTitleText('').icon('ion-android-arrow-back');
  169. $ionicConfigProvider.platform.ios.views.transition('ios');
  170. $ionicConfigProvider.platform.android.views.transition('android');
  171. var regex = new RegExp('\.(html|js|css|png|jpg)$', 'i');
  172. var isAsset = function (url) {
  173. return regex.test(url);
  174. };
  175. $stateProvider.state('selectmember', {
  176. url: '/selectmember',
  177. templateUrl: '/templates/common/selectmember.html',
  178. controller: 'SelectMemberCtrl'
  179. })
  180. .state('selectsinglemember', {
  181. url: '/selectsinglemember',
  182. templateUrl: '/templates/common/selectsinglemember.html',
  183. controller: 'SelectSingleMemberCtrl'
  184. })
  185. .state('selectdept', {
  186. url: '/selectdept/:id',
  187. templateUrl: '/templates/common/selectdept.html',
  188. controller: 'SelectDeptCtrl'
  189. })
  190. .state('fieldtype', {
  191. url: '/fieldtype/:id',
  192. templateUrl: '/templates/common/fieldtype.html',
  193. controller: 'FormFieldTypeCtrl'
  194. })
  195. .state('transfer', {
  196. url: '/transfer/:module/:id',
  197. templateUrl: '/templates/common/transfer.html',
  198. controller: 'TransferCtrl'
  199. })
  200. .state('selectsingledept', {
  201. url: '/selectsingledept',
  202. templateUrl: '/templates/common/selectsingledept.html',
  203. controller: 'SelectSingleDeptCtrl'
  204. })
  205. $urlRouterProvider.otherwise('/index');
  206. $translateProvider.useStaticFilesLoader({
  207. prefix: '/i18n/',
  208. suffix: '.json'
  209. });
  210. $httpProvider.interceptors.push(function ($q, cfg, global) {
  211. return {
  212. 'request': function (config) {
  213. if (!isAsset(config.url) && (global.refresh || global.debug)) { //if the call is not for an asset file
  214. config.url += (config.url.indexOf("?") === -1 ? "?" : "&") + "v=" + Date.now();
  215. if (global.refresh)
  216. global.refresh = false;
  217. }
  218. if (config.url.startsWith(cfg.api) || config.url.indexOf(global.api) == 0) {//分页时自带了请求路径
  219. if (config.url.startsWith(cfg.api)) config.url = global.api + config.url;
  220. console.log(angular.lowercase(config.method) + " url: " + config.url);
  221. if (global.user.token) {
  222. config.headers['authorization'] = 'Token ' + global.user.token;
  223. console.log(' authorization:' + config.headers['authorization']);
  224. }
  225. }
  226. config.timeout = 10000;
  227. return config;
  228. },
  229. 'responseError': function (rejection) {
  230. console.error(JSON.stringify(rejection));
  231. return $q.reject(rejection);
  232. }
  233. };
  234. });
  235. $resourceProvider.defaults.stripTrailingSlashes = false;
  236. $resourceProvider.defaults.actions.update = {
  237. method: 'PUT',
  238. params: {
  239. id: "@id"
  240. }
  241. };
  242. $resourceProvider.defaults.actions.patch = {
  243. method: 'PATCH',
  244. };
  245. })
  246. .constant('cfg', {
  247. api: '/api/'
  248. })
  249. .value('global', {
  250. user: {
  251. usrid: "",
  252. token: "",
  253. usrname: "",
  254. compno: "",
  255. compname: "",
  256. deptno: "",
  257. deptname: "",
  258. roleid: "",
  259. im_usrid: "",
  260. cellphone: "",
  261. password: ""
  262. },
  263. api: "",
  264. debug: true,
  265. refresh: false
  266. })
  267. _.mixin({
  268. diff: function (_new, _old) {
  269. var r = {C: [], D: [], U: []};
  270. list_new = _.pluck(_new, 'id');
  271. list_old = _.pluck(_old, 'id');
  272. r.D = _.difference(list_old, list_new).join(',');
  273. r.C = _.filter(_new, function (item) {
  274. return item.id == undefined;
  275. });
  276. r.U = _.map(_.filter(_new, function (item) {
  277. return item.isModified && item.id != undefined;
  278. }), _.clone);
  279. _.each(r.U, function (item) {
  280. delete item.isModified;
  281. });
  282. _.each(r.C, function (item) {
  283. delete item.isModified;
  284. });
  285. return r;
  286. }
  287. });
  288. //http://stackoverflow.com/questions/33106114/cordova-javascript-error-has-no-method-startswith-android
  289. if (typeof String.prototype.startsWith != 'function') {
  290. String.prototype.startsWith = function (str) {
  291. return this.indexOf(str) === 0;
  292. };
  293. }
  294. starter.controller('SelectParentCtrl', function ($scope, $state, Member) {
  295. $scope.deptlst = [];
  296. $scope.emplst = [];
  297. $scope.index = 0;
  298. $scope.isUp = false;
  299. $scope.deptid = 1;
  300. $scope.titlename = Member.titlename;
  301. $scope.selectedemplst = Member.selectedemplst;
  302. $scope.disabled = Member.disabled;
  303. $scope.showall = Member.showall;
  304. $scope.showgroup = Member.showgroup;
  305. $scope.loading = true;
  306. $scope.leftbtn = [{
  307. text: '取消',
  308. click: 'cancel'
  309. }, {
  310. text: '上一层',
  311. click: 'up'
  312. }];
  313. })
  314. .controller('SelectMemberCtrl', function ($scope, $state, $ionicHistory, $rootScope, $ionicModal, $timeout, $controller, Dept, Member) {
  315. var parentctrl = $controller('SelectParentCtrl', {$scope: $scope});
  316. var showgroupmodel = $ionicModal.fromTemplateUrl('/templates/common/modal-selectgroup.html', {
  317. scope: $scope,
  318. animation: 'slide-in-right'
  319. });
  320. var startdept = null;
  321. $rootScope.commons.goBackIsDisable = true;
  322. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  323. if (Member.homerenderdata.length != 0) {
  324. $scope.loading = false;
  325. _.each(Member.homerenderdata, function (item) {
  326. $scope.deptlst.push(item);
  327. });
  328. init_selected(Member.resourcemember);
  329. } else {
  330. Dept.getDep().then(function (data) {
  331. startdept = _.find(data, function (itemdept) {
  332. return itemdept.parent == null; //获取公司的顶层部门
  333. });
  334. getemp(startdept.id);
  335. data = _.filter(data, function (item) {
  336. return item.parent == startdept.id;
  337. });
  338. $scope.deptlst = data;
  339. init_selected(Member.resourcemember);
  340. }, function (err) {
  341. alert(JSON.stringify(err))
  342. });
  343. }
  344. });
  345. $scope.changeindex = function (index, dtid) {
  346. $scope.index = index;
  347. $scope.deptid = dtid;
  348. };
  349. $scope.change = function (emp) {
  350. if (emp.selected) {
  351. $scope.selectedemplst.push(emp);
  352. Member.selectedemplst = $scope.selectedemplst;
  353. } else {
  354. $scope.selectedemplst = _.filter($scope.selectedemplst, function (e) {
  355. return e.user_id != parseInt(emp.user_id);
  356. });
  357. Member.selectedemplst = $scope.selectedemplst;
  358. }
  359. setselectedcount();
  360. };
  361. $scope.up = function () {
  362. var dept = undefined;
  363. if (Member.homerenderdata.length > 0) {
  364. dept = _.find(Member.homerenderdata, function (item) {
  365. return item.id == parseInt($scope.deptid);
  366. })
  367. }
  368. if (dept != undefined) {
  369. $scope.deptlst = $scope.deptlst.concat(Member.homerenderdata);
  370. $scope.emplst = [];
  371. $scope.index = 0;
  372. } else {
  373. dept = _.find(Dept.all(), function (d) {
  374. return d.id == parseInt($scope.deptid);
  375. });
  376. getdept_emp(dept.parent);
  377. }
  378. };
  379. $scope.cancel = function () {
  380. Member.selectedemplst = [];
  381. Member.dialogresult = 0;
  382. if (Member.cancelroutename != "") {
  383. $state.go(Member.cancelroutename, Member.cancelrouteparams);
  384. } else {
  385. $ionicHistory.goBack();
  386. }
  387. };
  388. var dep = {};
  389. $scope.changedept = function (dept) {
  390. dep = dept;
  391. getdept_emp(dept.id);
  392. };
  393. $scope.ok = function () {
  394. Member.dialogresult = 1;
  395. Member.all = 0;
  396. if (Member.routename != '') {
  397. $state.go(Member.routename, Member.routeparams);
  398. } else {
  399. $ionicHistory.goBack(); //todo:带参数跳转
  400. }
  401. };
  402. $scope.selectAll = function () {
  403. Member.all = 1;
  404. $state.go(Member.routename, Member.routeparams);
  405. };
  406. $scope.back = function () {
  407. if ($rootScope.commons.modal != null) {
  408. $rootScope.commons.modal.hide();
  409. }
  410. };
  411. $scope.toselectgroup = function () {
  412. showgroupmodel.then(function (modal) {
  413. $rootScope.commons.modal = modal;
  414. $rootScope.commons.modal.show();
  415. });
  416. };
  417. $scope.$on("$destroy", function () {
  418. $rootScope.commons.goBackIsDisable = false;
  419. Member.member = {};
  420. });
  421. function init_selected(data) {
  422. setdeptrighticon($scope.deptlst);
  423. Member.selectedemplst = [];
  424. if (!Member.disabled) {
  425. $scope.selectedemplst = $scope.selectedemplst.concat(data);
  426. Member.selectedemplst = $scope.selectedemplst;
  427. }
  428. setselectedcount();
  429. }
  430. function getemp(id) {
  431. Dept.getEmp(id).then(function (data) {
  432. console.log(data);
  433. Member.member[id.toString()] = angular.copy(data);
  434. $scope.emplst = data;
  435. setitem();
  436. $scope.loading = false;
  437. });
  438. }
  439. function getdept_emp(did) {
  440. if (Member.member[did.toString()]) {
  441. set_member(did);
  442. } else {
  443. $scope.loading = true;
  444. Dept.getEmp(did).then(function (data) {
  445. Member.member[did.toString()] = angular.copy(data);
  446. set_member(did);
  447. $scope.loading = false;
  448. }, function (err) {
  449. $scope.loading = false;
  450. });
  451. }
  452. }
  453. var set_member = function (did) {
  454. $scope.deptlst = Dept.getChildDept(did);
  455. setdeptrighticon($scope.deptlst);
  456. $scope.emplst = Member.member[did.toString()];
  457. setitem();
  458. $scope.deptid = did;
  459. $scope.index = (startdept && did == startdept.id) ? 0 : 1;
  460. };
  461. function setselectedcount() {
  462. $scope.selectcount = $scope.selectedemplst.length > 0 ? "(" + $scope.selectedemplst.length + ")" : "";
  463. }
  464. function setitem() {
  465. _.each($scope.emplst, function (e) {
  466. e.selected = false;
  467. e.disabled = false;
  468. e.depname = dep.depname;
  469. set_isenable(e, Member.resourcemember, true);
  470. set_isenable(e, Member.unenabledata, false);
  471. var e1 = _.find($scope.selectedemplst, {'user_id': e.user_id});
  472. if (e1 != undefined) e.selected = true;
  473. });
  474. }
  475. function set_isenable(e, data, op) {
  476. var p = _.find(data, {'user_id': e.user_id});
  477. if (p != undefined) {
  478. e.disabled = e.selected = true;
  479. if (!Member.disabled && op) e.disabled = false;
  480. }
  481. }
  482. function setdeptrighticon(deptlst) {
  483. _.each(deptlst, function (d) {
  484. d.isShow = isShow(d);
  485. })
  486. }
  487. function isShow(dept) {
  488. var childdepts = Dept.getChildDept(dept.id);
  489. return !(childdepts.length == 0);
  490. }
  491. })
  492. .controller('SelectSingleMemberCtrl', function ($scope, $ionicHistory, $state, $controller, Dept, Member) {
  493. var parentctrl = $controller('SelectParentCtrl', {$scope: $scope});
  494. var startdept = {};
  495. $scope.init = function () {
  496. Dept.getDep().then(function (data) {
  497. startdept = _.find(data, function (itemdept) {
  498. return itemdept.parent == null; //获取公司的顶层部门
  499. });
  500. getemp(startdept.id);
  501. data = _.filter(data, function (item) {
  502. return item.parent == startdept.id;
  503. });
  504. $scope.deptlst = data;
  505. setdeptrighticon($scope.deptlst);
  506. });
  507. };
  508. $scope.changeindex = function (index, dtid) {
  509. $scope.index = index;
  510. $scope.deptid = dtid;
  511. };
  512. $scope.change = function (emp) {
  513. Member.dialogresult = 1;
  514. Member.selectedemplst.push(emp);
  515. if (Member.routename != '') {
  516. $state.go(Member.routename, Member.routeparams);
  517. } else {
  518. $ionicHistory.goBack(); //todo:带参数跳转
  519. }
  520. };
  521. $scope.up = function () {
  522. var dept = _.find(Dept.all(), function (d) {
  523. return d.id == parseInt($scope.deptid);
  524. });
  525. getdept_emp(dept.parent);
  526. };
  527. $scope.cancel = function () {
  528. Member.dialogresult = 0;
  529. Member.selectedemplst = [];
  530. $ionicHistory.goBack();
  531. };
  532. var dep = {};
  533. $scope.changedept = function (dept) {
  534. dep = dept;
  535. getdept_emp(dept.id);
  536. };
  537. $scope.deptdisplay = function () {
  538. return $scope.deptlst.length > 0;
  539. };
  540. function getemp(deptid) {
  541. Dept.getEmp(deptid).then(function (data) {
  542. Member.member[deptid.toString()] = angular.copy(data);
  543. $scope.emplst = data;
  544. setitem();
  545. $scope.loading = false;
  546. });
  547. }
  548. function getdept_emp(did) {
  549. if (Member.member[did.toString()]) {
  550. set_member(did);
  551. } else {
  552. $scope.loading = true;
  553. Dept.getEmp(did).then(function (data) {
  554. Member.member[did.toString()] = angular.copy(data);
  555. set_member(did);
  556. $scope.loading = false;
  557. });
  558. }
  559. }
  560. var set_member = function (did) {
  561. $scope.deptlst = Dept.getChildDept(did);
  562. setdeptrighticon($scope.deptlst);
  563. $scope.emplst = Member.member[did.toString()];
  564. setitem();
  565. $scope.deptid = did;
  566. $scope.index = (startdept && did == startdept.id) ? 0 : 1;
  567. };
  568. function setitem() {
  569. _.each($scope.emplst, function (e) {
  570. e.selected = false;
  571. e.disabled = false;
  572. e.depname = dep.depname;
  573. _.each(Member.resourcemember, function (p) {
  574. if (p.user_id == parseInt(e.user_id)) {
  575. e.disabled = true;
  576. e.selected = true;
  577. if (!Member.disabled) e.disabled = false;
  578. }
  579. });
  580. _.each($scope.selectedemplst, function (e1) {
  581. if (e1.user_id == e.user_id) e.selected = true;
  582. });
  583. });
  584. }
  585. function setdeptrighticon(deptlst) {
  586. _.each(deptlst, function (d) {
  587. d.isShow = isShow(d);
  588. })
  589. }
  590. function isShow(dept) {
  591. return Dept.getChildDept(dept.id).length != 0;
  592. }
  593. $scope.$on("$destroy", function () {
  594. Member.member = {};
  595. });
  596. })
  597. .controller('SelectDeptCtrl', function ($scope, $state, $ionicHistory, $timeout, $controller, Dept, Member) {
  598. var parentctrl = $controller('SelectParentCtrl', {$scope: $scope});
  599. $scope.id = $state.params['id'];
  600. $scope.selecteddepts = Member.selecteddepts;
  601. $scope.selectdeptcount = '';
  602. $scope.isallcheck = Member.isallcheck;
  603. $scope.flag = 0;
  604. $scope.isAll = false;
  605. var deptid = 1;
  606. var resourcedept = [];
  607. var startdept = null;
  608. $scope.isAllCheck = function () {
  609. Member.dialogresult = 1;
  610. $scope.isallcheck = !$scope.isallcheck;
  611. Member.isallcheck = $scope.isallcheck;
  612. if (Member.isallcheck) {
  613. Member.selecteddepts = [];
  614. if (Member.routename != '') {
  615. $state.go(Member.routename, Member.routeparams);
  616. } else {
  617. $ionicHistory.goBack(); //todo:带参数跳转
  618. }
  619. }
  620. };
  621. $scope.cancel = function () {
  622. Member.dialogresult = 0;
  623. Member.selecteddepts = [];
  624. $ionicHistory.goBack();
  625. };
  626. $scope.ok = function () {
  627. console.log($scope.selecteddepts.length);
  628. Member.dialogresult = 1;
  629. Member.all = 0;
  630. if (Member.routename != '') {
  631. $state.go(Member.routename, Member.routeparams);
  632. } else {
  633. $ionicHistory.goBack(); //todo:带参数跳转
  634. }
  635. };
  636. $scope.up = function () {
  637. if ($scope.index == 0 && Member.showall) {
  638. $scope.showall = true;
  639. }
  640. var dept = _.find(Dept.all(), function (d) {
  641. return d.id == parseInt(deptid);
  642. });
  643. getChildDept(dept.parent);
  644. };
  645. $scope.change = function (dept) {
  646. if (Member.isallcheck) {
  647. $scope.isallcheck = !$scope.isallcheck;
  648. Member.isallcheck = $scope.isallcheck;
  649. }
  650. if (dept.selected) {
  651. $scope.selecteddepts.push(dept);
  652. Member.selecteddepts = $scope.selecteddepts;
  653. } else {
  654. $scope.selecteddepts = _.filter($scope.selecteddepts, function (e) {
  655. return e.id != parseInt(dept.id);
  656. });
  657. Member.selecteddepts = $scope.selecteddepts;
  658. }
  659. setselectedcount();
  660. };
  661. $scope.tochilddept = function (dept) {
  662. if ($scope.index == startdept.id) {
  663. $scope.showall = false;
  664. }
  665. getChildDept(dept.id);
  666. };
  667. function setdept(data) {
  668. _.each(data, function (item) {
  669. item.selected = false;
  670. item.isdisabled = false;
  671. item.ishide = false;
  672. item.disableddesc = '';
  673. item.isShow = isShow(item);
  674. if (Member.datatype == 3) {
  675. if (item.diarymobid != null && $state.params["id"] != item.diarymobid) {
  676. item.disableddesc = '(已设置)';
  677. item.isdisabled = true;
  678. }
  679. } else if (Member.datatype == 4) {
  680. if (item.workatdsetid != null && $state.params["id"] != item.workatdsetid) {
  681. item.disableddesc = '(已设置)';
  682. item.isdisabled = true;
  683. }
  684. }
  685. if (_.find(Member.resourcemember, function (rsc) {
  686. return rsc.id == item.id ? true : false
  687. })) {
  688. item.selected = true;
  689. }
  690. });
  691. $scope.deptlst = data;
  692. }
  693. function getChildDept(did) {
  694. var childdepts = Dept.getChildDept(did);
  695. if (childdepts.length > 0) {
  696. deptid = did;
  697. if (did == startdept.id) {
  698. $scope.index = 0;
  699. } else {
  700. $scope.index = 1;
  701. }
  702. setdept(childdepts);
  703. }
  704. }
  705. function setselectedcount() {
  706. if (Member.selecteddepts.length > 0) {
  707. $scope.selectcount = "(" + Member.selecteddepts.length + ")";
  708. } else {
  709. $scope.selectcount = "";
  710. }
  711. }
  712. function isShow(dept) {
  713. var childdepts = Dept.getChildDept(dept.id);
  714. if (childdepts.length == 0) {
  715. return false;
  716. } else {
  717. return true;
  718. }
  719. }
  720. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  721. $scope.loading = true;
  722. Dept.getDep().then(function (data) {
  723. startdept = _.find(data, function (itemdept) {
  724. return itemdept.parent == null; //获取公司的顶层部门
  725. });
  726. Member.selecteddepts = Member.resourcemember;
  727. $scope.selecteddepts = Member.selecteddepts;
  728. if (Member.datatype == 3) {
  729. _.each(data, function (item) {
  730. if (item.diarymobid != null) {
  731. $scope.flag++;
  732. }
  733. if (item.id == 1 && item.diarymobid != null) {
  734. $scope.isAll = true;
  735. }
  736. })
  737. } else if (Member.datatype == 4) {
  738. _.each(data, function (item) {
  739. if (item.workatdsetid != null) {
  740. $scope.flag++;
  741. }
  742. if (item.id == 1 && item.workatdsetid != null) {
  743. $scope.isAll = true;
  744. }
  745. })
  746. }
  747. if ($scope.id == -1) {
  748. if ($scope.flag == 1 && $scope.isAll) {
  749. $scope.showall = true;
  750. } else if ($scope.flag >= 1 && !$scope.isAll) {
  751. $scope.showall = false;
  752. }
  753. if ($scope.flag >= 1 && $scope.flag + 1 == data.length && !$scope.isAll) {
  754. $scope.isAll = true;
  755. }
  756. } else {
  757. if ($scope.flag == 1 && $scope.isAll) {
  758. $scope.showall = true;
  759. } else if ($scope.flag >= 1 && !$scope.isAll && Member.resourcemember.length == 0) {
  760. $scope.showall = true;
  761. } else if ($scope.flag >= 1 && !$scope.isAll && $scope.flag == Member.resourcemember.length) {
  762. $scope.showall = true;
  763. } else if ($scope.flag >= 1 && !$scope.isAll && $scope.flag != Member.resourcemember.length) {
  764. $scope.showall = false;
  765. }
  766. }
  767. var rst = _.filter(data, function (a) {
  768. return (a.level === 1);
  769. });
  770. setdept(rst);
  771. if (!Member.disabled) {
  772. _.each(Member.resourcemember, function (m) {
  773. $scope.selecteddepts.push(m);
  774. });
  775. Member.selecteddepts = $scope.selecteddepts;
  776. }
  777. setselectedcount();
  778. }).finally(function () {
  779. $scope.loading = false;
  780. });
  781. });
  782. $scope.$on("$destroy", function () {
  783. beforeEnter = null;
  784. })
  785. })
  786. .controller('SelectSingleDeptCtrl', function ($scope, $state, $ionicHistory, $timeout, Dept, Member) {
  787. $scope.titlename = Member.titlename;
  788. var active_dept_id = 1;
  789. var startdept = null;
  790. $scope.leftbtn = [{
  791. text: '取消',
  792. click: 'cancel'
  793. }, {
  794. text: '上一层',
  795. click: 'up'
  796. }];
  797. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  798. $scope.loading = true;
  799. Dept.getDep().then(function (data) {
  800. startdept = _.find(data, {'parent': null});
  801. $scope.id = Member.resourcemember.length > 0 ? Member.resourcemember[0].id : null;
  802. getChildDept(startdept.id);
  803. }).finally(function () {
  804. $scope.loading = false;
  805. });
  806. });
  807. $scope.cancel = function () {
  808. Member.dialogresult = 0;
  809. Member.selecteddepts = [];
  810. $ionicHistory.goBack();
  811. };
  812. $scope.up = function () {
  813. getChildDept(_.find(Dept.all(), {'id': active_dept_id}).parent);
  814. };
  815. $scope.change = function (dept) {
  816. Member.selecteddepts = [];
  817. if (dept.selected) {
  818. Member.selecteddepts.push(dept);
  819. Member.routename == "" ? $ionicHistory.goBack() : $state.go(Member.routename, Member.routeparams);
  820. }
  821. };
  822. $scope.tochilddept = function (dept) {
  823. getChildDept(dept.id);
  824. };
  825. $scope.is_showright = function (dept) {
  826. return Dept.getChildDept(dept.id).length > 0;
  827. };
  828. function getChildDept(did) {
  829. var childdepts = Dept.getChildDept(did);
  830. if (childdepts.length > 0) {
  831. active_dept_id = did;
  832. $scope.index = did == startdept.id ? 0 : 1;
  833. var item = _.find(childdepts, {'id': $scope.id});
  834. if (item != undefined) item.selected = item != undefined;
  835. $scope.deptlst = childdepts;
  836. }
  837. }
  838. $scope.$on("$destroy", function () {
  839. beforeEnter = null;
  840. })
  841. })
  842. .controller('TransferCtrl', function ($scope, $state, $stateParams, $ionicPopup, $ionicHistory, global, Member) {
  843. $scope.selectmember = function () {
  844. $scope.isremove = false;
  845. Member.resourcemember = [];
  846. Member.resourcemember.push({
  847. id: global.user.usrid
  848. });
  849. Member.routename = '';
  850. Member.titlename = '选择联系人';
  851. $state.go('selectmember');
  852. };
  853. $scope.goback = function () {
  854. $ionicHistory.goBack();
  855. };
  856. function selectMember() {
  857. if (Member.selectedemplst.length > 0) {
  858. $scope.memberlist.push(global.user.imusrid);
  859. _.each(Member.selectedemplst, function (item) {
  860. $scope.memberlist.push(item.im_usrid);
  861. });
  862. Member.selectedemplst = [];
  863. if (window.cordovaLinker != undefined) {
  864. var discussion = {
  865. name: "讨论组",
  866. ids: []
  867. };
  868. discussion.ids = $scope.memberlist;
  869. window.cordovaLinker.discuss(discussion, function (s) {
  870. console.log(s);
  871. var confirmPopup = $ionicPopup.confirm({
  872. title: '<br/><div>转发至</div><br/>',
  873. subTitle: discussion.name,
  874. okText: '是',
  875. cancelText: '否'
  876. });
  877. confirmPopup.then(function (res) {
  878. if (res) {
  879. //:todo转发
  880. }
  881. });
  882. }, function (err) {
  883. console.error(err);
  884. });
  885. }
  886. Member.resourcemember = [];
  887. }
  888. }
  889. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  890. $scope.module = $stateParams.module;
  891. $scope.id = $stateParams.id;
  892. $scope.linkurl = '/tab/app/' + $scope.module + '/' + $scope.id;
  893. console.log($scope.linkurl);
  894. $scope.memberlist = [];
  895. $scope.popup = {
  896. isPopup: false
  897. };
  898. selectMember();
  899. });
  900. $scope.$on("$destroy", function () {
  901. beforeEnter = null;
  902. })
  903. })
  904. starter.directive('itemMember', function (Dept) {
  905. return {
  906. restrict: 'E',
  907. replace: true,
  908. template: '<div><ion-checkbox ng-model="emp.selected" ng-disabled="emp.disabled" ng-change="change(emp)" class="ion-checkbox-class">' +
  909. '<img ng-src="../../../img/panda.png" />' +
  910. '<label class="labelname">{{emp.username}}</label>' +
  911. '<label class="labelrole">{{emp.degree}}</label>' +
  912. '</ion-checkbox>' +
  913. '</div>'
  914. };
  915. })
  916. .directive('itemDept', function (Dept) {
  917. return {
  918. restrict: 'E',
  919. replace: true,
  920. template: '<div>' +
  921. '<ion-item class="item item-icon-right" type="item-text-wrap" ng-click="changedept(dept);">' +
  922. '{{dept.depname}}' +
  923. '<i class="icon ion-chevron-right icon-accessory" ng-show="dept.isShow"></i>' +
  924. '</ion-item>' +
  925. '</div>'
  926. };
  927. })
  928. .directive('footerMember', function (Dept) {
  929. return {
  930. restrict: 'E',
  931. replace: true,
  932. template: '<div class="bar bar-footer bar-dark footer-div" ng-class={true:"bigview",false:""}[isUp]>' +
  933. '<i class="cirl-i" ng-class={true:"ion-ios-arrow-down",false:"ion-ios-arrow-up"}[isUp] ng-click="isUp = !isUp"></i>' +
  934. '<ul class="ul-imgs dept-icon">' +
  935. '<li ng-repeat="user in selectedemplst">{{user.username}}</li>' +
  936. '</ul>' +
  937. '<button ng-disabled="selectedemplst.length==0" ng-click="ok();" class="button pull-right button-calm">确定{{selectcount}}</button>' +
  938. '</div>'
  939. };
  940. })
  941. .directive('rjCloseBackDrop', [function () {
  942. return {
  943. scope: false,
  944. restrict: 'A',
  945. replace: false,
  946. link: function (scope, iElm, iAttrs, controller) {
  947. var htmlEl = angular.element(document.querySelector('html'));
  948. htmlEl.unbind("click");
  949. htmlEl.on("click", function (event) {
  950. if (event.target.nodeName === "HTML" &&
  951. scope.popup.optionsPopup &&
  952. scope.popup.isPopup) {
  953. scope.popup.optionsPopup.close();
  954. scope.popup.isPopup = false;
  955. } else if (event.target.nodeName === "DIV" &&
  956. scope.popup.optionsPopup &&
  957. scope.popup.isSetPopup) {
  958. scope.popup.optionsPopup.close();
  959. scope.popup.isSetPopup = false;
  960. }
  961. });
  962. }
  963. };
  964. }])
  965. //放大缩小图片
  966. .directive('ngPinchZoom', [function () {
  967. var _directive = {
  968. restrict: 'A',
  969. scope: false,
  970. link: _link
  971. };
  972. function _link(scope, element, attrs) {
  973. var elWidth, elHeight;
  974. // mode : 'pinch' or 'swipe'
  975. var mode = '';
  976. // distance between two touche points (mode : 'pinch')
  977. var distance = 0;
  978. var initialDistance = 0;
  979. // image scaling
  980. var scale = 1;
  981. var relativeScale = 1;
  982. var initialScale = 1;
  983. var maxScale = parseInt(attrs.maxScale, 10);
  984. if (isNaN(maxScale) || maxScale <= 1) {
  985. maxScale = 3;
  986. }
  987. // position of the upper left corner of the element
  988. var positionX = 0;
  989. var positionY = 0;
  990. var initialPositionX = 0;
  991. var initialPositionY = 0;
  992. // central origin (mode : 'pinch')
  993. var originX = 0;
  994. var originY = 0;
  995. // start coordinate and amount of movement (mode : 'swipe')
  996. var startX = 0;
  997. var startY = 0;
  998. var moveX = 0;
  999. var moveY = 0;
  1000. var image = new Image();
  1001. image.onload = function () {
  1002. elWidth = element[0].clientWidth;
  1003. elHeight = element[0].clientHeight;
  1004. element.css({
  1005. '-webkit-transform-origin': '0 0',
  1006. 'transform-origin': '0 0'
  1007. });
  1008. element.on('touchstart', touchstartHandler);
  1009. element.on('touchmove', touchmoveHandler);
  1010. element.on('touchend', touchendHandler);
  1011. };
  1012. if (attrs.ngSrc) {
  1013. image.src = attrs.ngSrc;
  1014. } else {
  1015. if (attrs.src) {
  1016. image.src = attrs.src;
  1017. }
  1018. }
  1019. /**
  1020. * @param {object} evt
  1021. */
  1022. function touchstartHandler(evt) {
  1023. var touches = evt.originalEvent ? evt.originalEvent.touches : evt.touches;
  1024. startX = touches[0].clientX;
  1025. startY = touches[0].clientY;
  1026. initialPositionX = positionX;
  1027. initialPositionY = positionY;
  1028. moveX = 0;
  1029. moveY = 0;
  1030. }
  1031. /**
  1032. * @param {object} evt
  1033. */
  1034. function touchmoveHandler(evt) {
  1035. var touches = evt.originalEvent ? evt.originalEvent.touches : evt.touches;
  1036. if (mode === '') {
  1037. if (touches.length === 1 && scale > 1) {
  1038. mode = 'swipe';
  1039. } else if (touches.length === 2) {
  1040. mode = 'pinch';
  1041. initialScale = scale;
  1042. initialDistance = getDistance(touches);
  1043. originX = touches[0].clientX -
  1044. parseInt((touches[0].clientX - touches[1].clientX) / 2, 10) -
  1045. element[0].offsetLeft - initialPositionX;
  1046. originY = touches[0].clientY -
  1047. parseInt((touches[0].clientY - touches[1].clientY) / 2, 10) -
  1048. element[0].offsetTop - initialPositionY;
  1049. }
  1050. }
  1051. if (mode === 'swipe') {
  1052. evt.preventDefault();
  1053. moveX = touches[0].clientX - startX;
  1054. moveY = touches[0].clientY - startY;
  1055. positionX = initialPositionX + moveX;
  1056. positionY = initialPositionY + moveY;
  1057. transformElement();
  1058. } else if (mode === 'pinch' && touches.length === 2) {
  1059. evt.preventDefault();
  1060. distance = getDistance(touches);
  1061. relativeScale = distance / initialDistance;
  1062. scale = relativeScale * initialScale;
  1063. positionX = originX * (1 - relativeScale) + initialPositionX + moveX;
  1064. positionY = originY * (1 - relativeScale) + initialPositionY + moveY;
  1065. transformElement();
  1066. }
  1067. }
  1068. /**
  1069. * @param {object} evt
  1070. */
  1071. function touchendHandler(evt) {
  1072. var touches = evt.originalEvent ? evt.originalEvent.touches : evt.touches;
  1073. if (mode === '' || touches.length > 0) {
  1074. return;
  1075. }
  1076. if (scale < 1) {
  1077. scale = 1;
  1078. positionX = 0;
  1079. positionY = 0;
  1080. } else if (scale > maxScale) {
  1081. scale = maxScale;
  1082. relativeScale = scale / initialScale;
  1083. positionX = originX * (1 - relativeScale) + initialPositionX + moveX;
  1084. positionY = originY * (1 - relativeScale) + initialPositionY + moveY;
  1085. } else {
  1086. if (positionX > 0) {
  1087. positionX = 0;
  1088. } else if (positionX < elWidth * (1 - scale)) {
  1089. positionX = elWidth * (1 - scale);
  1090. }
  1091. if (positionY > 0) {
  1092. positionY = 0;
  1093. } else if (positionY < elHeight * (1 - scale)) {
  1094. positionY = elHeight * (1 - scale);
  1095. }
  1096. }
  1097. transformElement(0.1);
  1098. mode = '';
  1099. }
  1100. /**
  1101. * @param {Array} touches
  1102. * @return {number}
  1103. */
  1104. function getDistance(touches) {
  1105. var d = Math.sqrt(Math.pow(touches[0].clientX - touches[1].clientX, 2) +
  1106. Math.pow(touches[0].clientY - touches[1].clientY, 2));
  1107. return parseInt(d, 10);
  1108. }
  1109. /**
  1110. * @param {number} [duration]
  1111. */
  1112. function transformElement(duration) {
  1113. var transition = duration ? 'all cubic-bezier(0,0,.5,1) ' + duration + 's' : '';
  1114. var matrixArray = [scale, 0, 0, scale, positionX, positionY];
  1115. var matrix = 'matrix(' + matrixArray.join(',') + ')';
  1116. element.css({
  1117. '-webkit-transition': transition,
  1118. transition: transition,
  1119. '-webkit-transform': matrix + ' translate3d(0,0,0)',
  1120. transform: matrix
  1121. });
  1122. }
  1123. }
  1124. return _directive;
  1125. }])
  1126. .directive('focusMe', function ($timeout) {
  1127. return {
  1128. scope: {
  1129. trigger: '=focusMe'
  1130. },
  1131. link: function (scope, element) {
  1132. scope.$watch('trigger', function (value) {
  1133. if (value === true) {
  1134. $timeout(function () {
  1135. element[0].focus();
  1136. });
  1137. }
  1138. });
  1139. }
  1140. };
  1141. })
  1142. .directive('imagePopover', [function () {
  1143. return {
  1144. restrict: "E",
  1145. scope: {
  1146. allImages: '='
  1147. },
  1148. template: "<img ng-repeat='img in allImages' ng-click='showImages($index,$event)' ng-src='{{img.file_thumbnail_path}}' class='img-popver-pad'/>",
  1149. controller: function ($scope, $rootScope, $ionicModal) {
  1150. $scope.showImages = function (index, event) {
  1151. if (event != undefined) {
  1152. event.stopPropagation();
  1153. }
  1154. $scope.activeSlide = index;
  1155. $scope.showModal('../../templates/modal-imagepopover.html');
  1156. };
  1157. $scope.bigImage = $rootScope.commons.bigImage;
  1158. $scope.showModal = function (templateUrl) {
  1159. $rootScope.commons.fun = clear_change;
  1160. $rootScope.commons.bigImage = true;
  1161. $ionicModal.fromTemplateUrl(templateUrl, {
  1162. scope: $scope,
  1163. animation: 'slide-in-up'
  1164. }).then(function (modal) {
  1165. $rootScope.commons.modal = modal;
  1166. $rootScope.commons.modal.show();
  1167. });
  1168. };
  1169. $scope.closeModal = function () {
  1170. clear_change();
  1171. $rootScope.commons.fun = null;
  1172. };
  1173. function clear_change() {
  1174. $rootScope.commons.bigImage = false;
  1175. $rootScope.commons.modal.hide();
  1176. $rootScope.commons.modal.remove();
  1177. $rootScope.commons.modal = null;
  1178. }
  1179. }
  1180. }
  1181. }])
  1182. .directive('removePopoverHeader', [function () {
  1183. return {
  1184. restrict: "A",
  1185. link: function (scope, iElm, iAttrs, controller) {
  1186. document.getElementsByClassName('popup')[0].removeChild(document.getElementsByClassName('popup-head')[0]);
  1187. }
  1188. }
  1189. }])
  1190. starter.factory('Tool', function ($http, $q, $translate, $ionicHistory) {
  1191. var tempData = {};
  1192. var translates = {
  1193. "weekdays": ['sundayTitle', 'mondayTitle', 'tuesdayTitle', 'wednesdayTitle', 'thursdayTitle', 'fridayTitle', 'saturdayTitle']
  1194. };
  1195. return {
  1196. trim: function (str) {
  1197. if (str == null) {
  1198. str = "";
  1199. }
  1200. return str.replace(/(^\s*)|(\s*$)/g, "");
  1201. },
  1202. cloneObj: function (obj) {
  1203. if (obj == null) {
  1204. return null
  1205. }
  1206. var str, newobj = obj.constructor === Array ? [] : {};
  1207. if (typeof obj !== 'object') {
  1208. return;
  1209. } else if (window.JSON) {
  1210. str = JSON.stringify(obj), //系列化对象
  1211. newobj = JSON.parse(str); //还原
  1212. } else {
  1213. for (var i in obj) {
  1214. newobj[i] = typeof obj[i] === 'object' ?
  1215. cloneObj(obj[i]) : obj[i];
  1216. }
  1217. }
  1218. return newobj;
  1219. },
  1220. getTempData: function (key) {
  1221. return tempData[key]
  1222. },
  1223. setTempData: function (key) {
  1224. tempData[key] = []
  1225. },
  1226. get: function (url, iscache, key) {
  1227. var deferred = $q.defer();
  1228. iscache = iscache || false;
  1229. $http.get(url).then(function (res) {
  1230. deferred.resolve(res.data);
  1231. if (iscache)
  1232. tempData[key] = res.data;
  1233. },
  1234. function (err) {
  1235. deferred.reject(err);
  1236. });
  1237. return deferred.promise;
  1238. },
  1239. post: function (url, data, isjson) {
  1240. var deferred = $q.defer();
  1241. var header = null;
  1242. if (isjson == false) {
  1243. header = {
  1244. 'Content-Type': 'application/x-www-form-urlencoded'
  1245. };
  1246. }
  1247. $http.post(url, data, {
  1248. headers: header
  1249. }).then(function (res) {
  1250. deferred.resolve(res.data);
  1251. },
  1252. function (err) {
  1253. deferred.reject(err);
  1254. })
  1255. return deferred.promise;
  1256. },
  1257. patch: function (url, data) {
  1258. var deferred = $q.defer();
  1259. $http.patch(url, data).then(function (res) {
  1260. deferred.resolve(res.data);
  1261. }, function (err) {
  1262. deferred.resolve(err);
  1263. });
  1264. return deferred.promise;
  1265. },
  1266. put: function (url, data, iscache) {
  1267. var deferred = $q.defer();
  1268. iscache = iscache || false;
  1269. $http.put(url, data).then(function (res) {
  1270. deferred.resolve(res.data);
  1271. if (iscache)
  1272. tempData = res.data;
  1273. },
  1274. function (err) {
  1275. deferred.reject(err);
  1276. });
  1277. return deferred.promise;
  1278. },
  1279. delete: function (url) {
  1280. var deferred = $q.defer();
  1281. $http.delete(url).then(function (res) {
  1282. deferred.resolve(res.data);
  1283. },
  1284. function (err) {
  1285. deferred.reject(err);
  1286. });
  1287. return deferred.promise;
  1288. },
  1289. getTranslateByKey: function (type, key) {
  1290. if (translates[type] === undefined || translates[type][key] === undefined)
  1291. return null;
  1292. return $translate.instant(translates[type][key]);
  1293. },
  1294. removeBackView: function (routes) {
  1295. var view = $ionicHistory.backView();
  1296. if (!view)
  1297. return;
  1298. if (!(_.isArray(routes)))
  1299. routes = [routes];
  1300. _.find(routes, function (route) {
  1301. if (view.stateName == route) {
  1302. return $ionicHistory.removeBackView();
  1303. }
  1304. });
  1305. }
  1306. }
  1307. })
  1308. .factory('showPopup', function ($timeout, $ionicLoading, $ionicPopup, $rootScope, $ionicModal) {
  1309. var typeArr = [
  1310. '<i class="icon icon-warn" style="font-size:3em;"></i><br/>',
  1311. '<ion-spinner icon="android"></ion-spinner><br/>'
  1312. ];
  1313. function showLoadingToast(type, text, isShowBackDrop) {
  1314. if (isShowBackDrop == undefined) {
  1315. isShowBackDrop = true;
  1316. }
  1317. // Setup the loader
  1318. $ionicLoading.show({
  1319. template: typeArr[type] + text,
  1320. animation: 'fade-in',
  1321. showBackdrop: isShowBackDrop,
  1322. maxWidth: 200,
  1323. Showdelay: 0
  1324. });
  1325. }
  1326. function hideLoadingToast() {
  1327. $ionicLoading.hide();
  1328. }
  1329. function popupInfo(type, text, isShowBackDrop, delay) {
  1330. if (delay == undefined) {
  1331. delay = 1500;
  1332. }
  1333. //弹出缓冲提示
  1334. showLoadingToast(type, text, isShowBackDrop);
  1335. //这里使用定时器是为了缓存一下加载过程,防止加载过快
  1336. $timeout(function () {
  1337. //停止缓冲提示
  1338. hideLoadingToast();
  1339. }, delay);
  1340. }
  1341. return {
  1342. //触发函数
  1343. PopupWindow: function (type, text, isShowBackDrop, delay) {
  1344. popupInfo(type, text, isShowBackDrop, delay);
  1345. },
  1346. hideLoading: function () {
  1347. hideLoadingToast();
  1348. $rootScope.commons.isShowPopup = false;
  1349. },
  1350. showLoading: function (type, text, isShowBackDrop, delay) {
  1351. showLoadingToast(type, text, isShowBackDrop);
  1352. $rootScope.commons.isShowPopup = true;
  1353. delay = delay || 10000;
  1354. $timeout(function () {
  1355. if ($rootScope.commons.isShowPopup) {
  1356. $ionicLoading.hide();
  1357. console.log(self);
  1358. popupInfo(0, '请求超时!', false);
  1359. $rootScope.commons.isShowPopup = false;
  1360. }
  1361. }, delay);
  1362. },
  1363. confirm: function (title, okText, cancelText) {
  1364. var confirmpopup = $ionicPopup.confirm({
  1365. title: '<br/><div>' + title + '</div><br/>',
  1366. okText: okText,
  1367. cancelText: cancelText
  1368. });
  1369. return confirmpopup;
  1370. },
  1371. showSelectImgPopup: function (camera, imagePicker, scope) {
  1372. var optionsPopup = $ionicPopup.show({
  1373. templateUrl: '../../templates/template-selectimg.html',
  1374. scope: scope
  1375. });
  1376. scope.Camera = camera;
  1377. scope.ImagePicker = imagePicker;
  1378. return optionsPopup;
  1379. },
  1380. modalTemplate: function (templateurl, animation, scope) {
  1381. return $ionicModal.fromTemplateUrl(templateurl, {
  1382. scope: scope,
  1383. animation: animation,
  1384. focusFirstInput: true
  1385. })
  1386. }
  1387. }
  1388. })
  1389. .factory('ImageManage', function ($q, $cordovaCamera, $cordovaImagePicker, $cordovaFileTransfer, $cordovaFile, $http, cfg, formatFilter, Tool) {
  1390. var Qiniu_UploadUrl = "http://up.qiniu.com";
  1391. function S4() {
  1392. return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  1393. }
  1394. function guid() {
  1395. return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
  1396. }
  1397. return {
  1398. ImagePicker_getPictures: function (_imagecount) {
  1399. if (_imagecount == undefined) {
  1400. _imagecount = 1;
  1401. }
  1402. var deferred = $q.defer();
  1403. var options = {
  1404. maximumImagesCount: _imagecount,
  1405. quality: 30
  1406. };
  1407. var promises = [];
  1408. $cordovaImagePicker.getPictures(options).then(function (results) {
  1409. _.each(results, function (res) {
  1410. var deferred1 = $q.defer();
  1411. $cordovaFile.readFileMetadata(cordova.file.cacheDirectory, res.substr(res.lastIndexOf('/') + 1)).then(function (metadata) {
  1412. console.log(metadata);
  1413. }, function (error) {
  1414. console.log(error);
  1415. });
  1416. $cordovaFile.readAsDataURL(cordova.file.cacheDirectory, res.substr(res.lastIndexOf('/') + 1)).then(function (base64) {
  1417. deferred1.resolve(base64);
  1418. }, function (error) {
  1419. deferred1.reject(error);
  1420. console.log(error);
  1421. });
  1422. // deferred1.resolve(res);
  1423. promises.push(deferred1.promise);
  1424. });
  1425. deferred.resolve(promises);
  1426. }, function (err) {
  1427. deferred.reject(err);
  1428. });
  1429. return deferred.promise;
  1430. },
  1431. Camera_getPicture: function (_allowEdit) {
  1432. if (_allowEdit == undefined) {
  1433. _allowEdit = false;
  1434. }
  1435. var deferred = $q.defer();
  1436. var options = {
  1437. quality: 30,
  1438. destinationType: Camera.DestinationType.DATA_URL,
  1439. sourceType: Camera.PictureSourceType.CAMERA,
  1440. allowEdit: _allowEdit,
  1441. encodingType: Camera.EncodingType.JPEG,
  1442. popoverOptions: CameraPopoverOptions,
  1443. saveToPhotoAlbum: true,
  1444. correctOrientation: true
  1445. };
  1446. $cordovaCamera.getPicture(options).then(function (imageData) {
  1447. deferred.resolve("data:image/jpeg;base64," + imageData);
  1448. }, function (err) {
  1449. deferred.reject(err);
  1450. });
  1451. return deferred.promise;
  1452. },
  1453. upload: function (fileurls, token, _filepath) {
  1454. var promises = [];
  1455. var files = fileurls;
  1456. var options = new FileUploadOptions();
  1457. if (!_.isArray(files)) {
  1458. files = [];
  1459. files.push(fileurls);
  1460. }
  1461. _.each(files, function (itemfile) {
  1462. var params = {};
  1463. options.params = params;
  1464. params.token = token;
  1465. params.mimeType = "image/jpg";
  1466. params.key = _filepath + guid() + itemfile.substr(itemfile.lastIndexOf('.'));
  1467. promises.push($cordovaFileTransfer.upload(Qiniu_UploadUrl, itemfile, options, true));
  1468. });
  1469. return $q.all(promises);
  1470. },
  1471. getToken: function (app, id, cls) {
  1472. var url = formatFilter('{0}qiniuupload/?app={1}&cls={2}&pk={3}', cfg.api, app, cls, id);
  1473. return $http.get(url);
  1474. },
  1475. get_upload_Token: function (_url, compid) {
  1476. var url = formatFilter('{0}{1}/{2}/', cfg.api, _url, compid);
  1477. return $http.get(url);
  1478. },
  1479. uploadImage: function (fileurls, app, id, cls) {
  1480. var url = formatFilter('{0}qiniuupload/?app={1}&cls={2}&pk={3}', cfg.api, app, cls, id);
  1481. var defreed1 = $q.defer();
  1482. Tool.get(url).then(function (data) {
  1483. var promises = [];
  1484. var files = fileurls;
  1485. var options = new FileUploadOptions();
  1486. if (!_.isArray(files)) {
  1487. files = [];
  1488. files.push(fileurls);
  1489. }
  1490. _.each(files, function (itemfile) {
  1491. var params = {};
  1492. options.params = params;
  1493. params.token = data.token;
  1494. params.mimeType = "image/jpg";
  1495. params.key = data.filepath + guid() + itemfile.substr(itemfile.lastIndexOf('.'));
  1496. var deferred = $q.defer();
  1497. $cordovaFileTransfer.upload(Qiniu_UploadUrl, itemfile, options, true).then(function (res) {
  1498. deferred.resolve(res);
  1499. }, function (err) {
  1500. deferred.reject(err);
  1501. });
  1502. promises.push(deferred.promise);
  1503. });
  1504. defreed1.resolve(promises);
  1505. }, function (err) {
  1506. defreed1.reject(err);
  1507. alert('get upload token error' + JSON.stringify(err));
  1508. });
  1509. return defreed1.promise;
  1510. }
  1511. }
  1512. })
  1513. .factory('Member', function () {
  1514. var member = {};
  1515. var defaultmember = {};
  1516. member.resourcemember = []; //基础数据
  1517. member.selectedemplst = []; //选中的员工数据
  1518. member.selecteddepts = []; //选中的部门数据
  1519. member.isallcheck = false; //是否选中全部成员(部门)
  1520. member.unenabledata = [];//未启用的数据(禁用的数据)
  1521. member.homerenderdata = []; //目前为展示部门数据
  1522. member.routename = ''; //点击确定后需要跳转的路由名称,默认是goBack();
  1523. member.routeparams = {}; //"确定" 路由参数
  1524. member.cancelroutename = ''; //点击取消后需要跳转的路由名称,默认是goBack();
  1525. member.cancelrouteparams = {}; //"取消" 路由参数
  1526. member.titlename = "选择成员"; //页面显示的标题名称
  1527. member.datatype = ''; //成员类型 0:不计考勤成员 1:可查看考勤统计成员
  1528. member.disabled = true; //是否需要禁用基础数据
  1529. member.hide = false; //是否需要隐藏基础数据
  1530. member.dialogresult = 1; //0:是点击了取消按钮退出,1:点击了确定按钮
  1531. member.showall = false; //默认不显示‘全部成员’栏位
  1532. member.showgroup = false; //默认不显示‘选择小组’栏位
  1533. member.all = 1; // 全部成员/部分成员 : 1/0
  1534. member.customerop = null; //自定义操作
  1535. member.member = {};//用来存放相对应部门的员工数据,一部门ID作为key
  1536. return member;
  1537. })
  1538. .factory('Dept', function ($http, $q, cfg, formatFilter, Tool, global) {
  1539. var deptlst = [];
  1540. var resultdept = new Array();
  1541. var resultemp = new Array();
  1542. return {
  1543. selecteddepts: [], //存放被选中的部门集合
  1544. titleName: {
  1545. name: ''
  1546. },
  1547. save: function (up_depts, del_deptids, add_depts, compid) {
  1548. var datas = [];
  1549. if (del_deptids.length > 0) {
  1550. datas.push({
  1551. "op": "del",
  1552. "values": del_deptids
  1553. });
  1554. }
  1555. if (add_depts.length > 0) {
  1556. datas.push({
  1557. "op": "add",
  1558. "values": add_depts
  1559. });
  1560. }
  1561. if (up_depts.length > 0) {
  1562. datas.push({
  1563. "op": "up",
  1564. "values": up_depts
  1565. });
  1566. }
  1567. var url = formatFilter('{0}depts/?compid={1}', cfg.api, compid);
  1568. return Tool.patch(url, datas)
  1569. },
  1570. all: function () {
  1571. deptlst = Tool.getTempData('deptlist') || [];
  1572. return deptlst;
  1573. },
  1574. setdeptlst: function (data) {
  1575. deptlst = data;
  1576. Tool.setTempData('deptlist')
  1577. },
  1578. getDep: function (compid) {
  1579. var url = formatFilter('{0}depts/', cfg.api);
  1580. if (compid) {
  1581. url = formatFilter('{0}depts/?compid={1}', cfg.api, compid);
  1582. }
  1583. return Tool.get(url, true, 'deptlist')
  1584. },
  1585. getEmp: function (deptid, compid) {
  1586. var url = formatFilter('{0}usrs/', cfg.api);
  1587. if (deptid != undefined) {
  1588. url = formatFilter('{0}usrs/?deptid={1}', cfg.api, deptid);
  1589. }
  1590. if (compid != undefined && deptid != undefined) {
  1591. url = formatFilter('{0}usrs/?compid={1}&deptid={2}', cfg.api, compid, deptid);
  1592. }
  1593. return Tool.get(url)
  1594. },
  1595. getChildDept: function (pid) {
  1596. return _.filter(this.all(), function (dept) {
  1597. return parseInt(dept.parent) == parseInt(pid);
  1598. });
  1599. },
  1600. getUsrDetail: function () {
  1601. return Tool.get(formatFilter('{0}usrs/{1}/?compid={2}', cfg.api, global.user.usrid, global.user.compno), true, 'userinfo');
  1602. },
  1603. putUsrInfo: function (data) {
  1604. data.dept = data.dept_id;
  1605. data = _.pick(data, 'username', 'sex', 'dept', 'degree', 'email');
  1606. return Tool.put(formatFilter('{0}usrs/{1}/', cfg.api, global.user.usrid), data)
  1607. }
  1608. };
  1609. })
  1610. .factory('General', function ($http, $q, cfg, global, formatFilter) {
  1611. var Comment = {};
  1612. var Read = {};
  1613. return {
  1614. getComment: function (id, module) {
  1615. var url = formatFilter('{0}{1}/comments/?{2}id={3}', cfg.api, module, module, id);
  1616. var deferred = $q.defer();
  1617. $http.get(url).then(function (res) {
  1618. deferred.resolve(res.data);
  1619. Comment = res.data;
  1620. },
  1621. function (err) {
  1622. deferred.reject(err);
  1623. });
  1624. return deferred.promise;
  1625. },
  1626. getRead: function (id, module, type) {
  1627. var url = formatFilter('{0}{1}/readeds/?{2}id={3}', cfg.api, module, module, id);
  1628. if (type != undefined) {
  1629. url += '&type=unreads'
  1630. }
  1631. var deferred = $q.defer();
  1632. $http.get(url).then(function (res) {
  1633. deferred.resolve(res.data);
  1634. },
  1635. function (err) {
  1636. deferred.reject(err);
  1637. });
  1638. return deferred.promise;
  1639. },
  1640. postComment: function (data, module) {
  1641. var url = formatFilter('{0}{1}/comment/', cfg.api, module);
  1642. var deferred = $q.defer();
  1643. $http.post(url, data, {
  1644. headers: {
  1645. 'Content-Type': 'application/json'
  1646. }
  1647. }).then(function (res) {
  1648. console.log(res.data)
  1649. deferred.resolve(res.data);
  1650. res.data.user__username = global.user.usrname;
  1651. res.data.user_id = global.user.usrid;
  1652. res.data.create_dd = new Date();
  1653. Comment.splice(0, 0, res.data);
  1654. },
  1655. function (err) {
  1656. deferred.reject(err);
  1657. });
  1658. return deferred.promise;
  1659. },
  1660. postRead: function (data, module) {
  1661. console.log(Read)
  1662. var url = formatFilter('{0}{1}/readeds/', cfg.api, module);
  1663. var deferred = $q.defer();
  1664. $http.post(url, data, {
  1665. headers: {
  1666. 'Content-Type': 'application/json'
  1667. }
  1668. }).then(function (res) {
  1669. deferred.resolve(res.data);
  1670. },
  1671. function (err) {
  1672. deferred.reject(err);
  1673. });
  1674. return deferred.promise;
  1675. },
  1676. deleteComment: function (id, module) {
  1677. var comment = _.find(Comment, function (item) {
  1678. if (item.id === parseInt(id)) {
  1679. return item;
  1680. }
  1681. })
  1682. if (comment != undefined) {
  1683. Comment.splice(Comment.indexOf(comment), 1);
  1684. var url = formatFilter('{0}{1}/comment/{2}/', cfg.api, module, id);
  1685. return $http.delete(url);
  1686. }
  1687. }
  1688. }
  1689. })
  1690. starter.filter("format", function () {
  1691. return function (input) {
  1692. var args = arguments;
  1693. return input.replace(/\{(\d+)\}/g, function (match, capture) {
  1694. return args[1 * capture + 1];
  1695. });
  1696. };
  1697. })
  1698. .filter('getDateDiff', function () {
  1699. return function (dateTimeStamp) {
  1700. if (dateTimeStamp == null) {
  1701. return null;
  1702. }
  1703. var minute = 1000 * 60;
  1704. var hour = minute * 60;
  1705. var day = hour * 24;
  1706. var week = day * 7;
  1707. var month = day * 30;
  1708. var year = day * 365;
  1709. var now = new Date().getTime();
  1710. var datetime = new Date(dateTimeStamp).getTime()
  1711. var diffValue = now - datetime;
  1712. if (diffValue + 10000 < 0) {
  1713. //非法操作
  1714. return false;
  1715. }
  1716. var yearC = diffValue / year;
  1717. var monthC = diffValue / month;
  1718. var weekC = diffValue / week;
  1719. var dayC = diffValue / day;
  1720. var hourC = diffValue / hour;
  1721. var minC = diffValue / minute;
  1722. if (yearC >= 1) {
  1723. result = parseInt(yearC) + "年前";
  1724. } else if (monthC >= 1) {
  1725. result = parseInt(monthC) + "个月前";
  1726. } else if (weekC >= 1) {
  1727. result = parseInt(weekC) + "周前";
  1728. } else if (dayC >= 1) {
  1729. result = parseInt(dayC) + "天前";
  1730. } else if (hourC >= 1) {
  1731. result = parseInt(hourC) + "小时前";
  1732. } else if (minC >= 1) {
  1733. result = parseInt(minC) + "分钟前";
  1734. } else
  1735. result = "刚刚";
  1736. return result;
  1737. }
  1738. })
  1739. .filter('SwitchHtmlContent', function () {
  1740. return function (content) {
  1741. if (content != null) {
  1742. content = content.replace(/\n/g, '<br/>');
  1743. if (typeof ioNull != 'undefined') {
  1744. return ioNull.emoji.parse(content);
  1745. }
  1746. }
  1747. return content;
  1748. }
  1749. })
  1750. .filter('percentage', function ($window) {
  1751. return function (input, decimals, suffix) {
  1752. decimals = angular.isNumber(decimals) ? decimals : 2;
  1753. suffix = suffix || '%';
  1754. if ($window.isNaN(input)) {
  1755. return '';
  1756. }
  1757. return Math.round(input * Math.pow(10, decimals + 2)) / Math.pow(10, decimals) + suffix
  1758. };
  1759. })
  1760. .filter('strtimeformat', function ($filter) {
  1761. var dateFilter = $filter('date');
  1762. function formatter(value) {
  1763. return dateFilter(value, 'HH:mm'); //format
  1764. }
  1765. return function (str) {
  1766. if (str == null)
  1767. return null;
  1768. str = new Date('2016/10/1 ' + str);
  1769. return formatter(str);
  1770. };
  1771. })