zhengwuDingdingSso.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. layout = window.layout || {};
  2. var locate = window.location;
  3. layout.protocol = locate.protocol;
  4. layout.mobile = true;
  5. layout.desktop = layout;
  6. layout.session = layout.session || {};
  7. o2.addReady(function(){
  8. var href = locate.href;
  9. if (href.indexOf("debugger")!==-1) layout.debugger = true;
  10. var uri = new URI(href);
  11. var redirectTo = uri.getData("redirectTo");
  12. var optionsStr = (uri.getData("option"));
  13. var statusStr = (uri.getData("status"));
  14. var options = (optionsStr) ? JSON.decode(optionsStr) : null;
  15. var statusObj = (statusStr) ? JSON.decode(statusStr) : null;
  16. o2.load(["../o2_lib/mootools/plugin/mBox.Notice.js", "../o2_lib/mootools/plugin/mBox.Tooltip.js"], {"sequence": true}, function(){
  17. //MWF.defaultPath = "../x_desktop" + MWF.defaultPath;
  18. MWF.loadLP("zh-cn");
  19. // MWF.require("MWF.widget.Mask", null, false);
  20. // layout.mask = new MWF.widget.Mask({"style": "desktop"});
  21. // layout.mask.load();
  22. MWF.require("MWF.xDesktop.Layout", function () {
  23. MWF.xDesktop.requireApp("Common", "", null, false);
  24. MWF.require("MWF.xDesktop.Authentication", null, false);
  25. (function () {
  26. layout.requireApp = function(appNames, callback, clazzName){
  27. var appPath = appNames.split(".");
  28. var appName = appPath[appPath.length-1];
  29. var appObject = "MWF.xApplication."+appNames;
  30. var className = clazzName || "Main";
  31. var appClass = appObject+"."+className;
  32. var appLp = appObject+".lp."+MWF.language;
  33. var baseObject = MWF.xApplication;
  34. appPath.each(function(path, i){
  35. if (i<(appPath.length-1)){
  36. baseObject[path] = baseObject[path] || {};
  37. }else {
  38. baseObject[path] = baseObject[path] || {"options": Object.clone(MWF.xApplication.Common.options)};
  39. }
  40. baseObject = baseObject[path];
  41. }.bind(this));
  42. if (!baseObject.options) baseObject.options = Object.clone(MWF.xApplication.Common.options);
  43. //MWF.xDesktop.requireApp(appNames, "lp."+MWF.language, null, false);
  44. MWF.xDesktop.requireApp(appNames, "lp."+MWF.language, {
  45. "onRequestFailure": function(){
  46. MWF.xDesktop.requireApp(appNames, "lp.zh-cn", null, false);
  47. }.bind(this),
  48. "onSuccess": function(){}.bind(this)
  49. }, false);
  50. MWF.xDesktop.requireApp(appNames, clazzName, function(){
  51. if (callback) callback(baseObject);
  52. });
  53. };
  54. layout.openApplication = function(e, appNames, options, statusObj){
  55. if (layout.app){
  56. layout.desktop.openBrowserApp = appNames;
  57. layout.desktop.openBrowserStatus = statusObj;
  58. layout.desktop.openBrowserOption = options;
  59. var optionsStr = JSON.encode(options);
  60. var statusStr = JSON.encode(statusObj);
  61. //window.open("appMobile.html", "_blank");
  62. //layout.openApplication(null, appNames, option||{}, m_status);
  63. var title = options.docTitle || "";
  64. if (appNames==="process.Work"){
  65. var uri = new URI(window.location.href);
  66. var redirectlink = uri.getData("redirectlink");
  67. if( !redirectlink ){
  68. redirectlink = encodeURIComponent(locate.pathname + locate.search);
  69. }else{
  70. redirectlink = encodeURIComponent(redirectlink);
  71. }
  72. if( options.workId ){
  73. window.location = o2.filterUrl("../x_desktop/workmobilewithaction.html?workid="+options.workId+"&redirectlink="+redirectlink);
  74. }else if( options.workCompletedId ){
  75. window.location = o2.filterUrl("../x_desktop/workmobilewithaction.html?workcompletedid="+options.workCompletedId+"&redirectlink="+redirectlink);
  76. }
  77. }else{
  78. window.location = o2.filterUrl("../x_desktop/appMobile.html?app="+appNames+"&option="+(optionsStr || "")+"&status="+(statusStr || ""));
  79. }
  80. }else{
  81. var appPath = appNames.split(".");
  82. var appName = appPath[appPath.length-1];
  83. layout.requireApp(appNames, function(appNamespace){
  84. this.createNewApplication(e, appNamespace, appName, options, statusObj);
  85. }.bind(this));
  86. }
  87. };
  88. layout.createNewApplication = function(e, appNamespace, appName, options, statusObj){
  89. var app = new appNamespace["Main"](this, options);
  90. app.desktop = layout;
  91. app.inBrowser = true;
  92. app.status = statusObj;
  93. app.load(true);
  94. var appId = appName;
  95. if (options.appId){
  96. appId = options.appId;
  97. }else{
  98. if (appNamespace.options.multitask) appId = appId+"-"+(new MWF.widget.UUID());
  99. }
  100. app.appId = appId;
  101. layout.app = app;
  102. };
  103. layout.load = function () {
  104. // MWF.require("MWF.xDesktop.MessageMobile", function(){
  105. // layout.message = new MWF.xDesktop.MessageMobile();
  106. // layout.message.load();
  107. // }.bind(this));
  108. var uri = href.toURI();
  109. MWF.require("MWF.xDesktop.Actions.RestActions", function () {
  110. var action = new MWF.xDesktop.Actions.RestActions("", "x_organization_assemble_authentication", "");
  111. action.getActions = function (actionCallback) {
  112. this.actions = {
  113. "info": {"uri": "/jaxrs/zhengwudingding/info", "method": "POST"},
  114. "auth": {"uri": "/jaxrs/zhengwudingding/code/{code}"}
  115. };
  116. if (actionCallback) actionCallback();
  117. };
  118. action.invoke({
  119. "name": "info", "async": true, "data": {"url": href}, "success": function (json) {
  120. // if (redirectTo){
  121. // document.all.appContent.src = (redirectTo+"&option="+optionsStr);
  122. // }else{
  123. // document.all.appContent.src = "appMobile.html?app=process.TaskCenter";
  124. // }
  125. //if (document.all.appContentMask) document.all.appContentMask.destroy();
  126. // debugger;
  127. this.isAuthentication(function(){
  128. var appName = "portal.Portal";
  129. var m_status = statusObj;
  130. var option = options;
  131. layout.openApplication(null, appName, option||{}, m_status);
  132. if (document.all.appContentMask) document.all.appContentMask.destroy();
  133. }.bind(this));
  134. // return false;
  135. var _config = json.data;
  136. dd.config({
  137. agentId: _config.agentid,
  138. corpId: _config.corpId,
  139. timeStamp: _config.timeStamp,
  140. nonceStr: _config.nonceStr,
  141. signature: _config.signature,
  142. jsApiList: ['runtime.info']
  143. });
  144. //dd.ready(function() {
  145. dd.biz.navigation.setTitle({
  146. title: ''
  147. });
  148. // dd.runtime.info({
  149. // onSuccess : function(info) {
  150. // logger.e('runtime info: ' + JSON.stringify(info));
  151. // },
  152. // onFail : function(err) {
  153. // logger.e('fail: ' + JSON.stringify(err));
  154. // }
  155. // });
  156. dd.runtime.permission.requestAuthCode({
  157. corpId: _config.corpId,
  158. onSuccess: function (info) {
  159. action.invoke({
  160. "name": "auth",
  161. "async": true,
  162. "parameter": {"code": info.code},
  163. "success": function (json) {
  164. // var appName = appNames;
  165. // var m_status = statusObj;
  166. // var option = options;
  167. // layout.openApplication(null, appName, option||{}, m_status);
  168. // if (redirectTo){
  169. // document.all.appContent.src = (redirectTo+"&option="+option);
  170. // }else{
  171. // document.all.appContent.src = "appMobile.html?app=process.TaskCenter";
  172. // }
  173. // if (document.all.appContentMask) document.all.appContentMask.destroy();
  174. // if (redirectTo){
  175. // (redirectTo+"&option="+option).toURI().go();
  176. // }else{
  177. // "appMobile.html?app=process.TaskCenter".toURI().go();
  178. // }
  179. }.bind(this),
  180. "failure": function (xhr, text, error) {
  181. "appMobile.html?app=process.TaskCenter".toURI().go();
  182. }.bind(this)
  183. });
  184. }.bind(this),
  185. onFail: function (err) {
  186. }
  187. });
  188. //});
  189. }.bind(this), "failure": function (xhr, text, error) {
  190. }.bind(this)
  191. });
  192. }.bind(this));
  193. };
  194. layout.isAuthentication = function(callback){
  195. this.authentication = new MWF.xDesktop.Authentication({
  196. "onLogin": layout.load.bind(layout)
  197. });
  198. var returnValue = true;
  199. this.authentication.isAuthenticated(function(json){
  200. this.user = json.data;
  201. this.session = {};
  202. this.session.user = json.data;
  203. if (callback) callback();
  204. }.bind(this), function(){
  205. this.authentication.loadLogin(document.body);
  206. if (layout.mask) layout.mask.hide();
  207. if (document.all.appContentMask) document.all.appContentMask.destroy();
  208. returnValue = false;
  209. }.bind(this));
  210. return returnValue;
  211. };
  212. layout.notice = function (content, type, target, where, offset) {
  213. if (!where) where = {"x": "right", "y": "top"};
  214. if (!target) target = this.content;
  215. if (!type) type = "ok";
  216. var noticeTarget = target || $(document.body);
  217. var off = offset;
  218. if (!off) {
  219. off = {
  220. x: 10,
  221. y: where.y.toString().toLowerCase() == "bottom" ? 10 : 10
  222. };
  223. }
  224. new mBox.Notice({
  225. type: type,
  226. position: where,
  227. move: false,
  228. target: noticeTarget,
  229. delayClose: (type == "error") ? 10000 : 5000,
  230. offset: off,
  231. content: content
  232. });
  233. };
  234. MWF.getJSON("res/config/config.json", function (config) {
  235. if (config.proxyCenterEnable){
  236. if (o2.typeOf(config.center)==="array"){
  237. config.center.forEach(function(c){
  238. c.port = window.location.port || 80;
  239. });
  240. }else{
  241. config.port = window.location.port || 80;
  242. }
  243. }
  244. layout.config = config;
  245. MWF.xDesktop.getServiceAddress(layout.config, function (service, center) {
  246. layout.serviceAddressList = service;
  247. layout.centerServer = center;
  248. layout.load();
  249. }.bind(this));
  250. //layout.getServiceAddress(function(){
  251. // layout.load();
  252. //});
  253. });
  254. })();
  255. });
  256. });
  257. });