123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- MWF.xApplication.Org.List = new Class({
- Extends: MWF.widget.Common,
- Implements: [Options, Events],
- options: {
- "style": "default",
- "action": false,
- "canEdit": true,
- "data": {
- "name": "",
- "attributeList": [""]
- },
- "attr": [],
- "saveAction": "savePersonAttribute",
- "deleteAction": "removePersonAttribute",
- "deleteItemTitle": MWF.xApplication.Org.LP.deleteAttributeTitle,
- "deleteItemText": MWF.xApplication.Org.LP.deleteAttribute
- },
- _loadPath: function(){
- this.path = "../x_component_Org/$List/";
- this.cssPath = "../x_component_Org/$List/"+this.options.style+"/css.wcss";
- },
- initialize: function(node, content, options){
- this.setOptions(options);
- this._loadPath();
- this._loadCss();
- this.content = content;
- this.contentNode = $(node);
- this.items = [];
- this.selectedItems = [];
- },
- load: function(headers){
- this.headers = headers;
- //this.node = new Element("div", {"styles": this.css.node}).inject(this.contentNode);
- var html = "<table cellspacing='0' cellpadding='5' border='0' width='80%' align='center' style='line-height:normal; clear: both;'>";
- html += "<tr><th style='width:20px'></th>";
- headers.each(function(title){
- html += "<th style='"+title.style+"'>"+o2.txt(title.text)+"</th>";
- }.bind(this));
- html += "</table>";
- this.contentNode.set("html", html);
- this.loadAction();
- this.table = new HtmlTable(this.contentNode.getFirst("table"));
- this.contentNode.getElements("th").setStyles(this.css.listTitle);
- },
- // reLoad: function(){
- // var html = "<table cellspacing='0' cellpadding='5' border='0' width='80%' align='center' style='line-height:normal; clear: both;'>";
- // html += "<tr><th style='width:20px'></th>";
- // this.headers.each(function(title){
- // html += "<th style='"+title.style+"'>"+title.text+"</th>";
- // }.bind(this));
- // html += "</table>";
- // this.contentNode.set("html", html);
- //
- // this.table = new HtmlTable(this.contentNode.getFirst("table"));
- // this.contentNode.getElements("th").setStyles(this.css.listTitle);
- // },
- loadAction: function(){
- this.actionAreaNode = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.contentNode, "top");
- if (this.options.action){
- this.actionNode = new Element("div", {"styles": this.css.actionNode}).inject(this.actionAreaNode);
- this.deleteAction = new Element("div", {"styles": this.css.deleteActionNode_disabled, "text": this.content.explorer.app.lp.delete}).inject(this.actionNode);
- this.addAction = new Element("div", {"styles": this.css.addActionNode, "text": this.content.explorer.app.lp.add}).inject(this.actionNode);
- this.addAction.addEvent("click", function(){
- this.addItem();
- }.bind(this));
- this.deleteAction.addEvent("click", function(e){
- this.deleteItem(e);
- }.bind(this));
- this.fireEvent("postLoadAction")
- }
- },
- addItem: function(){
- var data = Object.clone(this.options.data);
- var tr = new MWF.xApplication.Org.List.Item(data, this.options.attr, this);
- this.items.push(tr);
- tr.edit(tr.tr.tds[1]);
- },
- deleteItem: function(e){
- if (this.selectedItems.length){
- this.fireEvent("queryDelete");
- var _self = this;
- this.content.explorer.app.confirm("infor", e, this.options.deleteItemTitle, this.options.deleteItemText, 350, 120, function(){
- this.close();
- var delCount = 0;
- var deleteCompleted = function(){
- if (delCount === _self.selectedItems.length){
- var continueDelete = true;
- _self.fireEvent("delete", continueDelete);
- if (continueDelete){
- while (_self.selectedItems.length){
- var tr = _self.selectedItems[0];
- tr.destroy();
- }
- }
- _self.fireEvent("postDelete", delCount);
- }
- };
- _self.selectedItems.each(function(item){
- item["delete"](function(){
- delCount++;
- deleteCompleted();
- });
- }.bind(this));
- }, function(){this.close();});
- }
- },
- push: function(data){
- // var rows = [""];
- // attr.each(function(n){
- // if (typeOf(n)==="function"){
- // rows.push(n.apply(data));
- // }else if(typeOf(n)==="string"){
- // rows.push(data[n]);
- // }else{
- // rows.push("");
- // }
- // }.bind(this));
- // var tr = this.table.push(rows, {"styles": this.css.contentTrNode});
- // tr.tds.each(function(td){td.setStyles(this.css.contentTdNode);}.bind(this));
- // tr.tds[0].setStyles(this.css.selectTdNode);
- var i = this.items.push(new MWF.xApplication.Org.List.Item(data, this.options.attr, this));
- return this.items[i-1];
- },
- setAction: function(){
- if (this.selectedItems.length){
- this.deleteAction.setStyles(this.css.deleteActionNode);
- }else{
- this.deleteAction.setStyles(this.css.deleteActionNode_disabled);
- }
- },
- clear: function(){
- this.items = [];
- this.selectedItems = [];
- var table = this.contentNode.getFirst("table");
- while (table.rows.length>1){
- table.rows[table.rows.length-1].destroy();
- }
- //this.reLoad();
- }
- });
- MWF.xApplication.Org.List.Item = new Class({
- initialize: function(data, attr, list){
- this.data = data;
- this.attr = attr;
- this.list = list;
- this.css = this.list.css;
- this.load();
- },
- reload: function(data){
- this.data = data;
- this.tr.tds.each(function(td, i){
- if (i===0) this.selectTd = td;
- if (i>0){
- var at = this.attr[i-1];
- if (typeOf(at)==="object"){
- if (at.get){
- td.set("text", at.get.apply(this.data));
- }else{
- td.set("text", "");
- }
- }else if(typeOf(at)==="string"){
- if (at==="icon"){
- td.set("html", "<div></div>");
- }else{
- var v = this.data[at];
- if (typeOf(v)==="array") v = v.join(",");
- td.set("text", o2.txt(v) );
- }
- }else{
- td.set("text", "");
- }
- if (at.events){
- if (at.events["init"]) at.events["init"].apply({"item": this, "data": this.data, "td": td, "item": this});
- }
- }
- td.setStyles(this.css.contentTdNode);
- td.set("title", td.get("text"));
- }.bind(this));
- },
- load: function(){
- var rows = [""];
- this.attr.each(function(n){
- if (typeOf(n)==="object"){
- if (n.get){
- var v = n.get.apply(this.data) || "";
- v = v.replace(/\</g, "<");
- v = v.replace(/\</g, ">");
- rows.push(v);
- }else if(n.getHtml){
- var v = n.getHtml.apply(this.data);
- rows.push(v);
- }else{
- rows.push("");
- }
- }else if(typeOf(n)==="string"){
- if (n==="icon"){
- rows.push("<div>cc</div>");
- }else{
- rows.push(typeOf(this.data[n])==='string' ? o2.txt(this.data[n]) : this.data[n]);
- }
- }else{
- rows.push("");
- }
- }.bind(this));
- this.tr = this.list.table.push(rows, {"styles": this.css.contentTrNode});
- this.tr.tr.store("data", this.data);
- var _self = this;
- this.tr.tds.each(function(td, i){
- td.setStyles(this.css.contentTdNode);
- td.set("title", td.get("text"));
- if (i===0) this.selectTd = td;
- if (i>0){
- if (this.list.options.action || this.list.options.canEdit){
- td.store("attr", this.attr[i-1]);
- if (this.list.options.canEdit){
- td.addEvent("click", function(){
- _self.edit(this);
- });
- }
- }
- var at = this.attr[i-1];
- if (at.events){
- td.removeEvents("click");
- Object.each(at.events, function(v, k){
- if (k.toLowerCase!=="init") td.addEvent(k, v.bind({"data": this.data, "td": td, "item": this}));
- }.bind(this));
- if (at.events["init"]) at.events["init"].apply({"item": this, "data": this.data, "td": td, "item": this});
- }
- }
- }.bind(this));
- if (this.list.options.action){
- this.selectTd.setStyles(this.css.selectTdNode);
- this.selectTd.addEvent("click", function(){
- if (!this.isSelected){
- this.selected();
- }else{
- this.unSelected();
- }
- }.bind(this));
- }else{
- this.selectTd.setStyles(this.css.blankTdNode);
- }
- },
- edit: function(td){
- var attr = td.retrieve("attr");
- var text = td.get("text");
- td.empty();
- var input = new Element("input", {"styles": this.css.inputNode, "value": text}).inject(td);
- td.removeEvents("click");
- var _self = this;
- input.focus();
- input.addEvents({
- "blur": function(){
- var value = this.get("value");
- if (value){
- if (typeOf(attr)==="object"){
- if (attr.set){
- attr.set.apply(_self.data, [value]);
- }
- }else if(typeOf(attr)==="string") {
- _self.data[attr] = value
- }
- }
- _self.editCompleted(td, value, text);
- }
- });
- },
- editCompleted: function(td, value, text){
- td.empty();
- if (!value && !text){
- if (td.cellIndex===1){
- this.destroy();
- }
- }else if (!value){
- if (td.cellIndex===1){
- td.set("text", text);
- }else{
- td.set("text", value);
- if (value!==text) this.save(td);
- }
- }else{
- td.set("text", value);
- if (value!==text) this.save(td);
- }
- var _self = this;
- if (this.list.options.canEdit){
- td.addEvent("click", function(){
- _self.edit(this);
- });
- }
- },
- "delete": function(callback){
- this.list.content.explorer.actions[this.list.options.deleteAction](this.data.id, function(){
- if (callback) callback();
- //this.destroy();
- }.bind(this));
- },
- destroy: function(){
- this.list.items.erase(this);
- if (this.isSelected) this.unSelected();
- this.list.setAction();
- this.tr.tr.destroy();
- MWF.release(this);
- },
- save: function(td){
- this.list.content.explorer.actions[this.list.options.saveAction](this.data, function(json){
- this.list.fireEvent("postSave", [this, json.data.id]);
- this.data.id = json.data.id;
- }.bind(this), function(xhr, text, error){
- td.set("text", "");
- this.edit(td);
- this.list.content.explorer.app.notice((JSON.decode(xhr.responseText).message.trim() || "request json error"), "error");
- }.bind(this));
- },
- selected: function(){
- this.selectTd.setStyles(this.css.selectTdNode_selected);
- this.tr.tr.setStyles(this.css.contentTrNode_selected);
- this.list.selectedItems.push(this);
- this.isSelected = true;
- this.list.setAction();
- },
- unSelected: function(){
- this.selectTd.setStyles(this.css.selectTdNode);
- this.tr.tr.setStyles(this.css.contentTrNode);
- this.list.selectedItems.erase(this);
- this.isSelected = false;
- this.list.setAction();
- }
- });
|