starter.js 66 KB

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