o2.widget = o2.widget || {};
o2.require("o2.widget.Common", null, false);
o2.widget.Identity = new Class({
Implements: [Options, Events],
Extends: o2.widget.Common,
options: {
"style": "default"
},
initialize: function(data, container, explorer, canRemove, removeAction, options){
this.setOptions(options);
this.path = o2.session.path+"/widget/$Identity/";
this.cssPath = o2.session.path+"/widget/$Identity/"+this.options.style+"/css.wcss";
this._loadCss();
this.container = $(container);
this.data = data;
this.style = this.css;
this.explorer = explorer;
this.canRemove = canRemove || false;
this.removeAction = removeAction;
this.load();
},
load: function(){
this.node = new Element("div", {
"styles": this.style.identityNode,
"text": this.data.name
}).inject(this.container);
if (this.canRemove){
this.removeNode = new Element("div", {
"styles": this.style.identityRemoveNode
}).inject(this.node);
if (this.removeAction) this.removeNode.addEvent("click", this.removeAction.bind(this));
// var pr = this.node.getStyle("padding-right").toFloat();
// pr = pr+this.removeNode.getSize().x;
// this.node.setStyle("padding-right", ""+pr+"px");
}
this.createInforNode(function(){
this.fireEvent("loadedInfor");
}.bind(this));
this.node.addEvents({
"mouseover": function(){
this.node.setStyles(this.style.identityNode_over);
// this.showPersonInfor();
}.bind(this),
"mouseout": function(){
this.node.setStyles(this.style.identityNode);
// this.hidePersonInfor();
}.bind(this)
});
this.setEvent();
},
setEvent: function(){},
getPerson: function(callback){
var method = "getPersonByIdentity";
var key = this.data.name;
if (!this.explorer.actions.getPersonByIdentity){
method = "getPerson";
key = this.data.person;
}
this.explorer.actions[method](function(json){
if (callback) callback(json);
}, null, key);
},
createInforNode: function(callback){
this.getPerson(function(person){
if (person.data){
this.inforNode = new Element("div", {
"styles": this.style.identityInforNode
});
var nameNode = new Element("div", {
"styles": this.style.identityInforNameNode
}).inject(this.inforNode);
if (person.data.icon){
img = ""
}else{
if (person.genderType=="f"){
img = "
";
}else{
img = "
";
}
}
var picNode = new Element("div", {
"styles": this.style.identityInforPicNode,
"html": img
}).inject(nameNode);
var nameTextNode = new Element("div", {
"styles": this.style.identityInforNameTextNode,
"text": person.data.display
}).inject(nameNode);
var phoneNode = new Element("div", {
"styles": this.style.identityInforPhoneNode,
"html": "