Identity.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. o2.widget = o2.widget || {};
  2. o2.require("o2.widget.Common", null, false);
  3. o2.widget.Identity = new Class({
  4. Implements: [Options, Events],
  5. Extends: o2.widget.Common,
  6. options: {
  7. "style": "default"
  8. },
  9. initialize: function(data, container, explorer, canRemove, removeAction, options){
  10. this.setOptions(options);
  11. this.path = o2.session.path+"/widget/$Identity/";
  12. this.cssPath = o2.session.path+"/widget/$Identity/"+this.options.style+"/css.wcss";
  13. this._loadCss();
  14. this.container = $(container);
  15. this.data = data;
  16. this.style = this.css;
  17. this.explorer = explorer;
  18. this.canRemove = canRemove || false;
  19. this.removeAction = removeAction;
  20. this.load();
  21. },
  22. load: function(){
  23. this.node = new Element("div", {
  24. "styles": this.style.identityNode,
  25. "text": this.data.name
  26. }).inject(this.container);
  27. if (this.canRemove){
  28. this.removeNode = new Element("div", {
  29. "styles": this.style.identityRemoveNode
  30. }).inject(this.node);
  31. if (this.removeAction) this.removeNode.addEvent("click", this.removeAction.bind(this));
  32. // var pr = this.node.getStyle("padding-right").toFloat();
  33. // pr = pr+this.removeNode.getSize().x;
  34. // this.node.setStyle("padding-right", ""+pr+"px");
  35. }
  36. this.createInforNode(function(){
  37. this.fireEvent("loadedInfor");
  38. }.bind(this));
  39. this.node.addEvents({
  40. "mouseover": function(){
  41. this.node.setStyles(this.style.identityNode_over);
  42. // this.showPersonInfor();
  43. }.bind(this),
  44. "mouseout": function(){
  45. this.node.setStyles(this.style.identityNode);
  46. // this.hidePersonInfor();
  47. }.bind(this)
  48. });
  49. this.setEvent();
  50. },
  51. setEvent: function(){},
  52. getPerson: function(callback){
  53. var method = "getPersonByIdentity";
  54. var key = this.data.name;
  55. if (!this.explorer.actions.getPersonByIdentity){
  56. method = "getPerson";
  57. key = this.data.person;
  58. }
  59. this.explorer.actions[method](function(json){
  60. if (callback) callback(json);
  61. }, null, key);
  62. },
  63. createInforNode: function(callback){
  64. this.getPerson(function(person){
  65. if (person.data){
  66. this.inforNode = new Element("div", {
  67. "styles": this.style.identityInforNode
  68. });
  69. var nameNode = new Element("div", {
  70. "styles": this.style.identityInforNameNode
  71. }).inject(this.inforNode);
  72. if (person.data.icon){
  73. img = "<img width='50' height='50' border='0' src='data:image/png;base64,"+person.data.icon+"'></img>"
  74. }else{
  75. if (person.genderType=="f"){
  76. img = "<img width='50' height='50' border='0' src='"+"../x_component_Organization/$PersonExplorer/default/icon/female.png'></img>";
  77. }else{
  78. img = "<img width='50' height='50' border='0' src='"+"../x_component_Organization/$PersonExplorer/default/icon/man.png'></img>";
  79. }
  80. }
  81. var picNode = new Element("div", {
  82. "styles": this.style.identityInforPicNode,
  83. "html": img
  84. }).inject(nameNode);
  85. var nameTextNode = new Element("div", {
  86. "styles": this.style.identityInforNameTextNode,
  87. "text": person.data.display
  88. }).inject(nameNode);
  89. var phoneNode = new Element("div", {
  90. "styles": this.style.identityInforPhoneNode,
  91. "html": "<div style='width:30px; float:left'>"+this.explorer.app.lp.phone+": </div><div style='width:90px; float:left; margin-left:10px'>"+(person.data.mobile || "")+"</div>"
  92. }).inject(this.inforNode);
  93. var mailNode = new Element("div", {
  94. "styles": this.style.identityInforPhoneNode,
  95. "html": "<div style='width:30px; float:left'>"+this.explorer.app.lp.mail+": </div><div style='width:90px; float:left; margin-left:10px'>"+(person.data.mail || "")+"</div>"
  96. }).inject(this.inforNode);
  97. new mBox.Tooltip({
  98. content: this.inforNode,
  99. setStyles: {content: {padding: 15, lineHeight: 20}},
  100. attach: this.node,
  101. transition: 'flyin'
  102. });
  103. }
  104. if (callback) callback();
  105. }.bind(this));
  106. }
  107. });
  108. o2.widget.Person = new Class({
  109. Implements: [Options, Events],
  110. Extends: o2.widget.Identity,
  111. getPerson: function(callback){
  112. if (this.data.name && this.data.id){
  113. if (callback) callback({"data": this.data});
  114. }else{
  115. var key = this.data.name;
  116. this.explorer.actions["getPerson"](function(json){
  117. if (callback) callback(json);
  118. }, null, key);
  119. }
  120. }
  121. });
  122. o2.widget.Department = new Class({
  123. Implements: [Options, Events],
  124. Extends: o2.widget.Identity,
  125. createInforNode: function(){
  126. return true;
  127. }
  128. });
  129. o2.widget.Company = new Class({
  130. Extends: o2.widget.Department
  131. });
  132. o2.widget.Application = new Class({
  133. Extends: o2.widget.Department
  134. });
  135. o2.widget.Process = new Class({
  136. Extends: o2.widget.Department
  137. });
  138. o2.widget.FormField = new Class({
  139. Extends: o2.widget.Department
  140. });