Main.js 21 KB

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