Main.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. MWF.xApplication.Profile.options.multitask = false;
  2. MWF.xApplication.Profile.Main = new Class({
  3. Extends: MWF.xApplication.Common.Main,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "name": "Profile",
  8. "icon": "icon.png",
  9. "width": "800",
  10. "height": "600",
  11. "isResize": false,
  12. "isMax": false,
  13. "mvcStyle": "style.css",
  14. "title": MWF.xApplication.Profile.LP.title
  15. },
  16. _loadCss: function(){},
  17. loadCss: function(file, callback){
  18. var path = (file && typeOf(file)==="string") ? file : "style.css";
  19. var cb = (file && typeOf(file)==="function") ? file : callback;
  20. var cssPath = this.path+this.options.style+"/"+path;
  21. this.content.loadCss(cssPath, cb);
  22. },
  23. onQueryLoad: function(){
  24. this.lp = MWF.xApplication.Profile.LP;
  25. this.action = MWF.Actions.get("x_organization_assemble_personal");
  26. },
  27. loadApplication: function(callback){
  28. this.action.getPerson(function(json){
  29. this.personData = json.data;
  30. this.personData.personIcon = this.action.getPersonIcon();
  31. this.content.loadHtml(this.path+this.options.style+"/view.html", {"bind": {"data": this.personData, "lp": this.lp}}, function(){
  32. this.loadContent()
  33. }.bind(this));
  34. }.bind(this));
  35. //this.loadCss();
  36. // this.loadTitle();
  37. // this.loadContent();
  38. if (callback) callback();
  39. },
  40. loadContent: function(){
  41. var pageConfigNodes = this.content.getElements(".o2_profile_configNode");
  42. this.contentNode = this.content.getElement(".o2_profile_contentNode");
  43. MWF.require("MWF.widget.Tab", function(){
  44. this.tab = new MWF.widget.Tab(this.contentNode, {"style": "profile"});
  45. this.tab.load();
  46. pageConfigNodes.each(function(node){
  47. this.tab.addTab(node, node.get("title"));
  48. }.bind(this));
  49. if (this.options.tab){
  50. this.tab.pages[this.options.tab].showIm();
  51. }else{
  52. this.tab.pages[0].showIm();
  53. }
  54. this.loadInforConfigActions();
  55. this.loadLayoutConfigActions();
  56. this.loadIdeaConfigActions();
  57. this.loadPasswordConfigActions();
  58. this.loadSSOConfigAction();
  59. }.bind(this));
  60. },
  61. loadInforConfigActions: function(){
  62. this.contentImgNode = this.content.getElement(".o2_profile_inforIconContentImg");
  63. this.content.getElement(".o2_profile_inforIconChange").addEvent("click", function(){
  64. this.changeIcon();
  65. }.bind(this));
  66. var inputs = this.tab.pages[0].contentNode.getElements("input");
  67. this.mailInputNode = inputs[0];
  68. this.mobileInputNode = inputs[1];
  69. this.officePhoneInputNode = inputs[2];
  70. this.weixinInputNode = inputs[3];
  71. this.qqInputNode = inputs[4];
  72. this.signatureInputNode = inputs[5];
  73. this.content.getElement(".o2_profile_saveInforAction").addEvent("click", function(){
  74. this.savePersonInfor();
  75. }.bind(this));
  76. },
  77. loadLayoutConfigActions: function(){
  78. var buttons = this.tab.pages[1].contentNode.getElements(".o2_profile_layoutClearDataAction");
  79. this.clearDataAction = buttons[0];
  80. this.defaultDataAction = (buttons.length>1) ? buttons[1]: null;
  81. this.clearDefaultDataAction = (buttons.length>2) ? buttons[2]: null;
  82. this.forceDataAction = (buttons.length>3) ? buttons[3]: null;
  83. this.deleteForceDataAction = (buttons.length>4) ? buttons[4]: null;
  84. this.clearDataAction.addEvent("click", function(){
  85. MWF.require("MWF.widget.UUID", function(){
  86. MWF.UD.deleteData("layout", function(){
  87. this.notice(this.lp.clearok, "success");
  88. this.desktop.notRecordStatus = true;
  89. }.bind(this));
  90. }.bind(this));
  91. }.bind(this));
  92. if( MWF.AC.isAdministrator() ){
  93. this.defaultDataAction.addEvent("click", function(){
  94. MWF.require("MWF.widget.UUID", function(){
  95. var text = this.lp.setDefaultOk;
  96. this.close();
  97. var status = layout.desktop.getLayoutStatusData();
  98. MWF.UD.putPublicData("defaultLayout", status, function(){
  99. MWF.xDesktop.notice("success", {"x": "right", "y": "top"}, text, layout.desktop.desktopNode);
  100. }.bind(this));
  101. }.bind(this));
  102. }.bind(this));
  103. this.clearDefaultDataAction.addEvent("click", function(){
  104. MWF.require("MWF.widget.UUID", function(){
  105. MWF.UD.deletePublicData("defaultLayout", function(){
  106. this.notice(this.lp.clearok, "success");
  107. this.desktop.notRecordStatus = true;
  108. }.bind(this));
  109. }.bind(this));
  110. }.bind(this));
  111. this.forceDataAction.addEvent("click", function(){
  112. MWF.require("MWF.widget.UUID", function(){
  113. var text = this.lp.setForceOk;
  114. this.close();
  115. var status = layout.desktop.getLayoutStatusData();
  116. MWF.UD.putPublicData("forceLayout", status, function(){
  117. MWF.xDesktop.notice("success", {"x": "right", "y": "top"}, text, layout.desktop.desktopNode);
  118. }.bind(this));
  119. }.bind(this));
  120. }.bind(this));
  121. this.deleteForceDataAction.addEvent("click", function(){
  122. MWF.require("MWF.widget.UUID", function(){
  123. MWF.UD.deletePublicData("forceLayout", function(){
  124. this.notice(this.lp.clearok, "success");
  125. this.desktop.notRecordStatus = true;
  126. }.bind(this));
  127. }.bind(this));
  128. }.bind(this));
  129. }
  130. var UINode = this.tab.pages[1].contentNode.getLast();
  131. this.loadDesktopBackground(UINode);
  132. },
  133. loadIdeaConfigActions: function(){
  134. this.ideasArea = this.tab.pages[2].contentNode.getElement("textarea");
  135. this.ideasSaveAction = this.ideasArea.getNext();
  136. this.ideasSaveDefaultAction = this.ideasSaveAction.getNext() || null;
  137. if (MWF.AC.isAdministrator()){
  138. this.ideasSaveDefaultAction.addEvent("click", function(){
  139. MWF.require("MWF.widget.UUID", function(){
  140. var data = {};
  141. data.ideas = this.ideasArea.get("value").split("\n");
  142. MWF.UD.putPublicData("idea", data, function(){
  143. this.notice(this.lp.ideaSaveOk, "success");
  144. }.bind(this));
  145. }.bind(this));
  146. }.bind(this))
  147. }
  148. MWF.require("MWF.widget.UUID", function(){
  149. MWF.UD.getDataJson("idea", function(json){
  150. if (json){
  151. if (json.ideas) this.ideasArea.set("value", json.ideas.join("\n"));
  152. }
  153. }.bind(this));
  154. }.bind(this));
  155. this.ideasSaveAction.addEvent("click", function(){
  156. MWF.require("MWF.widget.UUID", function(){
  157. var data = {};
  158. data.ideas = this.ideasArea.get("value").split("\n");
  159. MWF.UD.putData("idea", data, function(){
  160. this.notice(this.lp.ideaSaveOk, "success");
  161. }.bind(this));
  162. }.bind(this));
  163. }.bind(this))
  164. },
  165. loadPasswordConfigActions: function(){
  166. var inputs = this.tab.pages[3].contentNode.getElements("input");
  167. this.oldPasswordInputNode = inputs[0];
  168. this.passwordInputNode = inputs[1];
  169. this.morePasswordInputNode = inputs[2];
  170. this.savePasswordAction = this.tab.pages[3].contentNode.getElement(".o2_profile_savePasswordAction");
  171. this.oldPasswordInputNode.addEvents({
  172. "blur": function(){this.removeClass("o2_profile_inforContentInput_focus");},
  173. "focus": function(){this.addClass("o2_profile_inforContentInput_focus");}
  174. });
  175. this.passwordInputNode.addEvents({
  176. "blur": function(){this.removeClass("o2_profile_inforContentInput_focus");},
  177. "focus": function(){this.addClass("o2_profile_inforContentInput_focus");},
  178. "keyup" : function(){ this.checkPassowrdStrength( this.passwordInputNode.get("value") ) }.bind(this)
  179. });
  180. this.morePasswordInputNode.addEvents({
  181. "blur": function(){this.removeClass("o2_profile_inforContentInput_focus");},
  182. "focus": function(){this.addClass("o2_profile_inforContentInput_focus");}
  183. });
  184. this.savePasswordAction.addEvent("click", function(){
  185. this.changePassword();
  186. }.bind(this));
  187. },
  188. loadSSOConfigAction: function(){
  189. this.ssoConfigAreaNode = this.tab.pages[4].contentNode.getElement(".o2_profile_ssoConfigArea");
  190. MWF.Actions.get("x_organization_assemble_authentication").listOauthServer(function(json){
  191. json.data.each(function(d){
  192. var node = new Element("a", {
  193. "styles": {"font-size": "14px", "display": "block", "margin-bottom": "10px"},
  194. "text": d.displayName,
  195. "target": "_blank",
  196. "href": "/x_desktop/oauth.html?oauth="+encodeURIComponent(d.name)+"&redirect="+"&method=oauthBind"
  197. }).inject(this.ssoConfigAreaNode)
  198. }.bind(this));
  199. }.bind(this));
  200. },
  201. changeIcon: function(){
  202. var options = {};
  203. var width = "668";
  204. var height = "510";
  205. width = width.toInt();
  206. height = height.toInt();
  207. var size = this.content.getSize();
  208. var x = (size.x-width)/2;
  209. var y = (size.y-height)/2;
  210. if (x<0) x = 0;
  211. if (y<0) y = 0;
  212. if (layout.mobile){
  213. x = 20;
  214. y = 0;
  215. }
  216. var _self = this;
  217. MWF.require("MWF.xDesktop.Dialog", function() {
  218. MWF.require("MWF.widget.ImageClipper", function(){
  219. var dlg = new MWF.xDesktop.Dialog({
  220. "title": this.lp.changePersonIcon,
  221. "style": "image",
  222. "top": y,
  223. "left": x - 20,
  224. "fromTop": y,
  225. "fromLeft": x - 20,
  226. "width": width,
  227. "height": height,
  228. "html": "<div></div>",
  229. "maskNode": this.content,
  230. "container": this.content,
  231. "buttonList": [
  232. {
  233. "text": MWF.LP.process.button.ok,
  234. "action": function () {
  235. //_self.uploadPersonIcon();
  236. _self.image.uploadImage( function( json ){
  237. _self.action.getPerson(function(json){
  238. if (json.data){
  239. this.personData = json.data;
  240. _self.contentImgNode.set("src", _self.action.getPersonIcon());
  241. }
  242. this.close();
  243. }.bind(this));
  244. }.bind(this), null );
  245. }
  246. },
  247. {
  248. "text": MWF.LP.process.button.cancel,
  249. "action": function () {
  250. _self.image = null;
  251. this.close();
  252. }
  253. }
  254. ]
  255. });
  256. dlg.show();
  257. this.image = new MWF.widget.ImageClipper(dlg.content.getFirst(), {
  258. "aspectRatio": 1,
  259. "description" : "",
  260. "imageUrl" : this.action.getPersonIcon(),
  261. "resetEnable" : false,
  262. "data": null,
  263. "parameter": null,
  264. "action": this.action.action,
  265. "method": "changeIcon"
  266. });
  267. this.image.load();
  268. }.bind(this));
  269. }.bind(this))
  270. },
  271. uploadPersonIcon: function(){
  272. if (this.image){
  273. if( this.image.getResizedImage() ){
  274. this.action.changeIcon(function(){
  275. this.action.getPerson(function(json){
  276. if (json.data){
  277. this.personData = json.data;
  278. //if (this.personData.icon){
  279. this.contentImgNode.set("src", this.action.getPersonIcon());
  280. //}
  281. }
  282. }.bind(this))
  283. }.bind(this), null, this.image.getFormData(), this.image.resizedImage);
  284. }
  285. }
  286. },
  287. savePersonInfor: function(){
  288. this.personData.officePhone = this.officePhoneInputNode.get("value");
  289. this.personData.mail = this.mailInputNode.get("value");
  290. this.personData.mobile = this.mobileInputNode.get("value");
  291. this.personData.weixin = this.weixinInputNode.get("value");
  292. this.personData.qq = this.qqInputNode.get("value");
  293. this.personData.signature = this.signatureInputNode.get("value");
  294. this.action.updatePerson(this.personData, function(){
  295. this.notice(this.lp.saveInforOk, "success");
  296. }.bind(this));
  297. },
  298. loadDesktopBackground: function(UINode){
  299. var currentSrc = layout.desktop.options.style;
  300. MWF.UD.getDataJson("layoutDesktop", function(json){
  301. if (json) currentSrc = json.src;
  302. }.bind(this), false);
  303. MWF.getJSON(layout.desktop.path+"styles.json", function(json){
  304. json.each(function(style){
  305. var img = MWF.defaultPath+"/xDesktop/$Layout/"+style.style+"/preview.jpg";
  306. //var dskImg = MWF.defaultPath+"/xDesktop/$Layout/"+style.style+"/desktop.jpg";
  307. var imgArea = new Element("div.o2_profile_previewBackground").inject(UINode);
  308. if (currentSrc==style.style){
  309. imgArea.setStyles({"border": "4px solid #ffea00"});
  310. }
  311. new Element("img", {"src": img}).inject(imgArea);
  312. imgArea.store("dskimg", style.style);
  313. var _self = this;
  314. imgArea.addEvent("click", function(){ _self.selectDesktopImg(this, UINode); });
  315. }.bind(this));
  316. }.bind(this));
  317. },
  318. selectDesktopImg: function(item, UINode){
  319. var desktopImg = item.retrieve("dskimg");
  320. MWF.UD.putData("layoutDesktop", {"src": desktopImg}, function(){
  321. UINode.getChildren().each(function(node){
  322. node.setStyles({"border": "4px solid #eeeeee"});
  323. }.bind(this));
  324. item.setStyles({"border": "4px solid #ffea00"});
  325. var dskImg = MWF.defaultPath+"/xDesktop/$Layout/"+desktopImg+"/desktop.jpg";
  326. layout.desktop.node.setStyle("background-image", "url("+dskImg+")");
  327. }.bind(this));
  328. },
  329. changePassword: function(){
  330. var oldPassword = this.oldPasswordInputNode.get("value");
  331. var password = this.passwordInputNode.get("value");
  332. var morePassword = this.morePasswordInputNode.get("value");
  333. if (password!=morePassword){
  334. this.notice(this.lp.passwordNotMatch, "error");
  335. this.passwordInputNode.setStyles(this.css.inforContentInputNode_error);
  336. this.morePasswordInputNode.setStyles(this.css.inforContentInputNode_error);
  337. }else{
  338. this.action.changePassword(oldPassword, password, morePassword, function(){
  339. this.oldPasswordInputNode.set("value", "");
  340. this.passwordInputNode.set("value", "");
  341. this.morePasswordInputNode.set("value", "");
  342. this.notice(this.lp.changePasswordOk, "success");
  343. }.bind(this));
  344. if (layout.config.mail){
  345. var url = "http://"+layout.config.mail+"//names.nsf?changepassword&password="+encodeURIComponent(oldPassword)+"&passwordnew="+encodeURIComponent(password)+"&passwordconfirm="+encodeURIComponent(password);
  346. var iframe = new Element("iframe", {"styles": {"display": "none"}}).inject(this.desktop.desktopNode);
  347. iframe.set("src", url);
  348. window.setTimeout(function(){
  349. iframe.destroy();
  350. }.bind(this), 2000);
  351. }
  352. }
  353. },
  354. getAction: function(callback){
  355. if (!this.acrion){
  356. this.action = MWF.Actions.get("x_organization_assemble_personal");
  357. if (callback) callback();
  358. }else{
  359. if (callback) callback();
  360. }
  361. },
  362. createPasswordStrengthNode : function(){
  363. var passwordStrengthArea = this.passwordRemindContainer;
  364. var lowNode = new Element( "div", {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  365. this.lowColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( lowNode );
  366. this.lowTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.weak }).inject( lowNode );
  367. var middleNode = new Element( "div" , {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  368. this.middleColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( middleNode );
  369. this.middleTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.middle }).inject( middleNode );
  370. var highNode = new Element("div", {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  371. this.highColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( highNode );
  372. this.highTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.high }).inject( highNode );
  373. },
  374. getPasswordLevel: function( password, callback ){
  375. /*Level(级别)
  376. •0-3 : [easy]
  377. •4-6 : [midium]
  378. •7-9 : [strong]
  379. •10-12 : [very strong]
  380. •>12 : [extremely strong]
  381. */
  382. this.getAction( function( ){
  383. this.action.checkPassword( password, function( json ){
  384. if(callback)callback( json.data.value );
  385. }.bind(this), null, false );
  386. }.bind(this) );
  387. },
  388. checkPassowrdStrength: function(pwd){
  389. var passwordStrengthNode = this.tab.pages[3].contentNode.getElement(".o2_profile_passwordStrengthArea");
  390. var nodes = passwordStrengthNode.getElements(".o2_profile_passwordStrengthColor");
  391. var lowColorNode = nodes[0];
  392. var middleColorNode = nodes[1];
  393. var highColorNode = nodes[2];
  394. nodes = passwordStrengthNode.getElements(".o2_profile_passwordStrengthText");
  395. var lowTextNode = nodes[0];
  396. var middleTextNode = nodes[1];
  397. var highTextNode = nodes[2];
  398. lowColorNode.removeClass("o2_profile_passwordStrengthColor_low");
  399. middleColorNode.removeClass("o2_profile_passwordStrengthColor_middle");
  400. highColorNode.removeClass("o2_profile_passwordStrengthColor_high");
  401. lowTextNode.removeClass("o2_profile_passwordStrengthText_current");
  402. middleTextNode.removeClass("o2_profile_passwordStrengthText_current");
  403. highTextNode.removeClass("o2_profile_passwordStrengthText_current");
  404. if (pwd==null||pwd==''){
  405. }else{
  406. this.getPasswordLevel( pwd, function( level ){
  407. switch(level) {
  408. case 0:
  409. case 1:
  410. case 2:
  411. case 3:
  412. lowColorNode.addClass("o2_profile_passwordStrengthColor_low");
  413. lowTextNode.addClass("o2_profile_passwordStrengthText_current");
  414. break;
  415. case 4:
  416. case 5:
  417. case 6:
  418. middleColorNode.addClass("o2_profile_passwordStrengthColor_middle");
  419. middleTextNode.addClass("o2_profile_passwordStrengthText_current");
  420. break;
  421. default:
  422. highColorNode.addClass("o2_profile_passwordStrengthColor_high");
  423. highTextNode.addClass("o2_profile_passwordStrengthText_current");
  424. }
  425. }.bind(this) )
  426. }
  427. }
  428. });