o2m.api.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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.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. * ***** END UTIL BLOCK ******/
  294. this.o2m.util = {
  295. date: {},
  296. calendar: {}
  297. };
  298. var _util_post = function(body, onFail) {
  299. if (body == null) {
  300. if (onFail && typeof onFail === "function") {
  301. onFail("参数异常!")
  302. return
  303. }
  304. }
  305. var message = JSON.stringify(body);
  306. if ((window.o2mUtil.postMessage&&window.o2mUtil.postMessage) || (window.webkit.messageHandlers.o2mUtil)) {
  307. window.o2mUtil&&window.o2mUtil.postMessage ? window.o2mUtil.postMessage(message) : window.webkit.messageHandlers.o2mUtil.postMessage(message);
  308. }else {
  309. if (onFail && typeof onFail === "function") {
  310. onFail("请在O2OA移动端使用!")
  311. return
  312. }
  313. }
  314. }
  315. //o2m.util.date.datePicker
  316. this.o2m.util.date.datePickerSuccess = function(result) {
  317. console.log("util date datePicker back, result:"+result);
  318. };
  319. var _o2m_u_date_datePicker = function(c) {
  320. var onSuccess = c&&c.onSuccess ? c.onSuccess : null;
  321. var onFail = c&&c.onFail ? c.onFail : null;
  322. var value = c&&c.value ? c.value : "";
  323. if(onSuccess && typeof onSuccess === "function"){
  324. o2m.util.date.datePickerSuccess = onSuccess;
  325. }
  326. var body = {
  327. type: "date.datePicker",
  328. callback: "o2m.util.date.datePickerSuccess",
  329. data: {
  330. value: value
  331. }
  332. };
  333. _util_post(body, onFail);
  334. }
  335. this.o2m.util.date.datePicker = _o2m_u_date_datePicker;
  336. //o2m.util.date.timePicker
  337. this.o2m.util.date.timePickerSuccess = function(result) {
  338. console.log("util date timePicker back, result:"+result);
  339. };
  340. var _o2m_u_date_timePicker = function(c) {
  341. var onSuccess = c&&c.onSuccess ? c.onSuccess : null;
  342. var onFail = c&&c.onFail ? c.onFail : null;
  343. var value = c&&c.value ? c.value : "";
  344. if(onSuccess && typeof onSuccess === "function"){
  345. o2m.util.date.timePickerSuccess = onSuccess;
  346. }
  347. var body = {
  348. type: "date.timePicker",
  349. callback: "o2m.util.date.timePickerSuccess",
  350. data: {
  351. value: value
  352. }
  353. };
  354. _util_post(body, onFail);
  355. }
  356. this.o2m.util.date.timePicker = _o2m_u_date_timePicker;
  357. //o2m.util.date.dateTimePicker
  358. this.o2m.util.date.dateTimePickerSuccess = function(result) {
  359. console.log("util date dateTimePicker back, result:"+result);
  360. };
  361. var _o2m_u_date_dateTimePicker = function(c) {
  362. var onSuccess = c&&c.onSuccess ? c.onSuccess : null;
  363. var onFail = c&&c.onFail ? c.onFail : null;
  364. var value = c&&c.value ? c.value : "";
  365. if(onSuccess && typeof onSuccess === "function"){
  366. o2m.util.date.dateTimePickerSuccess = onSuccess;
  367. }
  368. var body = {
  369. type: "date.dateTimePicker",
  370. callback: "o2m.util.date.dateTimePickerSuccess",
  371. data: {
  372. value: value
  373. }
  374. };
  375. _util_post(body, onFail);
  376. }
  377. this.o2m.util.date.dateTimePicker = _o2m_u_date_dateTimePicker;
  378. //o2m.util.calendar.chooseOneDay
  379. this.o2m.util.calendar.chooseOneDaySuccess = function(result) {
  380. console.log("util calendar chooseOneDay back, result:"+result);
  381. };
  382. var _o2m_u_calendar_chooseOneDay = function(c) {
  383. var onSuccess = c&&c.onSuccess ? c.onSuccess : null;
  384. var onFail = c&&c.onFail ? c.onFail : null;
  385. var value = c&&c.value ? c.value : "";
  386. if(onSuccess && typeof onSuccess === "function"){
  387. o2m.util.calendar.chooseOneDaySuccess = onSuccess;
  388. }
  389. var body = {
  390. type: "calendar.chooseOneDay",
  391. callback: "o2m.util.calendar.chooseOneDaySuccess",
  392. data: {
  393. value: value
  394. }
  395. };
  396. _util_post(body, onFail);
  397. }
  398. this.o2m.util.calendar.chooseOneDay = _o2m_u_calendar_chooseOneDay;
  399. //o2m.util.calendar.chooseDateTime
  400. this.o2m.util.calendar.chooseDateTimeSuccess = function(result) {
  401. console.log("util calendar chooseDateTime back, result:"+result);
  402. };
  403. var _o2m_u_calendar_chooseDateTime = function(c) {
  404. var onSuccess = c&&c.onSuccess ? c.onSuccess : null;
  405. var onFail = c&&c.onFail ? c.onFail : null;
  406. var value = c&&c.value ? c.value : "";
  407. if(onSuccess && typeof onSuccess === "function"){
  408. o2m.util.calendar.chooseDateTimeSuccess = onSuccess;
  409. }
  410. var body = {
  411. type: "calendar.chooseDateTime",
  412. callback: "o2m.util.calendar.chooseDateTimeSuccess",
  413. data: {
  414. value: value
  415. }
  416. };
  417. _util_post(body, onFail);
  418. }
  419. this.o2m.util.calendar.chooseDateTime = _o2m_u_calendar_chooseDateTime;
  420. //o2m.util.calendar.chooseInterval
  421. this.o2m.util.calendar.chooseIntervalSuccess = function(result) {
  422. console.log("util calendar chooseInterval back, result:"+result);
  423. };
  424. var _o2m_u_calendar_chooseInterval = function(c) {
  425. var onSuccess = c&&c.onSuccess ? c.onSuccess : null;
  426. var onFail = c&&c.onFail ? c.onFail : null;
  427. var startDate = c&&c.startDate ? c.startDate : "";
  428. var endDate = c&&c.endDate ? c.endDate : "";
  429. if(onSuccess && typeof onSuccess === "function"){
  430. o2m.util.calendar.chooseIntervalSuccess = onSuccess;
  431. }
  432. var body = {
  433. type: "calendar.chooseInterval",
  434. callback: "o2m.util.calendar.chooseIntervalSuccess",
  435. data: {
  436. startDate: startDate,
  437. endDate: endDate
  438. }
  439. };
  440. _util_post(body, onFail);
  441. }
  442. this.o2m.util.calendar.chooseInterval = _o2m_u_calendar_chooseInterval;
  443. })();