o2m.api.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. /** ***** BEGIN LICENSE BLOCK *****
  2. * |------------------------------------------------------------------------------|
  3. * | O2OA 活力办公 创意无限 o2m.api.js |
  4. * |------------------------------------------------------------------------------|
  5. * | Distributed under the AGPL license: |
  6. * |------------------------------------------------------------------------------|
  7. * | Copyright © 2018, o2oa.net, o2server.io O2 Team |
  8. * | All rights reserved. |
  9. * |------------------------------------------------------------------------------|
  10. *
  11. * This file is part of O2OA.
  12. *
  13. * O2OA is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as published by
  15. * the Free Software Foundation, either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * O2OA is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
  25. *
  26. * ***** END LICENSE BLOCK ******/
  27. (function () {
  28. this.o2m = {
  29. version: {
  30. v: "1.0.0",
  31. build: "2019.04.20",
  32. info: "O2OA 活力办公 创意无限. Copyright © 2019, o2oa.net O2 Team All rights reserved."
  33. },
  34. log: function (message) {
  35. window.o2android && window.o2android.o2mLog ? window.o2android.o2mLog(message) : window.webkit.messageHandlers.o2mLog.postMessage(message);
  36. }
  37. };
  38. /** ***** BEGIN NOTIFICATION BLOCK *****
  39. notification 模块
  40. alert
  41. confirm
  42. prompt
  43. vibrate
  44. toast
  45. actionSheet
  46. showLoading
  47. hideLoading
  48. * ***** END NOTIFICATION BLOCK ******/
  49. this.o2m.notification = {};
  50. var _notification_post = function (body, onFail) {
  51. if (body == null) {
  52. if (onFail && typeof onFail === "function") {
  53. onFail("参数异常!");
  54. return
  55. }
  56. }
  57. var message = JSON.stringify(body);
  58. if ((window.o2mNotification && window.o2mNotification.postMessage) || (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.o2mNotification)) {
  59. window.o2mNotification && window.o2mNotification.postMessage ? window.o2mNotification.postMessage(message) : window.webkit.messageHandlers.o2mNotification.postMessage(message);
  60. } else {
  61. if (onFail && typeof onFail === "function") {
  62. onFail("请在O2OA移动端使用!");
  63. return
  64. }
  65. }
  66. };
  67. // notification.alert
  68. this.o2m.notification.alertSuccess = function () {
  69. console.log("notification alert back");
  70. };
  71. var _o2m_n_alert = function (alert) {
  72. var message = alert && alert.message ? alert.message : "";
  73. var title = alert && alert.title ? alert.title : "";
  74. var buttonName = alert && alert.buttonName ? alert.buttonName : "";
  75. var onSuccess = alert && alert.onSuccess ? alert.onSuccess : null;
  76. var onFail = alert && alert.onFail ? alert.onFail : null;
  77. if (message === "") {
  78. if (typeof onFail === "function") { onFail("消息内容不能为空!"); }
  79. return;
  80. }
  81. if (onSuccess && typeof onSuccess === "function") {
  82. o2m.notification.alertSuccess = onSuccess;
  83. }
  84. var body = {
  85. type: "alert",
  86. callback: "o2m.notification.alertSuccess",
  87. data: {
  88. message: message,
  89. title: title,
  90. buttonName: buttonName,
  91. }
  92. };
  93. _notification_post(body, onFail);
  94. };
  95. this.o2m.notification.alert = _o2m_n_alert;
  96. //notification.confirm
  97. this.o2m.notification.confirmSuccess = function (index) {
  98. console.log("notification confirm back, click button index: " + index);
  99. };
  100. var _o2m_n_confirm = function (c) {
  101. var buttonLabels = c && c.buttonLabels ? c.buttonLabels : ["确定", "取消"];
  102. var message = c && c.message ? c.message : "";
  103. var title = c && c.title ? c.title : "";
  104. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  105. var onFail = c && c.onFail ? c.onFail : null;
  106. if (message === "") {
  107. if (typeof onFail === "function") { onFail("消息内容message不能为空!"); }
  108. return;
  109. }
  110. if (buttonLabels.length != 2) {
  111. if (typeof onFail === "function") { onFail("按钮名称数组长度只能是2!"); }
  112. return;
  113. }
  114. if (onSuccess && typeof onSuccess === "function") {
  115. o2m.notification.confirmSuccess = onSuccess;
  116. }
  117. var body = {
  118. type: "confirm",
  119. callback: "o2m.notification.confirmSuccess",
  120. data: {
  121. message: message,
  122. title: title,
  123. buttonLabels: buttonLabels,
  124. }
  125. };
  126. _notification_post(body, onFail);
  127. }
  128. this.o2m.notification.confirm = _o2m_n_confirm;
  129. //notification.prompt
  130. this.o2m.notification.promptSuccess = function (result) {
  131. console.log("notification prompt back, click button result: " + result);
  132. };
  133. var _o2m_n_prompt = function (c) {
  134. var buttonLabels = c && c.buttonLabels ? c.buttonLabels : ["确定", "取消"];
  135. var message = c && c.message ? c.message : "";
  136. var title = c && c.title ? c.title : "";
  137. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  138. var onFail = c && c.onFail ? c.onFail : null;
  139. if (message === "") {
  140. if (typeof onFail === "function") { onFail("消息内容message不能为空!"); }
  141. return;
  142. }
  143. if (buttonLabels.length != 2) {
  144. if (typeof onFail === "function") { onFail("按钮名称数组长度只能是2!"); }
  145. return;
  146. }
  147. if (onSuccess && typeof onSuccess === "function") {
  148. o2m.notification.promptSuccess = onSuccess;
  149. }
  150. var body = {
  151. type: "prompt",
  152. callback: "o2m.notification.promptSuccess",
  153. data: {
  154. message: message,
  155. title: title,
  156. buttonLabels: buttonLabels,
  157. }
  158. };
  159. _notification_post(body, onFail);
  160. }
  161. this.o2m.notification.prompt = _o2m_n_prompt;
  162. //notification.vibrate
  163. this.o2m.notification.vibrateSuccess = function () {
  164. console.log("notification vibrate back, click button");
  165. };
  166. var _o2m_n_vibrate = function (c) {
  167. var duration = c && c.duration ? c.duration : 300;
  168. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  169. var onFail = c && c.onFail ? c.onFail : null;
  170. if (onSuccess && typeof onSuccess === "function") {
  171. o2m.notification.vibrateSuccess = onSuccess;
  172. }
  173. var body = {
  174. type: "vibrate",
  175. callback: "o2m.notification.vibrateSuccess",
  176. data: {
  177. duration: duration
  178. }
  179. };
  180. _notification_post(body, onFail);
  181. };
  182. this.o2m.notification.vibrate = _o2m_n_vibrate;
  183. //notification.toast
  184. this.o2m.notification.toastSuccess = function () {
  185. console.log("notification toast back, click button");
  186. };
  187. var _o2m_n_toast = function (c) {
  188. var duration = c && c.duration ? c.duration : 300;
  189. var message = c && c.message ? c.message : "";
  190. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  191. var onFail = c && c.onFail ? c.onFail : null;
  192. if (message === "") {
  193. if (typeof onFail === "function") { onFail("消息内容message不能为空!"); }
  194. return;
  195. }
  196. if (onSuccess && typeof onSuccess === "function") {
  197. o2m.notification.toastSuccess = onSuccess;
  198. }
  199. var body = {
  200. type: "toast",
  201. callback: "o2m.notification.toastSuccess",
  202. data: {
  203. duration: duration,
  204. message: message
  205. }
  206. };
  207. _notification_post(body, onFail);
  208. };
  209. this.o2m.notification.toast = _o2m_n_toast;
  210. //notification.actionSheet
  211. this.o2m.notification.actionSheetSuccess = function (buttonIndex) {
  212. console.log("notification actionSheet back, click button:" + buttonIndex);
  213. };
  214. var _o2m_n_actionSheet = function (c) {
  215. var title = c && c.title ? c.title : "";
  216. var cancelButton = c && c.cancelButton ? c.cancelButton : "取消";
  217. var otherButtons = c && c.otherButtons ? c.otherButtons : [];
  218. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  219. var onFail = c && c.onFail ? c.onFail : null;
  220. if (title === "") {
  221. if (typeof onFail === "function") { onFail("title标题不能为空!"); }
  222. return;
  223. }
  224. if (otherButtons.length < 1) {
  225. if (typeof onFail === "function") { onFail("其他按钮列表不能为空!"); }
  226. return;
  227. }
  228. if (onSuccess && typeof onSuccess === "function") {
  229. o2m.notification.actionSheetSuccess = onSuccess;
  230. }
  231. var body = {
  232. type: "actionSheet",
  233. callback: "o2m.notification.actionSheetSuccess",
  234. data: {
  235. title: title,
  236. cancelButton: cancelButton,
  237. otherButtons: otherButtons
  238. }
  239. };
  240. _notification_post(body, onFail);
  241. };
  242. this.o2m.notification.actionSheet = _o2m_n_actionSheet;
  243. //notification.showLoading
  244. this.o2m.notification.showLoadingSuccess = function () {
  245. console.log("notification showLoading back");
  246. };
  247. var _o2m_n_showLoading = function (c) {
  248. var text = c && c.text ? c.text : "";
  249. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  250. var onFail = c && c.onFail ? c.onFail : null;
  251. if (onSuccess && typeof onSuccess === "function") {
  252. o2m.notification.showLoadingSuccess = onSuccess;
  253. }
  254. var body = {
  255. type: "showLoading",
  256. callback: "o2m.notification.showLoadingSuccess",
  257. data: {
  258. text: text
  259. }
  260. };
  261. _notification_post(body, onFail);
  262. };
  263. this.o2m.notification.showLoading = _o2m_n_showLoading;
  264. //notification.hideLoading
  265. this.o2m.notification.hideLoadingSuccess = function () {
  266. console.log("notification hideLoading back");
  267. };
  268. var _o2m_n_hideLoading = function (c) {
  269. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  270. var onFail = c && c.onFail ? c.onFail : null;
  271. if (onSuccess && typeof onSuccess === "function") {
  272. o2m.notification.hideLoadingSuccess = onSuccess;
  273. }
  274. var body = {
  275. type: "hideLoading",
  276. callback: "o2m.notification.hideLoadingSuccess",
  277. data: {
  278. }
  279. };
  280. _notification_post(body, onFail);
  281. }
  282. this.o2m.notification.hideLoading = _o2m_n_hideLoading;
  283. /** ***** BEGIN UTIL BLOCK *****
  284. util 模块
  285. date
  286. o2m.util.date.datePicker
  287. o2m.util.date.timePicker
  288. o2m.util.date.dateTimePicker
  289. calendar
  290. o2m.util.calendar.chooseOneDay
  291. o2m.util.calendar.chooseDateTime
  292. o2m.util.calendar.chooseInterval
  293. device
  294. o2m.util.device.getPhoneInfo
  295. o2m.util.device.scan
  296. navigation
  297. o2m.util.navigation.setTitle
  298. o2m.util.navigation.close
  299. o2m.util.navigation.goBack
  300. * ***** END UTIL BLOCK ******/
  301. this.o2m.util = {
  302. date: {},
  303. calendar: {},
  304. device: {},
  305. navigation: {}
  306. };
  307. var _util_post = function (body, onFail) {
  308. if (body == null) {
  309. if (onFail && typeof onFail === "function") {
  310. onFail("参数异常!");
  311. return;
  312. }
  313. }
  314. var message = JSON.stringify(body);
  315. if ((window.o2mUtil && window.o2mUtil.postMessage) || (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.o2mUtil)) {
  316. window.o2mUtil && window.o2mUtil.postMessage ? window.o2mUtil.postMessage(message) : window.webkit.messageHandlers.o2mUtil.postMessage(message);
  317. } else {
  318. if (onFail && typeof onFail === "function") {
  319. onFail("请在O2OA移动端使用!");
  320. }
  321. }
  322. };
  323. //o2m.util.date.datePicker
  324. this.o2m.util.date.datePickerSuccess = function (result) {
  325. console.log("util date datePicker back, result:" + result);
  326. };
  327. var _o2m_u_date_datePicker = function (c) {
  328. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  329. var onFail = c && c.onFail ? c.onFail : null;
  330. var value = c && c.value ? c.value : "";
  331. if (onSuccess && typeof onSuccess === "function") {
  332. o2m.util.date.datePickerSuccess = onSuccess;
  333. }
  334. var body = {
  335. type: "date.datePicker",
  336. callback: "o2m.util.date.datePickerSuccess",
  337. data: {
  338. value: value
  339. }
  340. };
  341. _util_post(body, onFail);
  342. };
  343. this.o2m.util.date.datePicker = _o2m_u_date_datePicker;
  344. //o2m.util.date.timePicker
  345. this.o2m.util.date.timePickerSuccess = function (result) {
  346. console.log("util date timePicker back, result:" + result);
  347. };
  348. var _o2m_u_date_timePicker = function (c) {
  349. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  350. var onFail = c && c.onFail ? c.onFail : null;
  351. var value = c && c.value ? c.value : "";
  352. if (onSuccess && typeof onSuccess === "function") {
  353. o2m.util.date.timePickerSuccess = onSuccess;
  354. }
  355. var body = {
  356. type: "date.timePicker",
  357. callback: "o2m.util.date.timePickerSuccess",
  358. data: {
  359. value: value
  360. }
  361. };
  362. _util_post(body, onFail);
  363. };
  364. this.o2m.util.date.timePicker = _o2m_u_date_timePicker;
  365. //o2m.util.date.dateTimePicker
  366. this.o2m.util.date.dateTimePickerSuccess = function (result) {
  367. console.log("util date dateTimePicker back, result:" + result);
  368. };
  369. var _o2m_u_date_dateTimePicker = function (c) {
  370. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  371. var onFail = c && c.onFail ? c.onFail : null;
  372. var value = c && c.value ? c.value : "";
  373. if (onSuccess && typeof onSuccess === "function") {
  374. o2m.util.date.dateTimePickerSuccess = onSuccess;
  375. }
  376. var body = {
  377. type: "date.dateTimePicker",
  378. callback: "o2m.util.date.dateTimePickerSuccess",
  379. data: {
  380. value: value
  381. }
  382. };
  383. _util_post(body, onFail);
  384. };
  385. this.o2m.util.date.dateTimePicker = _o2m_u_date_dateTimePicker;
  386. //o2m.util.calendar.chooseOneDay
  387. this.o2m.util.calendar.chooseOneDaySuccess = function (result) {
  388. console.log("util calendar chooseOneDay back, result:" + result);
  389. };
  390. var _o2m_u_calendar_chooseOneDay = function (c) {
  391. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  392. var onFail = c && c.onFail ? c.onFail : null;
  393. var value = c && c.value ? c.value : "";
  394. if (onSuccess && typeof onSuccess === "function") {
  395. o2m.util.calendar.chooseOneDaySuccess = onSuccess;
  396. }
  397. var body = {
  398. type: "calendar.chooseOneDay",
  399. callback: "o2m.util.calendar.chooseOneDaySuccess",
  400. data: {
  401. value: value
  402. }
  403. };
  404. _util_post(body, onFail);
  405. };
  406. this.o2m.util.calendar.chooseOneDay = _o2m_u_calendar_chooseOneDay;
  407. //o2m.util.calendar.chooseDateTime
  408. this.o2m.util.calendar.chooseDateTimeSuccess = function (result) {
  409. console.log("util calendar chooseDateTime back, result:" + result);
  410. };
  411. var _o2m_u_calendar_chooseDateTime = function (c) {
  412. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  413. var onFail = c && c.onFail ? c.onFail : null;
  414. var value = c && c.value ? c.value : "";
  415. if (onSuccess && typeof onSuccess === "function") {
  416. o2m.util.calendar.chooseDateTimeSuccess = onSuccess;
  417. }
  418. var body = {
  419. type: "calendar.chooseDateTime",
  420. callback: "o2m.util.calendar.chooseDateTimeSuccess",
  421. data: {
  422. value: value
  423. }
  424. };
  425. _util_post(body, onFail);
  426. };
  427. this.o2m.util.calendar.chooseDateTime = _o2m_u_calendar_chooseDateTime;
  428. //o2m.util.calendar.chooseInterval
  429. this.o2m.util.calendar.chooseIntervalSuccess = function (result) {
  430. console.log("util calendar chooseInterval back, result:" + result);
  431. };
  432. var _o2m_u_calendar_chooseInterval = function (c) {
  433. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  434. var onFail = c && c.onFail ? c.onFail : null;
  435. var startDate = c && c.startDate ? c.startDate : "";
  436. var endDate = c && c.endDate ? c.endDate : "";
  437. if (onSuccess && typeof onSuccess === "function") {
  438. o2m.util.calendar.chooseIntervalSuccess = onSuccess;
  439. }
  440. var body = {
  441. type: "calendar.chooseInterval",
  442. callback: "o2m.util.calendar.chooseIntervalSuccess",
  443. data: {
  444. startDate: startDate,
  445. endDate: endDate
  446. }
  447. };
  448. _util_post(body, onFail);
  449. };
  450. this.o2m.util.calendar.chooseInterval = _o2m_u_calendar_chooseInterval;
  451. //o2m.util.device.getPhoneInfo
  452. this.o2m.util.device.getPhoneInfoSuccess = function (result) {
  453. console.log("util calendar chooseInterval back, result:" + result);
  454. };
  455. var _o2m_u_device_getPhoneInfo = function (c) {
  456. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  457. var onFail = c && c.onFail ? c.onFail : null;
  458. if (onSuccess && typeof onSuccess === "function") {
  459. o2m.util.device.getPhoneInfoSuccess = onSuccess;
  460. }
  461. var body = {
  462. type: "device.getPhoneInfo",
  463. callback: "o2m.util.device.getPhoneInfoSuccess",
  464. data: {
  465. }
  466. };
  467. _util_post(body, onFail);
  468. };
  469. this.o2m.util.device.getPhoneInfo = _o2m_u_device_getPhoneInfo;
  470. //o2m.util.device.scan
  471. this.o2m.util.device.scanSuccess = function (result) {
  472. console.log("util calendar chooseInterval back, result:" + result);
  473. };
  474. var _o2m_u_device_scan = function (c) {
  475. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  476. var onFail = c && c.onFail ? c.onFail : null;
  477. if (onSuccess && typeof onSuccess === "function") {
  478. o2m.util.device.scanSuccess = onSuccess;
  479. }
  480. var body = {
  481. type: "device.scan",
  482. callback: "o2m.util.device.scanSuccess",
  483. data: {
  484. }
  485. };
  486. _util_post(body, onFail);
  487. };
  488. this.o2m.util.device.scan = _o2m_u_device_scan;
  489. //o2m.util.navigation.setTitle
  490. this.o2m.util.navigation.setTitleSuccess = function (result) {
  491. console.log("util calendar chooseInterval back, result:" + result);
  492. };
  493. var _o2m_u_navigation_setTitle = function (c) {
  494. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  495. var onFail = c && c.onFail ? c.onFail : null;
  496. var title = c && c.title ? c.title : "";
  497. if (onSuccess && typeof onSuccess === "function") {
  498. o2m.util.navigation.setTitleSuccess = onSuccess;
  499. }
  500. var body = {
  501. type: "navigation.setTitle",
  502. callback: "o2m.util.navigation.setTitleSuccess",
  503. data: {
  504. title: title
  505. }
  506. };
  507. _util_post(body, onFail);
  508. };
  509. this.o2m.util.navigation.setTitle = _o2m_u_navigation_setTitle;
  510. //o2m.util.navigation.close
  511. this.o2m.util.navigation.closeSuccess = function (result) {
  512. console.log("util calendar chooseInterval back, result:" + result);
  513. };
  514. var _o2m_u_navigation_close = function (c) {
  515. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  516. var onFail = c && c.onFail ? c.onFail : null;
  517. if (onSuccess && typeof onSuccess === "function") {
  518. o2m.util.navigation.closeSuccess = onSuccess;
  519. }
  520. var body = {
  521. type: "navigation.close",
  522. callback: "o2m.util.navigation.closeSuccess",
  523. data: {
  524. }
  525. };
  526. _util_post(body, onFail);
  527. };
  528. this.o2m.util.navigation.close = _o2m_u_navigation_close;
  529. //o2m.util.navigation.goBack
  530. this.o2m.util.navigation.goBackSuccess = function (result) {
  531. console.log("util calendar chooseInterval back, result:" + result);
  532. };
  533. var _o2m_u_navigation_goBack = function (c) {
  534. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  535. var onFail = c && c.onFail ? c.onFail : null;
  536. if (onSuccess && typeof onSuccess === "function") {
  537. o2m.util.navigation.goBackSuccess = onSuccess;
  538. }
  539. var body = {
  540. type: "navigation.goBack",
  541. callback: "o2m.util.navigation.goBackSuccess",
  542. data: {
  543. }
  544. };
  545. _util_post(body, onFail);
  546. };
  547. this.o2m.util.navigation.goBack = _o2m_u_navigation_goBack;
  548. /** ***** BEGIN BIZ BLOCK *****
  549. biz 模块
  550. contact
  551. o2m.biz.contact.PersonPicker
  552. o2m.biz.contact.IdentityPicker
  553. o2m.biz.contact.departmentsPicker
  554. o2m.biz.contact.ComplexPicker
  555. o2m.biz.contact.GroupPicker
  556. * ***** END UTIL BLOCK ******/
  557. this.o2m.biz = {
  558. contact: {}
  559. };
  560. var _biz_post = function (body, onFail) {
  561. if (body == null) {
  562. if (onFail && typeof onFail === "function") {
  563. onFail("参数异常!");
  564. return;
  565. }
  566. }
  567. var message = JSON.stringify(body);
  568. if ((window.o2mBiz && window.o2mBiz.postMessage) || (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.o2mBiz)) {
  569. window.o2mBiz && window.o2mBiz.postMessage ? window.o2mBiz.postMessage(message) : window.webkit.messageHandlers.o2mBiz.postMessage(message);
  570. } else {
  571. if (onFail && typeof onFail === "function") {
  572. onFail("请在O2OA移动端使用!");
  573. }
  574. }
  575. };
  576. //o2m.biz.workClose()
  577. var _o2m_b_work_close = function () {
  578. if (window.o2android && window.o2android.closeWork) {
  579. window.o2android.closeWork("");
  580. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.closeWork) {
  581. window.webkit.messageHandlers.closeWork.postMessage("");
  582. } else {
  583. console.log("请在O2OA移动端使用, workClose");
  584. }
  585. }
  586. this.o2m.biz.workClose = _o2m_b_work_close;
  587. //o2m.biz.contact.departmentsPicker
  588. this.o2m.biz.contact.departmentsPickerSuccess = function (result) {
  589. console.log("biz contact departmentsPicker back, result:" + result);
  590. };
  591. var _o2m_b_contact_department_picker = function (c) {
  592. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  593. var onFail = c && c.onFail ? c.onFail : null;
  594. if (onSuccess && typeof onSuccess === "function") {
  595. o2m.biz.contact.departmentsPickerSuccess = onSuccess;
  596. }
  597. var topList = c && c.topList ? c.topList : [];
  598. var orgType = c && c.orgType ? c.orgType : "";
  599. var multiple = c && c.multiple ? c.multiple : false;
  600. var maxNumber = c && c.maxNumber ? c.maxNumber : 0;
  601. var pickedDepartments = c && c.pickedDepartments ? c.pickedDepartments : [];
  602. var body = {
  603. type: "contact.departmentPicker",
  604. callback: "o2m.biz.contact.departmentsPickerSuccess",
  605. data: {
  606. topList: topList,
  607. orgType: orgType,
  608. multiple: multiple,
  609. maxNumber: maxNumber,
  610. pickedDepartments: pickedDepartments,
  611. }
  612. };
  613. _biz_post(body, onFail);
  614. };
  615. this.o2m.biz.contact.departmentsPicker = _o2m_b_contact_department_picker;
  616. //o2m.biz.contact.IdentityPicker
  617. this.o2m.biz.contact.IdentityPickerSuccess = function (result) {
  618. console.log("biz contact IdentityPicker back, result:" + result);
  619. };
  620. var _o2m_b_contact_identity_picker = function (c) {
  621. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  622. var onFail = c && c.onFail ? c.onFail : null;
  623. if (onSuccess && typeof onSuccess === "function") {
  624. o2m.biz.contact.IdentityPickerSuccess = onSuccess;
  625. }
  626. var topList = c && c.topList ? c.topList : [];
  627. var multiple = c && c.multiple ? c.multiple : false;
  628. var maxNumber = c && c.maxNumber ? c.maxNumber : 0;
  629. var pickedIdentities = c && c.pickedIdentities ? c.pickedIdentities : [];
  630. var duty = c && c.duty ? c.duty : [];
  631. var body = {
  632. type: "contact.identityPicker",
  633. callback: "o2m.biz.contact.IdentityPickerSuccess",
  634. data: {
  635. topList: topList,
  636. multiple: multiple,
  637. maxNumber: maxNumber,
  638. pickedIdentities: pickedIdentities,
  639. duty: duty,
  640. }
  641. };
  642. _biz_post(body, onFail);
  643. };
  644. this.o2m.biz.contact.IdentityPicker = _o2m_b_contact_identity_picker;
  645. //o2m.biz.contact.GroupPicker
  646. this.o2m.biz.contact.GroupPickerSuccess = function (result) {
  647. console.log("biz contact GroupPicker back, result:" + result);
  648. };
  649. var _o2m_b_contact_group_picker = function (c) {
  650. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  651. var onFail = c && c.onFail ? c.onFail : null;
  652. if (onSuccess && typeof onSuccess === "function") {
  653. o2m.biz.contact.GroupPickerSuccess = onSuccess;
  654. }
  655. var multiple = c && c.multiple ? c.multiple : false;
  656. var maxNumber = c && c.maxNumber ? c.maxNumber : 0;
  657. var pickedGroups = c && c.pickedGroups ? c.pickedGroups : [];
  658. var body = {
  659. type: "contact.groupPicker",
  660. callback: "o2m.biz.contact.GroupPickerSuccess",
  661. data: {
  662. multiple: multiple,
  663. maxNumber: maxNumber,
  664. pickedGroups: pickedGroups,
  665. }
  666. };
  667. _biz_post(body, onFail);
  668. };
  669. this.o2m.biz.contact.GroupPicker = _o2m_b_contact_group_picker;
  670. //o2m.biz.contact.PersonPicker
  671. this.o2m.biz.contact.PersonPickerSuccess = function (result) {
  672. console.log("biz contact PersonPicker back, result:" + result);
  673. };
  674. var _o2m_b_contact_person_picker = function (c) {
  675. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  676. var onFail = c && c.onFail ? c.onFail : null;
  677. if (onSuccess && typeof onSuccess === "function") {
  678. o2m.biz.contact.PersonPickerSuccess = onSuccess;
  679. }
  680. var multiple = c && c.multiple ? c.multiple : false;
  681. var maxNumber = c && c.maxNumber ? c.maxNumber : 0;
  682. var pickedUsers = c && c.pickedUsers ? c.pickedUsers : [];
  683. var body = {
  684. type: "contact.personPicker",
  685. callback: "o2m.biz.contact.PersonPickerSuccess",
  686. data: {
  687. multiple: multiple,
  688. maxNumber: maxNumber,
  689. pickedUsers: pickedUsers,
  690. }
  691. };
  692. _biz_post(body, onFail);
  693. };
  694. this.o2m.biz.contact.PersonPicker = _o2m_b_contact_person_picker;
  695. //o2m.biz.contact.ComplexPicker
  696. this.o2m.biz.contact.ComplexPickerSuccess = function (result) {
  697. console.log("biz contact ComplexPicker back, result:" + result);
  698. };
  699. var _o2m_b_contact_complex_picker = function (c) {
  700. var onSuccess = c && c.onSuccess ? c.onSuccess : null;
  701. var onFail = c && c.onFail ? c.onFail : null;
  702. if (onSuccess && typeof onSuccess === "function") {
  703. o2m.biz.contact.ComplexPickerSuccess = onSuccess;
  704. }
  705. var pickMode = c && c.pickMode ? c.pickMode : [];
  706. var multiple = c && c.multiple ? c.multiple : false;
  707. var maxNumber = c && c.maxNumber ? c.maxNumber : 0;
  708. var topList = c && c.topList ? c.topList : [];
  709. var orgType = c && c.orgType ? c.orgType : "";
  710. var duty = c && c.duty ? c.duty : [];
  711. var pickedGroups = c && c.pickedGroups ? c.pickedGroups : [];
  712. var pickedUsers = c && c.pickedUsers ? c.pickedUsers : [];
  713. var pickedIdentities = c && c.pickedIdentities ? c.pickedIdentities : [];
  714. var pickedDepartments = c && c.pickedDepartments ? c.pickedDepartments : [];
  715. var body = {
  716. type: "contact.complexPicker",
  717. callback: "o2m.biz.contact.ComplexPickerSuccess",
  718. data: {
  719. pickMode: pickMode,
  720. multiple: multiple,
  721. maxNumber: maxNumber,
  722. topList: topList,
  723. orgType: orgType,
  724. duty: duty,
  725. pickedGroups: pickedGroups,
  726. pickedUsers: pickedUsers,
  727. pickedIdentities: pickedIdentities,
  728. pickedDepartments: pickedDepartments,
  729. }
  730. };
  731. _biz_post(body, onFail);
  732. };
  733. this.o2m.biz.contact.ComplexPicker = _o2m_b_contact_complex_picker;
  734. })();