123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- MWF.xApplication.process.FormDesigner.widget.FiledConfigurator = new Class({
- Implements: [Options, Events],
- Extends: MWF.widget.Common,
- options: {
- "style": "default",
- "title": "",
- "hasRefresh": false
- },
- initialize: function(node, designer, options, data){
- this.setOptions(options);
- this.node = $(node);
- this.app = designer;
- this.data = data || [];
- this.path = "../x_component_process_FormDesigner/widget/$FiledConfigurator/";
- this.cssPath = "../x_component_process_FormDesigner/widget/$FiledConfigurator/"+this.options.style+"/css.wcss";
- this._loadCss();
- },
- load: function(){
- this.loadTitle();
- this.loadContent();
- this.loadAddAction();
- },
- loadTitle: function(){
- this.titleNode = new Element("div",{
- "styles": this.css.titleNode,
- "text": this.options.title,
- }).inject(this.node);
- this.refreshNode = new Element("div",{
- "styles": this.css.refreshNode,
- "title": this.app.lp.filedConfigurator.importFromForm
- }).inject(this.titleNode);
- this.refreshNode.addEvent("click", function () {
- this.fireEvent("refresh")
- }.bind(this))
- },
- loadContent: function(){
- if(!this.contentNode)this.contentNode = new Element("div").inject(this.node);
- this.items = [];
- this.table = new Element("table").inject(this.contentNode);
- var tr = new Element("tr").inject(this.table);
- new Element("th", {"text": this.app.lp.filedConfigurator.sequence, "width":"10%"}).inject(tr);
- new Element("th", {"text": this.app.lp.filedConfigurator.fieldTitle, "width":"35%"}).inject(tr);
- new Element("th", {"text": this.app.lp.filedConfigurator.fieldId, "width":"35%"}).inject(tr);
- var td = new Element("th", {"text": this.app.lp.filedConfigurator.action, "width":"20%"}).inject(tr);
- // if( this.data.length === 0 ){
- // this.addItem()
- // }else{
- Array.each(this.data, function(obj, i){
- var item = new MWF.xApplication.process.FormDesigner.widget.FiledConfigurator.Item(this);
- item.load(obj, i);
- this.items.push(item);
- }.bind(this));
- // }
- },
- loadAddAction: function(){
- this.addNewItemAction = new Element("div", {"styles": this.css.addNewItemAction, "text": "+"}).inject(this.node);
- this.addNewItemAction.addEvent("click", function(){
- this.addItem();
- this.addNewItemAction.hide();
- }.bind(this));
- if(this.data.length > 0)this.addNewItemAction.hide();
- },
- reloadContent: function(){
- this.contentNode.empty();
- this.loadContent();
- if(this.data.length > 0){
- this.addNewItemAction.hide();
- }else{
- this.addNewItemAction.show();
- }
- },
- getData: function(){
- return this.data;
- },
- addItem: function(){
- var item = new MWF.xApplication.process.FormDesigner.widget.FiledConfigurator.Item(this);
- item.load("", this.items.length);
- this.items.push(item);
- this.fireEvent("change");
- },
- insertItem: function(beforeItem){
- var index = beforeItem.index+1;
- this.data.splice(index, 0, {"field": "", "title":""});
- this.reloadContent();
- this.fireEvent("change");
- // var item = new MWF.xApplication.process.FormDesigner.widget.FiledConfigurator.Item(this);
- // item.load("", beforeItem.index+1);
- // this.items.push(item);
- },
- deleteItem: function(item){
- this.items.erase(item);
- if (this.data[item.index]){
- this.data.splice(item.index, 1);
- }
- if (item.tr){
- item.tr.destroy();
- }
- this.setItemsSequence();
- if (this.data.length === 0){
- if (this.addNewItemAction) this.addNewItemAction.setStyle("display", "block");
- }
- this.fireEvent("change");
- },
- upItem: function(item){
- if( item.index === 0)return;
- var beforeData = this.data[item.index-1];
- this.data[item.index-1] = this.data[item.index];
- this.data[item.index] = beforeData;
- this.reloadContent();
- this.fireEvent("change");
- },
- setItemsSequence: function () {
- this.items.each(function (item, i) {
- item.index = i;
- item.sequenceNode.set("text", i+1)
- })
- }
- });
- MWF.xApplication.process.FormDesigner.widget.FiledConfigurator.Item = new Class({
- initialize: function(configurator){
- this.configurator = configurator;
- },
- load: function(data, i){
- this.index = i;
- if (!data){
- this.data = {"field": "", "title":""};
- this.configurator.data.push(this.data);
- }else{
- this.data = data;
- }
- this.create();
- },
- create: function () {
- var lp = this.configurator.app.lp.filedConfigurator;
- this.tr = new Element("tr").inject(this.configurator.table);
- var td;
- this.sequenceNode = new Element("td", {
- text : this.index+1,
- styles: this.configurator.css.sequenceNode,
- }).inject(this.tr);
- td = new Element("td").inject(this.tr);
- this.titleInput = new Element("input", {
- value: this.data.title,
- styles: this.configurator.css.inputNode,
- events: {
- blur: function (){
- this.data.title = this.titleInput.get("value");
- this.configurator.fireEvent("change");
- }.bind(this)
- }
- }).inject(td);
- td = new Element("td").inject(this.tr);
- this.fieldInput = new Element("input", {
- value: this.data.field,
- styles: this.configurator.css.inputNode,
- events: {
- blur: function (){
- this.data.field = this.fieldInput.get("value");
- this.configurator.fireEvent("change");
- }.bind(this)
- }
- }).inject(td);
- td = new Element("td").inject(this.tr);
- this.upAction = new Element("div", {
- text : "↑",
- "title": lp.moveup,
- styles: this.configurator.css.addAction,
- events: {
- click: function (ev) {
- this.up(ev)
- }.bind(this)
- }
- }).inject(td);
- this.delectAction = new Element("div", {
- text : "-",
- "title": lp.deleteRow,
- styles: this.configurator.css.delectAction,
- events: {
- click: function (ev) {
- this.delect(ev)
- }.bind(this)
- }
- }).inject(td);
- this.addAction = new Element("div", {
- text : "+",
- "title": lp.insertRow,
- styles: this.configurator.css.addAction,
- events: {
- click: function (ev) {
- this.add(ev)
- }.bind(this)
- }
- }).inject(td);
- },
- add: function(){
- this.configurator.insertItem(this)
- },
- delect: function () {
- this.configurator.deleteItem(this);
- },
- up: function () {
- this.configurator.upItem(this);
- }
- });
|