Current Path :
/
home
/
develito
/
www
/
administrator
/
components
/
com_raforms
/
js
/
Or
Select Your Path :
Upload File :
New :
File
Dir
//home/develito/www/administrator/components/com_raforms/js/raforms.js
var raHtmlTable = new Class({ Implements: [Options, Events, Class.Occlude], options: { properties: { cellpadding: 0, cellspacing: 0, border: 0 }, rows: [], headers: [], footers: [] }, property: 'raHtmlTable', initialize: function(){ var params = Array.link(arguments, {options: Type.isObject, table: Type.isElement, id: Type.isString}); this.setOptions(params.options); if (!params.table && params.id) params.table = document.id(params.id); this.element = params.table || new Element('table', this.options.properties); if (this.occlude()) return this.occluded; this.build(); }, build: function(){ this.element.store('raHtmlTable', this); this.body = document.id(this.element.tBodies[0]) || new Element('tbody').inject(this.element); $$(this.body.rows); if (this.options.headers.length) this.setHeaders(this.options.headers); else this.thead = document.id(this.element.tHead); if (this.thead) this.head = this.getHead(); if (this.options.footers.length) this.setFooters(this.options.footers); this.tfoot = document.id(this.element.tFoot); if (this.tfoot) this.foot = document.id(this.tfoot.rows[0]); this.options.rows.each(function(row){ this.push(row); }, this); }, toElement: function(){ return this.element; }, empty: function(){ this.body.empty(); return this; }, set: function(what, items){ var target = (what == 'headers') ? 'tHead' : 'tFoot', lower = target.toLowerCase(); this[lower] = (document.id(this.element[target]) || new Element(lower).inject(this.element, 'top')).empty(); var data = this.push(items, {}, this[lower], what == 'headers' ? 'th' : 'td'); if (what == 'headers') this.head = this.getHead(); else this.foot = this.getHead(); return data; }, getHead: function(){ var rows = this.thead.rows; return rows.length > 1 ? $$(rows) : rows.length ? document.id(rows[0]) : false; }, setHeaders: function(headers){ this.set('headers', headers); return this; }, setFooters: function(footers){ this.set('footers', footers); return this; }, update: function(tr, row, tag){ var tds = tr.getChildren(tag || 'td'), last = tds.length - 1; row.each(function(data, index){ var td = tds[index] || new Element(tag || 'td').inject(tr), content = ((data && data.hasOwnProperty('content')) ? data.content : '') || data, type = typeOf(content); if (data && data.hasOwnProperty('properties')) td.set(data.properties); if (/(element(s?)|array|collection)/.test(type)) td.empty().adopt(content); else td.set('html', content); if (index > last) tds.push(td); else tds[index] = td; }); return { tr: tr, tds: tds }; }, push: function(row, rowProperties, target, tag, where){ if (typeOf(row) == 'element' && row.get('tag') == 'tr'){ row.inject(target || this.body, where); return { tr: row, tds: row.getChildren('td') }; } return this.update(new Element('tr', rowProperties).inject(target || this.body, where), row, tag); }, pushMany: function(rows, rowProperties, target, tag, where){ return rows.map(function(row){ return this.push(row, rowProperties, target, tag, where); }, this); } }); ['adopt', 'inject', 'wraps', 'grab', 'replaces', 'dispose'].each(function(method){ raHtmlTable.implement(method, function(){ this.element[method].apply(this.element, arguments); return this; }); }); var raForms = new Class({ Implements: [Events, Options, Chain], options: { elementtype: null, page: 1, hidden: 0, fieldname: null, listview: -1, listfiltercontainer: -1, listfilter: -1, fx: [], isNew: true, isPlugin: false, posX: 0, posY: 0, sizX: null, sizY: null, label: '', labeldisplay: 1, label_width: 100, label_height: 20, labelposition: 'left', disabledelement: 0, filterHTML: true, elwidth: null, elheight: null, html: null, selopt: [], seloptsize: 1, seloptfromdb: false, seloptfromdbsql: null, seloptfromdbvalue: 'value', seloptfromdbtext: 'text', seloptfromdbpreselect: [], seloptempty: null, position: 1, hv: 1, multi: false, style: 'solid', cssclass: '', validation: [], editState: true, filterlabel: null, listviewlabel: null, listviewordering: null, listvieworderingdirection: null, listviewcrop: 0 }, // Initialize initialize: function(options) { this.setOptions(options); this.setup(); if (this.options.elementtype != null) { // Iterate global counter ++elementcounter; this.ec = elementcounter; this.properties = []; this.postEvents = []; // do the dirty work this.addElement(); // do not postprocess / add hiding for these elements this.postprocessing(); // fire all needed events this.fireAllEvents(); } }, setup: function() { this.hidden = this.options.hidden; return true; }, addDivElement: function(){ // Create a new <div> element for the master list this.divElement = new Element ('div', {'class': this.fieldname + ' divElement', 'id': 'div_el'+this.ec, 'style': 'position: absolute;'}); // store fieldname this.divElement.store('fieldname', this.fieldname); // insert form element label this.labelDiv = new Element('div', {'class': this.fieldname + ' labelDiv', 'id': 'el_'+this.ec+'_labelDiv', 'text': this.options.label}); this.labelDiv.setStyles({'clear': 'none', 'float': this.options.labelposition, 'text-align': this.options.labelposition}); this.labelDiv.makeResizable({ handle: '.labelDiv', grid: 5, onStart: function(el) { if (document.id('snapToGrid').checked) { this.options.grid.x = (document.id('gridSize').get('value') < 1) ? 1 : document.id('gridSize').get('value'); this.options.grid.y = (document.id('gridSize').get('value') < 1) ? 1 : document.id('gridSize').get('value'); } else { this.options.grid.x = 0; this.options.grid.y = 0; } }, onComplete: function(el) { var labelWidth = el.getSize().x; var labelHeight = el.getSize().y; if (labelWidth < 10) this.labelDiv.setStyle('width', '10px'); if (labelHeight < 10) this.labelDiv.setStyle('height', '10px'); var divWidth = el.getParent('div').getSize().x; // save label size this.labelwidth.set('value', labelWidth); this.labelheight.set('value', labelHeight); // global scope window.savePositions([this.divElement]); }.bind(this) }); this.labelDiv.setStyle('width', this.options.label_width); this.labelDiv.setStyle('height', this.options.label_height); this.elementDiv = new Element('div', {'class': this.fieldname, 'id': 'el_'+this.ec+'_elementDiv', 'class': 'elementDiv'}); this.elementDiv.setStyles({'clear': 'none', 'float': this.options.labelposition}); this.elementtypehidden = new Element('input', {'class': this.fieldname, 'type': 'hidden', 'name': 'data['+this.ec+'][elementtype]', 'value': this.options.elementtype}); this.elementtype.inject(this.elementDiv); this.elementtypehidden.inject(this.elementDiv); (this.labelDiv) ? this.labelDiv.inject(this.divElement) : true; this.elementDiv.inject(this.divElement); // mover to move the form element var invisible = (window.divMovers) ? ' ' : ' invisible '; var posDisplay = new Element('div', {'class': 'posDisplay'}); this.mover = new Element('div', {'class': 'mover' + invisible + this.fieldname}); posDisplay.inject(this.mover); this.mover.inject(this.divElement); // if loaded from database, insert elements in correct order if (!this.options.isNew) { this.divElement.inject(document.id('page-' + this.options.page)); this.divElement.setPosition({x: this.options.posX, y: this.options.posY}); } }, addHeading: function(){ var label = (this.options.listviewlabel == null || this.options.listviewlabel == this.options.label) ? this.options.label : this.options.listviewlabel + '\n(' + this.options.label + ')'; this.listviewhidden = new Element('input', {'class': this.fieldname, 'type': 'hidden', 'id': this.fieldname+'_order', 'name': 'data['+this.ec+'][listview]', 'value': this.options.listview}); this.listview = new Element('li', {'class': this.fieldname, 'id': this.fieldname+'_list'}); this.listviewlabelspan = new Element('span', {'class': this.fieldname, 'text': label, 'class': 'listviewlabel'}); this.listviewlabelspan.inject(this.listview); this.listviewhidden.inject(this.listview); if (this.options.listview == -1) { this.listview.inject(document.id('list-view-content')); } else { var list = $$('ul#list-view li input'); if (list.length > 0) { for (var index = 0; index < list.length; index++) { if (this.options.listview < list[index].get('value')) { this.listview.inject(document.id(list[index].get('id').replace('_order', '_list')), 'before'); break; } if (list[(index+1)] == undefined) { this.listview.inject(document.id('list-view')); break; } } } else { this.listview.inject(document.id('list-view')); } } }, addHeadingSortable: function(){ var listviewSortable = new Sortables('ul#list-view, ul#list-view-content',{ clone: true, opacity: 0.6, onComplete: function(el){ this.serialize().each(function(sortablearray){ sortablearray.each(function(value, index){ if (document.id(value).getParent().get('id') == 'list-view') { document.id(value.replace('_list','_order')).set('value', index); } else { document.id(value.replace('_list','_order')).set('value', -1); } }); }); } }); }, addFilter: function(){ var label = (this.options.filterlabel == null || this.options.filterlabel == this.options.label) ? this.options.label : this.options.filterlabel + '\n(' + this.options.label + ')'; this.listfiltercontainerhidden = new Element('input', {'class': this.fieldname, 'type': 'hidden', 'id': this.fieldname+'_filtercontainerorder', 'name': 'data['+this.ec+'][listfiltercontainer]', 'value': this.options.listfiltercontainer}); this.listfilterhidden = new Element('input', {'class': this.fieldname, 'type': 'hidden', 'id': this.fieldname+'_filterorder', 'name': 'data['+this.ec+'][listfilter]', 'value': this.options.listfilter, 'class': 'filterorder'}); this.listfilter = new Element('li', {'class': this.fieldname, 'id': this.fieldname+'_filterlist'}); this.listfilterlabel = new Element('span', {'class': this.fieldname, 'class': 'filterlabel', 'text': label}); this.listfilterlabel.inject(this.listfilter); this.listfilterhidden.inject(this.listfilter); this.listfiltercontainerhidden.inject(this.listfilter); if (this.options.listfilter == -1 || this.options.listfiltercontainer == 'content') { this.listfilter.inject(document.id('list-filter-content')); } else { var list = $$('ul#list-filter-'+this.options.listfiltercontainer+' li input.filterorder'); if (list.length > 0) { for (var index = 0; index < list.length; index++) { if (this.options.listfilter < list[index].get('value')) { this.listfilter.inject(document.id(list[index].get('id').replace('_filterorder', '_filterlist')), 'before'); break; } if (list[(index+1)] == undefined) { this.listfilter.inject(document.id('list-filter-'+this.options.listfiltercontainer)); break; } } } else { this.listfilter.inject(document.id('list-filter-'+this.options.listfiltercontainer)); } } document.listviewSortable.addItems(this.listfilter); }, addFilterSortable: function(){ // removed true; }, updateLabel: function(){ var label = this.label.get('value'); document.id('el_' + this.ec + '_labelDiv').set('text', label); this.options.label = label; if (this.hasHeading) { this.listviewlabel.fireEvent('keyup'); } if (this.filterlabel) { this.filterlabel.fireEvent('keyup'); } }, addPageProperties: function(page){ this.options.page = (this.options.page == null) ? 1 : this.options.page; //properties var label = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_PROP_PAGE'), 'class': 'proplabel'}); this.pagenumber = new Element('input', {'class': this.fieldname, 'id': 'el_'+this.ec+'_page', 'name': 'data['+this.ec+'][page]', 'size': 3, 'type': 'text', 'value': this.options.page, 'readonly': 'readonly'}); this.labelPropTable.push([{'content': label, 'properties': {'class': 'proplabelTd'}}, {'content': this.pagenumber, 'properties': {'class': 'propTd'}}]); }, addStdProperties: function(){ //properties this.labelwidth = new Element('input', {'class': this.fieldname, 'id': 'el_'+this.ec+'_label_width', 'name': 'data['+this.ec+'][label_width]', 'type': 'hidden', 'value': this.options.label_width.toInt()}); this.labelheight = new Element('input', {'class': this.fieldname, 'id': 'el_'+this.ec+'_label_height', 'name': 'data['+this.ec+'][label_height]', 'type': 'hidden', 'value': this.options.label_height.toInt()}); this.labellabel = new Element('span', {'class': this.fieldname, 'text': 'Label', 'class': 'proplabel'}); if (this.hasHeading) { this.addHeading(); } this.labelwidth.inject(this.labellabel); this.labelheight.inject(this.labellabel); this.label = new Element('input', {'class': this.fieldname, 'type': 'text', 'name': 'data['+this.ec+'][label]','size': '30', 'value': this.options.label}); this.label.addEvent('keyup', function() { this.updateLabel(); }.bind(this)); this.labelPropTable.push([{'content': this.labellabel, 'properties': {'class': 'proplabelTd'}}, {'content': this.label, 'properties': {'class': 'propTd'}}]); this.labelDisplayLabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_PROP_DISPLAY_LABEL'), 'class': 'proplabel'}); this.labelDisplay = new Element('select', {'class': this.fieldname, 'name': 'data[' + this.ec + '][labeldisplay]', 'size': '1'}).addEvent('change', function(){ var labelDisplay = this.labelDisplay.get('value').toInt(); if (document.id('el_' + this.ec + '_labelDiv')) { if (labelDisplay == 0) { document.id('el_' + this.ec + '_labelDiv').empty(); this.label.removeEvents('keyup'); this.options.labeldisplay = 0; } else { this.label.addEvent('keyup', function() { this.updateLabel(); }.bind(this)); this.label.fireEvent('keyup'); this.options.labeldisplay = 1; } } }.bind(this)); this.postEvents.push({'obj': 'this.labelDisplay', 'typ': 'change'}); var dispOption = new Element('option', {'class': this.fieldname, 'value': '1', 'text': Joomla.JText._('RAFORMS_PROP_YES')}); dispOption.selected = (this.options.labeldisplay == 1) ? true : false; dispOption.inject(this.labelDisplay); var dispOption = new Element('option', {'class': this.fieldname, 'value': '0', 'text': Joomla.JText._('RAFORMS_PROP_NO')}); dispOption.selected = (this.options.labeldisplay == 0) ? true : false; dispOption.inject(this.labelDisplay); this.labelPropTable.push([{'content': this.labelDisplayLabel, 'properties': {'class': 'proplabelTd'}}, {'content': this.labelDisplay, 'properties': {'class': 'propTd'}}]); this.labelPositionLabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_PROP_LABEL_POSITION'), 'class': 'proplabel'}); this.labelPosition = new Element('select', {'class': this.fieldname, 'name': 'data[' + this.ec + '][labelposition]', 'size': '1'}).addEvent('change', function(){ var labelPosition = this.labelPosition.get('value'); if (document.id('el_' + this.ec + '_labelDiv')) { var sav = document.id('el_' + this.ec + '_labelDiv'); if (labelPosition == 'top' || labelPosition == 'bottom') { sav.setStyles({'clear': 'both', 'float': 'left'}); sav.inject(document.id('div_el' + this.ec), labelPosition); document.id('el_' + this.ec + '_elementDiv').setStyles({'clear': 'both', 'float': 'left'}); } else if (labelPosition == 'left' || labelPosition == 'right') { sav.setStyles({'clear': 'none', 'float': labelPosition, 'text-align': labelPosition }); sav.inject(document.id('div_el' + this.ec), 'top'); var elementPosition = (labelPosition == 'left') ? 'right' : 'left'; document.id('el_' + this.ec + '_elementDiv').setStyles({'clear': 'none', 'float': labelPosition}); } this.options.labelposition = labelPosition; } }.bind(this)); (['left', 'right', 'top', 'bottom']).each(function(position) { var posOption = new Element('option', {'class': this.fieldname, 'value': position, 'text': ucfirst(position)}); posOption.selected = (this.options.labelposition == position) ? true : false; posOption.inject(this.labelPosition); }.bind(this)); this.labelPropTable.push([{'content': this.labelPositionLabel, 'properties': {'class': 'proplabelTd'}}, {'content': this.labelPosition, 'properties': {'class': 'propTd'}}]); this.disabledElementLabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_PROP_DISABLED'), 'class': 'proplabel'}); this.disabledElement = new Element('input', {'type': 'checkbox', 'value': 1, 'name': 'data[' + this.ec + '][disabledelement]'}).addEvent('change', function() { this.elementtype.disabled = (this.disabledElement.checked); }.bind(this)); this.disabledElement.checked = (this.options.disabledelement == 1) ? true : false; this.extraPropTable.push([{'content': this.disabledElementLabel, 'properties': {'class': 'proplabelTd'}}, {'content': this.disabledElement, 'properties': {'class': 'propTd'}}]); this.postEvents.push({'obj': 'this.disabledElement', 'typ': 'change'}); }, addListviewProperties: function(){ this.listviewlabellabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_PROP_LIST_LABEL'), 'class': 'proplabel'}); this.listviewlabel = new Element('input', {'class': this.fieldname, 'type': 'text', 'name': 'data['+this.ec+'][listviewlabel]', 'value': this.options.listviewlabel}).addEvent( 'keyup', function(){ var label = (this.listviewlabel.get('value') == '' || this.listviewlabel.get('value') == this.label.get('value')) ? this.label.get('value') : this.listviewlabel.get('value') + '\n (' + this.label.get('value') + ')'; $$('#'+this.fieldname+'_list span.listviewlabel').set('text', label); this.options.listviewlabel = label; }.bind(this)); this.listviewproperties.push([this.listviewlabellabel,this.listviewlabel]); this.listvieworderinglabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_PROP_LIST_ORDER_BY_THIS_COLUMN'), 'class': 'proplabel'}); this.listviewordering = new Element('input', {'class': this.fieldname, 'type': 'checkbox', 'name': 'data['+this.ec+'][listviewordering]', 'value': 'true', 'class': 'listviewordering'}).addEvent( 'click', function() { $$('.listviewordering').each(function(el) { if (el != this.listviewordering) { el.checked = false; } }.bind(this)); this.options.listviewordering = this.listviewordering.get('value'); }.bind(this)); (this.options.listviewordering) ? this.listviewordering.checked = true : this.listviewordering.checked = false; this.listviewproperties.push([this.listvieworderinglabel, this.listviewordering]); this.listvieworderingdirectionlabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_PROP_LIST_ORDERING_DIRECTION'), 'class': 'proplabel'}); this.listvieworderingdirection = new Element('select', {'class': this.fieldname, 'name': 'data['+this.ec+'][listvieworderingdirection]', 'size': '1'}); (['ASC', 'DESC']).each(function(direction) { var directionoption = new Element('option', {'class': this.fieldname, 'value': direction, 'text': ucfirst(direction)}); if (this.options.listvieworderingdirection == direction) { directionoption.set('selected', 'selected'); } directionoption.inject(this.listvieworderingdirection); }.bind(this)); this.listviewproperties.push([this.listvieworderingdirectionlabel, this.listvieworderingdirection]); this.listviewcroplabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_PROP_LIST_LIMIT_CHARS'), 'class': 'proplabel'}); this.listviewcrop = new Element('input', {'class': this.fieldname, 'type': 'text', 'name': 'data['+this.ec+'][listviewcrop]', 'size': '10', 'value': this.options.listviewcrop}); this.listviewproperties.push([this.listviewcroplabel, this.listviewcrop]); }, addCSSProperties: function(){ //properties this.cssclasslabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_PROP_CSS_CLASS'), 'class': 'proplabel'}); this.cssclass = new Element('input', {'class': this.fieldname, 'type': 'text', 'name': 'data['+this.ec+'][cssclass]', 'size': '30', 'value': this.options.cssclass}).addEvent( 'keyup', function(){ document.id('el_' + this.ec + '_labelDiv').set('class', this.cssclass.get('value')) this.options.cssclass = this.cssclass.get('value'); }.bind(this)); this.extraPropTable.push([{'content': this.cssclasslabel, 'properties': {'class': 'proplabelTd'}}, {'content': this.cssclass, 'properties': {'class': 'propTd'}}]); }, addFieldname: function(){ this.options.fieldname = (this.options.fieldname == null) ? this.options.elementtype+'_field'+this.ec : this.options.fieldname; this.fieldname = this.options.fieldname; if (this.options.isNew) { this.options.label = this.fieldname; } this.labelPropTable = new raHtmlTable({ 'properties': { 'id': this.fieldname + '-labelProperties', 'border': '0', 'cellspacing': '3', 'class': 'propeditformtable' }}); this.dataPropTable = new raHtmlTable({ 'properties': { 'id': this.fieldname + '-dataProperties', 'border': '0', 'cellspacing': '3', 'class': 'propeditformtable' }}); this.validationPropTable = new raHtmlTable({ 'properties': { 'id': this.fieldname + '-validationProperties', 'border': '0', 'cellspacing': '3', 'class': 'propeditformtable' }}); this.fxPropTable = new raHtmlTable({ 'properties': { 'id': this.fieldname + '-fxProperties', 'border': '0', 'cellspacing': '3', 'class': 'propeditformtable' }}); this.extraPropTable = new raHtmlTable({ 'properties': { 'id': this.fieldname + '-extraProperties', 'border': '0', 'cellspacing': '3', 'class': 'propeditformtable' }}); this.fieldnamehidden = new Element('input', {'class': this.fieldname, 'type': 'hidden', 'name': 'data['+this.ec+'][fieldname]', 'value': this.fieldname}); this.labelPropTable.push([{'content': 'Fieldname', 'properties': {'class': 'proplabelTd'}}, {'content': this.fieldnamehidden, 'properties': {'class': 'propTd'}}], {'class': 'invisible'}); if (this.options.isPlugin == true) { var isPlugin = new Element('input', {'class': this.fieldname, 'type': 'hidden', 'name': 'data['+this.ec+'][isPlugin]', 'value': true}); this.dataPropTable.push([{'content': 'isPlugin', 'properties': {'class': 'proplabelTd'}}, {'content': isPlugin, 'properties': {'class': 'propTd'}}], {'class': 'invisible'}); } }, addExtProperties: function() { this.requiredlabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_PROP_CHECK_IF_EMPTY'), 'class': 'proplabel'}); this.required = new Element('input', {'class': this.fieldname, 'type': 'checkbox', 'name': 'data['+this.ec+'][validation][]', 'value': 'required'}); (this.options.validation.contains('required')) ? this.required.checked = true : this.required.checked = false; this.validationPropTable.push([{'content': this.requiredlabel, 'properties': {'class': 'proplabelTd'}}, {'content': this.required, 'properties': {'class': 'propTd'}}]); }, editProperties: function() { if (!document.id(this.fieldname + '_editProperties')) { this.editProvertiesDiv = document.id('editPropertiesTemplate').clone(); this.editProvertiesDiv.set('id', this.fieldname + '_editProperties'); this.editProvertiesDiv.addClass(this.fieldname); this.editProvertiesDiv.getElement('.editPropertiesCaption').set('text', Joomla.JText._('RAFORMS_PROP_PROPERTIES') + ': ' + this.options.label); if (document.id(this.fieldname + '-labelProperties').getChildren('tbody tr').length > 0) { new TabSet({tabs: this.editProvertiesDiv.getElements('li.tab'), contents: this.editProvertiesDiv.getElements('li.content'), saveToCookie: false}); this.editProvertiesDiv.getElement('li.labelPropertiesTab').removeClass('invisible'); this.editProvertiesDiv.getElement('li.labelPropertiesContent').removeClass('invisible'); this.editProvertiesDiv.getElement('li.labelPropertiesContent').adopt(document.id(this.fieldname + '-labelProperties')); } if (document.id(this.fieldname + '-dataProperties').getChildren('tbody tr').length > 0) { new TabSet({tabs: this.editProvertiesDiv.getElements('li.tab'), contents: this.editProvertiesDiv.getElements('li.content'), saveToCookie: false}); this.editProvertiesDiv.getElement('li.dataPropertiesTab').removeClass('invisible'); this.editProvertiesDiv.getElement('li.dataPropertiesContent').removeClass('invisible'); this.editProvertiesDiv.getElement('li.dataPropertiesContent').adopt(document.id(this.fieldname + '-dataProperties')); } if (document.id(this.fieldname + '-validationProperties').getChildren('tbody tr').length > 0) { new TabSet({tabs: this.editProvertiesDiv.getElements('li.tab'), contents: this.editProvertiesDiv.getElements('li.content'), saveToCookie: false}); this.editProvertiesDiv.getElement('li.validationPropertiesTab').removeClass('invisible'); this.editProvertiesDiv.getElement('li.validationPropertiesContent').removeClass('invisible'); this.editProvertiesDiv.getElement('li.validationPropertiesContent').adopt(document.id(this.fieldname + '-validationProperties')); } if (document.id(this.fieldname + '-fxProperties').getChildren('tbody tr').length > 0) { this.editProvertiesDiv.getElement('li.fxPropertiesTab').removeClass('invisible'); this.editProvertiesDiv.getElement('li.fxPropertiesContent').removeClass('invisible'); this.editProvertiesDiv.getElement('li.fxPropertiesContent').adopt(document.id(this.fieldname + '-fxProperties')); } if (document.id(this.fieldname + '-extraProperties').getChildren('tbody tr').length > 0) { new TabSet({tabs: this.editProvertiesDiv.getElements('li.tab'), contents: this.editProvertiesDiv.getElements('li.content'), saveToCookie: false}); this.editProvertiesDiv.getElement('li.extraPropertiesTab').removeClass('invisible'); this.editProvertiesDiv.getElement('li.extraPropertiesContent').removeClass('invisible'); this.editProvertiesDiv.getElement('li.extraPropertiesContent').adopt(document.id(this.fieldname + '-extraProperties')); } this.editProvertiesDiv.setStyles({'top': (this.divElement.getPosition().y - 150) + 'px', 'left': (this.divElement.getPosition().x + this.divElement.getDimensions().x + 50) + 'px'}); this.editProvertiesDiv.removeClass('invisible'); this.editProvertiesDiv.inject('formEditor', 'top'); if ( this.options.elementtype == 'html' ) { tinyMCE.execCommand('mceAddEditor', false, 'el' + this.ec + '_editor'); } this.editProvertiesDiv.makeDraggable({ container: document.id('adminForm').getParent(), handle: this.editProvertiesDiv.getElement('.editPropertiesHead') }); this.editProvertiesDiv.getElement('.editPropertiesClose').addEvent('click', function() { if ( this.options.elementtype == 'html' ) { document.id('el' + this.ec).set('html', tinyMCE.get('el' + this.ec + '_editor').getContent()); tinyMCE.execCommand('mceRemoveEditor', true, 'el' + this.ec + '_editor'); } document.id(this.fieldname + '-labelProperties').inject(document.id(this.fieldname + '_element-properties-div')); document.id(this.fieldname + '-dataProperties').inject(document.id(this.fieldname + '_element-properties-div')); document.id(this.fieldname + '-validationProperties').inject(document.id(this.fieldname + '_element-properties-div')); document.id(this.fieldname + '-fxProperties').inject(document.id(this.fieldname + '_element-properties-div')); document.id(this.fieldname + '-extraProperties').inject(document.id(this.fieldname + '_element-properties-div')); window.savePositions([this.divElement]); this.editProvertiesDiv.destroy(); }.bind(this)); } }, copyElement: function() { var optionsCopy = {}; var fieldname = this.fieldname.replace(/[0-9]*$/, '') + (window.elementcounter + 1); Object.each(this.options, function (item, index) { optionsCopy[index] = item; }.bind(this)); optionsCopy.fieldname = fieldname; optionsCopy.isNew = false; var countNames = 0; $$('.labelDiv').each( function (el) { var elName = el.get('text'); var cpName = optionsCopy.label; if (elName == optionsCopy.label || elName.match(cpName + '*')) countNames++; }.bind(this)); optionsCopy.label = optionsCopy.label.replace(/ \([0-9]*\)$/, '') + ' (' + countNames + ')'; // reset some options optionsCopy.listfilter = -1; optionsCopy.listfiltercontainer = -1; if ( optionsCopy.listviewlabel != null) { optionsCopy.listviewlabel = optionsCopy.listviewlabel.replace(/ \([0-9]*\)$/, '') + ' (' + countNames + ')'; } if ( optionsCopy.filterlabel != null) { optionsCopy.filterlabel = optionsCopy.filterlabel.replace(/ \([0-9]*\)$/, '') + ' (' + countNames + ')'; } // add offset to the copy optionsCopy.posX = optionsCopy.posX + 50; optionsCopy.posY = optionsCopy.posY + 50; if (this.options.isPlugin == true) { var pluginClassName = 'Add' + ucfirst(this.options.elementtype); window.formElements[fieldname] = new window[pluginClassName](optionsCopy); } else { var className = 'raForms' + ucfirst(this.options.elementtype); window.formElements[fieldname] = new window[className](optionsCopy); } // add copy to RectangleSelection listener window.getRectangleSelection(); // add copy to ContextMenu listener window.addContextMenu.addItems(formElements[fieldname].divElement); //window.formElements[fieldname].divElement.inject(document.id('raforms-form-' + this.options.posUl)); window.formElements[fieldname].divElement.inject(document.id('div_el' + this.ec), 'after'); window.addContextMenu.addItems(window.formElements[fieldname].divElement); window.savePositions([window.formElements[fieldname].divElement]); }, hideElement: function(showOrHide) { if (showOrHide == null) { showOrHide = (this.hidden == 0) ? 1 : 0; } this.divElement.getChildren().each(function(el) { if (showOrHide == 1) { if (!el.hasClass('edit')) { el.setStyle('opacity', .30); } } else { el.setStyle('opacity', 1); } }.bind(this)); if (showOrHide == 1) { (typeof(this.listview) != 'undefined') ? this.listview.setStyle('opacity', .30) : true; (typeof(this.filterlabel) != 'undefined') ? this.filterlabel.setStyle('opacity', .30) : true; (typeof(this.listfilter) != 'undefined') ? this.listfilter.setStyle('opacity', .30) : true; (typeof(this.listfiltercontainer) != 'undefined') ? this.listfiltercontainer.setStyle('opacity', .30) : true; (typeof(this.listviewlabel) != 'undefined') ? this.listviewlabel.setStyle('opacity', .30) : true; } else { (typeof(this.listview) != 'undefined') ? this.listview.setStyle('opacity', 1) : true; (typeof(this.filterlabel) != 'undefined') ? this.filterlabel.setStyle('opacity', 1) : true; (typeof(this.listfilter) != 'undefined') ? this.listfilter.setStyle('opacity', 1) : true; (typeof(this.listfiltercontainer) != 'undefined') ? this.listfiltercontainer.setStyle('opacity', 1) : true; (typeof(this.listviewlabel) != 'undefined') ? this.listviewlabel.setStyle('opacity', 1) : true; } this.hiddenInput.set('value', showOrHide); this.hidden = showOrHide; }, addPropertiesTable: function() { // div for editing this.editDiv = new Element ('div', {'class': this.fieldname }); this.propertiesDiv = new Element('div', {'class': this.fieldname, 'name': this.fieldname+'_element-properties-div', 'id': this.fieldname+'_element-properties-div'}); // first, add DIV for deleting / hiding the element this.editDiv.inject(this.propertiesDiv); if (this.properties) { if (this.labelPropTable) { this.labelPropTable.inject(this.propertiesDiv); } if (this.dataPropTable) { this.dataPropTable.inject(this.propertiesDiv); } if (this.validationPropTable) { this.validationPropTable.inject(this.propertiesDiv); } if (this.fxPropTable) { this.fxPropTable.inject(this.propertiesDiv); } if (this.extraPropTable) { this.extraPropTable.inject(this.propertiesDiv); } } else { new Element('h2', {'class': this.fieldname, text: Joomla.JText._('RAFORMS_PROP_NO_PROPERTIES')}).inject(this.propertiesDiv); } this.propertiesDiv.inject(document.id('element-properties-div')); }, addFilterTable: function(){ // Standard Filter Properties (this.options.filterlabel != this.options.label) ? $$('#'+this.fieldname+'_list span.filterlabel').set('html', this.options.filterlabel+'<br/>'+'('+this.options.label+')') : true; this.filterlabellabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_PROP_FILTER_LABEL'), 'class': 'proplabel'}); this.filterlabel = new Element('input', {'class': this.fieldname, 'type': 'text', 'name': 'data['+this.ec+'][filterlabel]', 'value': this.options.filterlabel}).addEvent( 'keyup', function(){ if (this.filterlabel.get('value') != this.label.get('value')) { if (this.filterlabel.get('value') != '') { $$('#'+this.fieldname+'_filterlist span.filterlabel').set('html', this.filterlabel.get('value')+'<br/>'+'('+this.label.get('value')+')'); } else { $$('#'+this.fieldname+'_filterlist span.filterlabel').set('html', this.label.get('value')); } this.options.filterlabel = this.filterlabel.get('value'); } else { $$('#'+this.fieldname+'_filterlist span.filterlabel').set('html', this.filterlabel.get('value')); this.options.filterlabel = this.label.get('value'); } }.bind(this)); this.filterproperties.push([this.filterlabellabel,this.filterlabel]); this.filterdiv = new Element('div', {'class': this.fieldname, 'name': this.fieldname+'_filterpropertiesdiv', 'id': this.fieldname+'_filterpropertiesdiv'}); if (this.filterproperties) { this.filterproptable = new raHtmlTable({ 'properties': { 'border': '0', 'cellspacing': '3', 'class': 'propeditformtable' }}); this.filterproperties.each(function(value, key){ this.filterproptable.push(value); }.bind(this)); this.filterproptable.inject(this.filterdiv); } else { new Element('h2', {'class': this.fieldname, text: Joomla.JText._('RAFORMS_FILTER_NO_PROPERTIES')}).inject(this.filterdiv); } this.filterdiv.inject(document.id('filterpropertiesdiv')); this.listfilter.addEvent('contextmenu', function(event) { event.preventDefault(); if (!document.id(this.fieldname + '_editFilterProperties')) { var editFilterPropertiesDiv = document.id('editListFilterPropertiesTemplate').clone(); editFilterPropertiesDiv.set('id', this.fieldname + '_editFilterProperties'); editFilterPropertiesDiv.addClass(this.fieldname); editFilterPropertiesDiv.getElement('.editPropertiesCaption').appendText(Joomla.JText._('RAFORMS_FILTER_PROPERTIES') + ': ' + this.options.label); editFilterPropertiesDiv.setStyles({'top': this.listfilter.getPosition().y + 'px', 'left': this.listfilter.getPosition().x + this.listfilter.getDimensions().x + 'px'}); if (document.id(this.fieldname + '-labelProperties').getChildren('tbody tr').length > 0) { editFilterPropertiesDiv.getElement('.editPropertiesContent').removeClass('invisible'); editFilterPropertiesDiv.getElement('.editPropertiesContent').adopt(document.id(this.fieldname + '_filterpropertiesdiv')); } editFilterPropertiesDiv.removeClass('invisible'); editFilterPropertiesDiv.inject('listViewEditor', 'top'); editFilterPropertiesDiv.makeDraggable({ container: document.id('adminForm').getParent(), handle: editFilterPropertiesDiv.getElement('.editPropertiesHead') }); editFilterPropertiesDiv.getElement('.editPropertiesClose').addEvent('click', function() { document.id(this.fieldname+'_filterpropertiesdiv').inject(document.id('filterpropertiesdiv')); editFilterPropertiesDiv.destroy(); }.bind(this)); } }.bind(this)); }, addListviewTable: function(){ // Standard Listview Properties this.addListviewProperties(); this.listviewdiv = new Element('div', {'class': this.fieldname, 'id': this.fieldname+'_listviewpropertiesdiv'}); if (this.listviewproperties) { this.listviewproptable = new raHtmlTable({ 'properties': { 'border': '0', 'cellspacing': '3', 'class': 'propeditformtable' }}); this.listviewproperties.each(function(value, key){ this.listviewproptable.push(value); }.bind(this)); this.listviewproptable.inject(this.listviewdiv); } else { new Element('h2', {'class': this.fieldname, text: Joomla.JText._('RAFORMS_PROP_NO_PROPERTIES')}).inject(this.listviewdiv); } this.listviewdiv.inject(document.id('listviewpropertiesdiv')); this.listview.addEvent('contextmenu', function(event) { event.preventDefault(); if (!document.id(this.fieldname + '_editListviewProperties')) { var editListViewPropertiesDiv = document.id('editListFilterPropertiesTemplate').clone(); editListViewPropertiesDiv.set('id', this.fieldname + '_editListviewProperties'); editListViewPropertiesDiv.addClass(this.fieldname); editListViewPropertiesDiv.getElement('.editPropertiesCaption').set('text', Joomla.JText._('RAFORMS_LIST_CAPTION_PROPERTIES') + ': ' + this.options.label); editListViewPropertiesDiv.setStyles({'top': this.listview.getPosition().y + 'px', 'left': this.listview.getPosition().x + this.listview.getDimensions().x + 'px'}); if (document.id(this.fieldname + '-labelProperties').getChildren('tbody tr').length > 0) { editListViewPropertiesDiv.getElement('.editPropertiesContent').removeClass('invisible'); editListViewPropertiesDiv.getElement('.editPropertiesContent').adopt(document.id(this.fieldname + '_listviewpropertiesdiv')); } editListViewPropertiesDiv.removeClass('invisible'); editListViewPropertiesDiv.inject('listViewEditor', 'top'); editListViewPropertiesDiv.makeDraggable({ container: document.id('adminForm').getParent(), handle: editListViewPropertiesDiv.getElement('.editPropertiesHead') }); editListViewPropertiesDiv.getElement('.editPropertiesClose').addEvent('click', function() { document.id(this.fieldname+'_listviewpropertiesdiv').inject(document.id('listviewpropertiesdiv')); editListViewPropertiesDiv.destroy(); }.bind(this)); } }.bind(this)); }, addEffects: function(id, val) { id = (id == null) ? '' : '_' + id var elid = this.fieldname + id; if ((val == null || val == '') && document.id(elid + '_fx_row')) { document.id(elid + '_fx_row').destroy(); } else { // for memorizing effects while editing this.fx[elid] = (!this.fx[elid]) ? {} : this.fx[elid]; this.fx[elid].label = new Element('span', {'id': elid + '_fx_option-label', 'class': this.fieldname, 'text': val, 'class': 'proplabel'}); this.fx[elid].effect = new Element('select', {'class': this.fieldname, 'name': 'data['+this.ec+'][fx][' + elid + ']', 'size': '1'}); new Element('option', {'class': this.fieldname, 'value': '', 'text': Joomla.JText._('RAFORMS_FX_NONE')}).inject(this.fx[elid].effect); new Element('option', {'class': this.fieldname, 'value': 'background-color', 'text': Joomla.JText._('RAFORMS_FX_BACKGROUND_COLOR')}).inject(this.fx[elid].effect); new Element('option', {'class': this.fieldname, 'value': 'css', 'text': Joomla.JText._('RAFORMS_FX_CSS_STYLES')}).inject(this.fx[elid].effect); this.fx[elid].effect.value = (this.fxOptions[elid]) ? this.fxOptions[elid].effect : null; this.fx[elid].effect.addEvent('change', function() { if (this.fx[elid].effect.get('value') == '') { this.fx[elid].setting = new Element('div', {'class': this.fieldname, 'id': elid + '_fx_setting'}); (document.id(elid + '_fx_setting')) ? this.fx[elid].setting.replaces(document.id(elid + '_fx_setting')) : true; this.fx[elid].applyto = new Element('div', {'class': this.fieldname, 'id': elid + '_fx_applyto'}); (document.id(elid + '_fx_applyto')) ? this.fx[elid].applyto.replaces(document.id(elid + '_fx_applyto')) : true; } else { if (this.fx[elid].effect.get('value') == 'css') { this.fx[elid].setting = new Element('textarea', {'class': this.fieldname, 'id': elid + '_fx_setting', 'name': 'data['+this.ec+'][fx][' + elid + '][fxtype][css]', 'rows': '10', 'cols': '25'}); this.fx[elid].setting.value = (this.fxOptions[elid] && this.fxOptions[elid].setting) ? this.fxOptions[elid].setting : null; (document.id(elid + '_fx_setting')) ? this.fx[elid].setting.replaces(document.id(elid + '_fx_setting')) : true; } if (this.fx[elid].effect.get('value') == 'background-color') { this.fx[elid].setting = new Element('select', {'class': this.fieldname, 'id': elid + '_fx_setting', 'name': 'data['+this.ec+'][fx][' + elid + '][fxtype][background-color]', 'size': '1'}); ['#FF0000', '#FFFF00', '#00FF00', '#00FFFF', '#0000FF', 'transparent'].each( function(col) { new Element('option', {'class': this.fieldname, 'value': col, 'style': 'background-color: ' + col + ';', 'text': col }).inject(this.fx[elid].setting); }.bind(this)); this.fx[elid].setting.value = (this.fxOptions[elid] && this.fxOptions[elid].setting) ? this.fxOptions[elid].setting : null; (document.id(elid + '_fx_setting')) ? this.fx[elid].setting.replaces(document.id(elid + '_fx_setting')) : true; } this.fx[elid].applyto = new Element('select', {'class': this.fieldname, 'id': elid + '_fx_applyto', 'name': 'data['+this.ec+'][fx][' + elid + '][applyto]', 'size': '1'}); ['row', 'field'].each( function(col) { new Element('option', {'class': this.fieldname, 'value': col, 'text': ucfirst(col) }).inject(this.fx[elid].applyto); }.bind(this)); this.fx[elid].applyto.value = (this.fxOptions[elid] && this.fxOptions[elid].applyto) ? this.fxOptions[elid].applyto : null; (document.id(elid + '_fx_applyto')) ? this.fx[elid].applyto.replaces(document.id(elid + '_fx_applyto')) : true; } }.bind(this)); this.fx[elid].effect.fireEvent('change'); var rowfx = new Element ('tr', {'class': this.fieldname + ' ' + this.fieldname + '_fx', 'id': elid + '_fx_row'}); var row_1 = new Element('td', {'class': this.fieldname}); this.fx[elid].label.inject(row_1); row_1.inject(rowfx); var row_2 = new Element('td', {'class': this.fieldname}); this.fx[elid].effect.inject(row_2); row_2.inject(rowfx); var row_3 = new Element('td', {'class': this.fieldname}); this.fx[elid].setting.inject(row_3); row_3.inject(rowfx); var row_4 = new Element('td', {'class': this.fieldname}); this.fx[elid].applyto.inject(row_4); row_4.inject(rowfx); (document.id(elid + '_fx_row')) ? rowfx.replaces(document.id(elid + '_fx_row')) : this.fxPropTable.push(rowfx); } }, deleteElement: function(dontask, plural) { if (!dontask) { if (plural) { var check = confirm ( Joomla.JText._('RAFORMS_DELETE_ELEMENT_CONFIRM_PLURAL') ); } else { var check = confirm ( Joomla.JText._('RAFORMS_DELETE_ELEMENT_CONFIRM') ); } } else { var check = true; } if (check == true) { $$('.' + this.fieldname).each(function (el) { ('destroy' in el) ? el.destroy() : true; }); window.formElements[this.fieldname] = null; delete window.formElements[this.fieldname]; return true; } else { //if (this.fieldname == 'option_user') if (this.fieldname.match(/option_/)) { if (document.id(this.fieldname).checked == false) { document.id(this.fieldname).checked = true; } } return false; } }, getDelOptions: function(id) { return new Element ('div', {'id': this.fieldname + '-delOption-' + id, 'class': this.fieldname + ' deletelink deleteimg'}).addEvent('click', function() { var hidden = document.id('el' + this.ec + '_option-' + id + '-hidden').get('value'); this.SelOptDelMenu = new Element ('div', {'class': this.fieldname, 'class': 'SelOptDelMenu'}); var hidebtn = new Element ('input', {'class': this.fieldname, 'type': 'button', 'value': (hidden == 0) ? Joomla.JText._('RAFORMS_HIDE') : Joomla.JText._('RAFORMS_SHOW')}).addEvent('click', function() { switch(this.options.elementtype) { case 'select': document.id('el' + this.ec + '_option-' + id).toggleClass('invisible'); break; case 'checkbox': case 'radio': document.id('el' + this.ec + '_option-' + id + '-div').toggleClass('invisible'); break; } document.id('el' + this.ec + '_option-' + id + '-hidden').set('value', (hidden == 0) ? 1 : 0); document.id('el' + this.ec + '_option-' + id + '-input').setStyle('opacity', (hidden == 0) ? .30 : 1); this.getDelOptions(id).replaces(this.SelOptDelMenu); }.bind(this)); var delbtn = new Element ('input', {'class': this.fieldname, 'type': 'button', 'value': Joomla.JText._('RAFORMS_DELETE')}).addEvent('click', function() { var check = confirm ( Joomla.JText._('RAFORMS_DELETE_ELEMENT_CONFIRM') ); if (check == true) { this.doDeleteOption(id); } }.bind(this)); var cnclbtn = new Element ('input', {'class': this.fieldname, 'type': 'button', 'value': Joomla.JText._('RAFORMS_CANCEL')}).addEvent('click', function() { this.getDelOptions(id).replaces(this.SelOptDelMenu); }.bind(this)); hidebtn.inject(this.SelOptDelMenu); delbtn.inject(this.SelOptDelMenu); cnclbtn.inject(this.SelOptDelMenu); this.SelOptDelMenu.replaces(document.id(this.fieldname + '-delOption-' + id)); }.bind(this)); }, doDeleteOption: function(id) { if (document.id('el' + this.ec + '_option-' + id)) { document.id('el' + this.ec + '_option-' + id).destroy(); } if (document.id('el' + this.ec + '_option-' + id + '-div')) { document.id('el' + this.ec + '_option-' + id + '-div').destroy(); } if (document.id('el' + this.ec + '_option-' + id + '-hidden')) { document.id('el' + this.ec + '_option-' + id + '-hidden').destroy(); } if (document.id('el' + this.ec + '_option-' + id + '-input')) { document.id('el' + this.ec + '_option-' + id + '-input').destroy(); } if (document.id(this.fieldname + '_' + id + '_fx_row')) { document.id(this.fieldname + '_' + id + '_fx_row').destroy(); } }, addOption: function(option, id) { if (this.options.elementtype == 'select') { var input = (new Element('input', {'class': this.fieldname, 'style': 'width: 100%;', 'name': 'data[' + this.ec + '][selopt][' + id + '][option]', 'value': option.option})).addEvent ('keyup', function() { if (document.id('el' + this.ec + '_option-' + id)) { document.id('el' + this.ec + '_option-' + id).set('text', input.get('value')); document.id(this.fieldname + '_' + id + '_fx_option-label').set('text', input.get('value')); } else { // add element effects this.addEffects(id, option.option); this.selOpts[id] = new Element('option', {'id': 'el' + this.ec + '_option-' + id, 'class': this.fieldname + ((option.hidden == 0) ? '' : ' invisible'), 'value': id, 'text': option.option}); this.selOpts[id].selected = (option.preselect); this.selOpts[id].inject(this.elementtype); (new Element('input', {'id': 'el' + this.ec + '_option-' + id + '-hidden', 'type': 'hidden', 'name': 'data[' + this.ec + '][selopt][' + id + '][hidden]', 'value': option.hidden})).inject(this.seloptDiv); } }.bind(this)); var preselect = new Element('input', {'type': 'checkbox', 'class': this.fieldname, 'name': 'data[' + this.ec + '][selopt][' + id + '][preselect]', 'value': 1}).addEvent('click', function() { Array.each(this.elementtype.getChildren('option'), function (item) { if (item.get('value') == id) { item.selected = preselect.checked; } }); }.bind(this)); preselect.checked = (option.preselect); // for hiding / deleting var delOption = this.getDelOptions(id); this.selopt.push([id, preselect, input, delOption], {'id': 'el' + this.ec + '_option-' + id + '-input', 'opacity': (option.hidden == 1) ? .30 : 1}); input.fireEvent('keyup'); } if (this.options.elementtype == 'radio') { var input = (new Element('input', {'class': this.fieldname + ' el' + this.ec + '_option-input', 'style': 'width: 100%;', 'name': 'data[' + this.ec + '][selopt][' + id + '][option]', 'value': option.option})).addEvent ('keyup', function() { var hv = (this.hv) ? this.hv.get('value') : this.options.hv; var position = (this.position) ? this.position.get('value') : this.options.position; var divstyle = (hv == 1) ? 'float: left;' : 'clear: both;'; var labelstyle = (position == 1) ? 'float: left;' : 'float: right;'; var inputstyle = (position == 1) ? 'float: right;' : 'float: left;'; if (document.id('el' + this.ec + '_option-' + id)) { document.id('el' + this.ec + '_option-' + id).set('text', input.get('value')); document.id('el' + this.ec + '_option-' + id).set('style', labelstyle); document.id('el' + this.ec + '_option-' + id + '-radio').set('style', inputstyle); document.id('el' + this.ec + '_option-' + id + '-div').set('style', divstyle); document.id(this.fieldname + '_' + id + '_fx_option-label').set('text', input.get('value')); } else { var radioDiv = new Element('div', {'id': 'el' + this.ec + '_option-' + id + '-div', 'class': this.fieldname + ((option.hidden == 0) ? '' : ' invisible'), 'style': divstyle}); var radioLabel = new Element('label', {'id': 'el' + this.ec + '_option-' + id, 'class': this.fieldname, 'for': 'data['+this.ec+'][radio]', 'text': option.option, 'style': labelstyle}); var radioOption = new Element('input', {'id': 'el' + this.ec + '_option-' + id + '-radio', 'class': this.fieldname + ' inputOption', 'type': 'radio', 'name': 'data['+this.ec+'][radio]', 'value': id, 'style': inputstyle}); radioOption.checked = (option.preselect); radioLabel.inject(radioDiv); radioOption.inject(radioDiv); radioDiv.inject(this.elementtype); this.selOpts[id] = new Element('option', {'id': 'el' + this.ec + '_option-' + id, 'class': this.fieldname, 'value': id, 'text': option.option}); this.selOpts[id].selected = (option.preselect); // add element effects this.addEffects(id, option.option); (new Element('input', {'id': 'el' + this.ec + '_option-' + id + '-hidden', 'type': 'hidden', 'name': 'data[' + this.ec + '][selopt][' + id + '][hidden]', 'value': option.hidden})).inject(this.seloptDiv); } }.bind(this)); var preselect = new Element('input', {'type': 'checkbox', 'class': this.fieldname, 'name': 'data[' + this.ec + '][selopt][' + id + '][preselect]', 'value': 1}).addEvent('click', function() { Array.each(this.elementtype.getElements('.inputOption'), function (item) { if (item.get('value') == id) { item.checked = preselect.checked; } }); }.bind(this)); preselect.checked = (option.preselect == 1); // for hiding / deleting var delOption = this.getDelOptions(id); this.selopt.push([id, preselect, input, delOption], {'id': 'el' + this.ec + '_option-' + id + '-input', 'opacity': (option.hidden == 1) ? .30 : 1}); input.fireEvent('keyup'); } if (this.options.elementtype == 'checkbox') { var input = (new Element('input', {'class': this.fieldname + ' el' + this.ec + '_option-input', 'style': 'width: 100%;', 'name': 'data[' + this.ec + '][selopt][' + id + '][option]', 'value': option.option})).addEvent ('keyup', function() { var hv = (this.hv) ? this.hv.get('value') : this.options.hv; var position = (this.position) ? this.position.get('value') : this.options.position; var divstyle = (hv == 1) ? 'float: left;' : 'clear: both;'; var labelstyle = (position == 1) ? 'float: left;' : 'float: right;'; var inputstyle = (position == 1) ? 'float: right;' : 'float: left;'; if (document.id('el' + this.ec + '_option-' + id)) { document.id('el' + this.ec + '_option-' + id).set('text', input.get('value')); document.id('el' + this.ec + '_option-' + id).set('style', labelstyle); document.id('el' + this.ec + '_option-' + id + '-checkbox').set('style', inputstyle); document.id('el' + this.ec + '_option-' + id + '-div').set('style', divstyle); document.id(this.fieldname + '_' + id + '_fx_option-label').set('text', input.get('value')); } else { var checkboxDiv = new Element('div', {'id': 'el' + this.ec + '_option-' + id + '-div', 'class': this.fieldname + ((option.hidden == 0) ? '' : ' invisible'), 'style': divstyle}); var checkhidden = new Element('input', {'class': this.fieldname, 'name': 'data[' + this.ec + '][checkbox_' + id + ']', 'type': 'hidden', 'value': 'false'}); var checkhiddenvalue = new Element('input', {'class': this.fieldname, 'name': 'data[' + this.ec + '][checkbox_' + id + '_value]', 'type': 'hidden', 'value': id}); checkhidden.inject(checkboxDiv); checkhiddenvalue.inject(checkboxDiv); var checkboxLabel = new Element('div', {'id': 'el' + this.ec + '_option-' + id, 'class': this.fieldname, 'text': option.option, 'class': 'checkboxlabel', 'style': labelstyle}); var checkboxOption = new Element('input', {'id': 'el' + this.ec + '_option-' + id + '-checkbox', 'class': this.fieldname + ' inputOption', 'type': 'checkbox', 'name': 'data[' + this.ec + '][checkbox_' + id + ']', 'value': id, 'style': inputstyle}); checkboxOption.checked = (option.preselect); checkboxLabel.inject(checkboxDiv); checkboxOption.inject(checkboxDiv); checkboxDiv.inject(this.elementtype); this.selOpts[id] = new Element('option', {'id': 'el' + this.ec + '_option-' + id, 'class': this.fieldname, 'value': id, 'text': option.option}); this.selOpts[id].selected = (option.preselect); // add element effects this.addEffects(id, option.option); (new Element('input', {'id': 'el' + this.ec + '_option-' + id + '-hidden', 'type': 'hidden', 'name': 'data[' + this.ec + '][selopt][' + id + '][hidden]', 'value': option.hidden})).inject(this.seloptDiv); } }.bind(this)); var preselect = new Element('input', {'type': 'checkbox', 'class': this.fieldname, 'name': 'data[' + this.ec + '][selopt][' + id + '][preselect]', 'value': 1}).addEvent('click', function() { switch(this.options.elementtype) { case 'select': Array.each(this.elementtype.getChildren('option'), function (item) { item.selected = (item.get('value') == id && this.checked); }); break; case 'radio': case 'checkbox': Array.each(this.elementtype.getElements('.inputOption'), function (item) { if (item.get('value') == id) { item.checked = preselect.checked; } }); break; } }.bind(this)); preselect.checked = (option.preselect == 1); // for hiding / deleting var delOption = this.getDelOptions(id); this.selopt.push([id, preselect, input, delOption], {'id': 'el' + this.ec + '_option-' + id + '-input', 'opacity': (option.hidden == 1) ? .30 : 1}); input.fireEvent('keyup'); } }, addSelOpt: function() { this.seloptDiv = document.id('seloptDiv').clone(); this.seloptDiv.removeClass('invisible'); this.seloptDiv.set('id', 'el_' + this.ec + '_selopt_div'); this.addselopt = new Element('div', {'id': 'el_' + this.ec + '_selopt_div_add', 'class': 'add-option'}); this.seloptlabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_SELOPT_OPTIONS'), 'class': 'propcaption'}); this.selopt = new raHtmlTable({properties: { 'id': 'id_' + this.ec + '_selopt', 'class': 'selopt-option', 'style': 'width: 75%;' }}); this.selopt.set('headers', [{'content': 'ID', 'properties': {'width': '5%'}}, {'content': Joomla.JText._('RAFORMS_SELOPT_PRESELECT'), 'properties': {'width': '5%'}}, {'content': Joomla.JText._('RAFORMS_SELOPT_DATA'), 'properties': {'width': '90%'}}, {'content': ' ', 'properties': {'width': '5%'}}]); this.selopt.set('footers', [{'content': this.addselopt, 'properties': {'colspan': '4'}}]); // add element effects empty table, so removed items get deleted // only do that if <table> has a <tbody> containing children if (this.fxPropTable.toElement().getChildren().length > 1) { this.fxPropTable.empty() } this.fxPropTable.push([new Element('b', {'text': Joomla.JText._('RAFORMS_FX'), 'class': 'propcaption'})], {'colspan': 4}); if (this.seloptOptions.length > 0) { Array.each ( this.seloptOptions, function (option, id) { this.addOption(option, id); }.bind(this)); } this.addselopt.addEvent ('click', function() { var seloptcount = this.seloptOptions.length; this.seloptOptions[seloptcount] = {}; this.seloptOptions[seloptcount].option = ''; this.seloptOptions[seloptcount].preselect = 0; this.seloptOptions[seloptcount].hidden = 0; this.addOption(this.seloptOptions[seloptcount], seloptcount); (this.seloptDiv.getParent()) ? document.id('el_' + this.ec + '_selopt_div').getParent().setStyle('height', 'auto') : true; ($$('.' + this.fieldname + ' .propertiesDiv').getParent()) ? $$('.' + this.fieldname + ' .propertiesDiv').getParent().setStyle('height', 'auto') : true; }.bind(this)); if (this.seloptOptions.length == 0) { this.addselopt.fireEvent('click'); } this.selopt.inject(this.seloptDiv, 'top'); this.dataPropTable.push([{'content': this.seloptlabel, 'properties': {'class': 'proplabelTd'}}, {'content': this.seloptDiv, 'properties': {'class': 'propTd'}}]); }, addSelOptFromDB: function() { this.SelOptFromDBlabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_SELOPT_FROM_DB'), 'class': 'proplabel'}); (new Element('input', {'class': this.fieldname, 'name': 'data['+this.ec+'][seloptfromdb]', 'type': 'hidden', 'value': 'false'})).inject(this.SelOptFromDBlabel); this.SelOptFromDB = new Element('input', {'class': this.fieldname, 'name': 'data['+this.ec+'][seloptfromdb]', 'type': 'checkbox', 'value': 'true'}).addEvent('click', function() { if (this.SelOptFromDB.checked) { (document.id('el_' + this.ec + '_seloptfromdb_div')) ? document.id('el_' + this.ec + '_seloptfromdb_div').setStyle('height', 'auto') : true; (document.id('el_' + this.ec + '_selopt_div')) ? document.id('el_' + this.ec + '_selopt_div').setStyles({'height': 0, 'overflow': 'hidden'}) : true; $$('.' + this.fieldname + ' .propertiesDiv').getParent().setStyle('height', 'auto'); } else { (document.id('el_' + this.ec + '_selopt_div')) ? document.id('el_' + this.ec + '_selopt_div').setStyle('height', 'auto') : true; (document.id('el_' + this.ec + '_seloptfromdb_div')) ? document.id('el_' + this.ec + '_seloptfromdb_div').setStyles({'height': 0, 'overflow': 'hidden'}) : true; $$('.' + this.fieldname + ' .propertiesDiv').getParent().setStyle('height', 'auto'); } }.bind(this)); this.SelOptFromDB.checked = this.options.seloptfromdb; this.dataPropTable.push([{'content': this.SelOptFromDBlabel, 'properties': {'class': 'proplabelTd'}}, {'content': this.SelOptFromDB, 'properties': {'class': 'propTd'}}]); var SelOptFromDBDiv = new Element('div', {'id': 'el_' + this.ec + '_seloptfromdb_div'}); var SelOptFromDBProperties = new raHtmlTable({ 'properties': { 'border': '0', 'cellspacing': '3', 'id': 'el_' + this.ec + '_seloptfromdb', 'class': 'propeditformtable' }}); var SelOptFromDBSQLLabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_SELOPT_FROM_DB_SQL'), 'class': 'proplabel'}); var SelOptFromDBSQLDiv = new Element('div', {'id': 'el_'+this.ec+'_seloptfromdbsqldiv', 'class': this.fieldname + ' seloptfromdbsqldiv'}); var SelOptFromDBSQLTestDiv = new Element('div', {'id': 'el_'+this.ec+'_seloptfromdbsqltestdiv', 'class': this.fieldname + ' seloptfromdbsqltestdiv', 'text': Joomla.JText._('RAFORMS_SELOPT_FROM_DB_SQL_NOT_TESTED')}); var SelOptFromDBSQL = new Element('textarea', {'class': this.fieldname + ' seloptfromdbsql', 'id': 'el_'+this.ec+'_seloptfromdbsql', 'name': 'data['+this.ec+'][seloptfromdbsql]', 'cols': '35', 'rows': '5', 'value': this.options.seloptfromdbsql}); this.SelOptFromDBSQLTest = new Element('input', {'type': 'button', 'name': 'Test', 'value': 'Test Query', 'class': this.fieldname + ' selopttestbtn', 'id': 'el_'+this.ec+'_seloptfromdbsqltest'}); this.SelOptFromDBSQLTest.addEvent('click', function () { var route = document.id('adminForm').get('action'); // the request var loadSelOptions = new Request.JSON ({ method: 'post', url: route + '&format=raw&task=raform.getSelOptFromDBSQLTest&q=' + encodeURIComponent(document.id('el_' + this.ec + '_seloptfromdbsql').get('value')), initialDelay: 0, link: 'chain', onSuccess: function(response) { var valProp = document.id('el_' + this.ec + '_seloptfromdbvalue').get('value'); var textProp = document.id('el_' + this.ec + '_seloptfromdbtext').get('value'); if (!response.result || response.result === false) { document.id('el_' + this.ec + '_seloptfromdbsqltestdiv').setProperties({ 'text': response.message, 'class': this.fieldname + ' seloptfromdbsqltestdiv seloptfromdbsqltestdivFailed' }); } else { var allOptions = []; var ret = Object.every(response.result, function (item) { if (!item[valProp]) { document.id('el_' + this.ec + '_seloptfromdbsqltestdiv').setProperties({ 'text': Joomla.JText._('RAFORMS_SELOPT_FROM_DB_ERROR_ITEM_VALUE_KEYWORD_WRONG'), 'class': this.fieldname + ' seloptfromdbsqltestdiv seloptfromdbsqltestdivFailed' }); return false; } if (!item[textProp]) { document.id('el_' + this.ec + '_seloptfromdbsqltestdiv').setProperties({ 'text': Joomla.JText._('RAFORMS_SELOPT_FROM_DB_ERROR_ITEM_TEXT_KEYWORD_WRONG'), 'class': this.fieldname + ' seloptfromdbsqltestdiv seloptfromdbsqltestdivFailed' }); return false; } var option = {}; option.option = item[textProp]; option.val = item[valProp]; option.hidden = 0; option.preselect = (this.options.seloptfromdbpreselect.contains(item[valProp])); allOptions.push(option); return true; }.bind(this)); if (ret) { this.selopt.empty(); this.SelOptFromDBPreselect.empty(); // delete previous options if (this.selOpts && Object.getLength(this.selOpts) > 0) { Object.each(this.selOpts, function(option, id) { this.doDeleteOption(id); }.bind(this)); // if there is a first entry, delete it if (document.id('firstEntry_' + this.fieldname)) { document.id('firstEntry_' + this.fieldname).destroy(); } } Array.each(allOptions, function (option) { this.addOption(option, option.val); this.selOpts[option.val].clone().inject(this.SelOptFromDBPreselect); }.bind(this)); if (this.seloptempty && this.seloptempty.get('value') != '') { var firstOption = new Element('option', {'id': 'firstEntry_' + this.fieldname, 'value': '', 'text': this.seloptempty.get('value')}); //firstOption.selected = (this.options.seloptfromdbpreselect.contains('')); firstOption.selected = (this.options.seloptfromdbpreselect == ''); firstOption.inject(this.elementtype, 'top'); firstOption.clone().inject(this.SelOptFromDBPreselect, 'top'); } document.id('el_' + this.ec + '_seloptfromdbsqltestdiv').setProperties({ 'text': response.message, 'class': this.fieldname + ' seloptfromdbsqltestdiv seloptfromdbsqltestdivOk' }); } } }.bind(this), onFailure: function() { document.id('el_' + this.ec + '_seloptfromdbsqltestdiv').setProperties({ 'text': Joomla.JText._('RAFORMS_SELOPT_FROM_DB_SQL_TEST_FAILED'), 'class': this.fieldname + ' seloptfromdbsqltestdiv seloptfromdbsqltestdivFailed' }); }.bind(this) /* onComplete: function() { console.log('yay!'); } */ }).send(); }.bind(this)); SelOptFromDBSQL.inject(SelOptFromDBSQLDiv); this.SelOptFromDBSQLTest.inject(SelOptFromDBSQLDiv); SelOptFromDBSQLTestDiv.inject(SelOptFromDBSQLDiv); SelOptFromDBProperties.push([SelOptFromDBSQLLabel, SelOptFromDBSQLDiv]); var SelOptFromDBCheckPermHintLabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_SELOPT_FROM_DB_PERM_CHECK_HINT'), 'class': 'proplabel el_'+this.ec+'_seloptfromdbcheckpermhint'}); var SelOptFromDBCheckPermHint = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_SELOPT_FROM_DB_PERM_CHECK_HINT_TEXT'), 'class': 'el_'+this.ec+'_seloptfromdbcheckpermhint'}); SelOptFromDBProperties.push([{'content': SelOptFromDBCheckPermHintLabel, 'properties': {'style': 'max-width: 200px;'}}, {'content': SelOptFromDBCheckPermHint, 'properties': {'style': 'max-width: 400px;'}}]); var SelOptFromDBValueLabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_SELOPT_FROM_DB_KEY_FOR_VALUE'), 'class': 'proplabel'}); var SelOptFromDBValue = new Element('input', {'class': this.fieldname, 'id': 'el_'+this.ec+'_seloptfromdbvalue', 'name': 'data['+this.ec+'][seloptfromdbvalue]', 'type': 'text', 'size': '30', 'value': this.options.seloptfromdbvalue}); SelOptFromDBProperties.push([SelOptFromDBValueLabel, SelOptFromDBValue]); var SelOptFromDBTextLabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_SELOPT_FROM_DB_KEY_FOR_TEXT'), 'class': 'proplabel'}); var SelOptFromDBText = new Element('input', {'class': this.fieldname, 'id': 'el_'+this.ec+'_seloptfromdbtext', 'name': 'data['+this.ec+'][seloptfromdbtext]', 'type': 'text', 'size': '30', 'value': this.options.seloptfromdbtext}); SelOptFromDBProperties.push([SelOptFromDBTextLabel, SelOptFromDBText]); var SelOptFromDBPreselectLabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_SELOPT_PRESELECT'), 'class': 'proplabel'}); this.SelOptFromDBPreselect = new Element('select', {'class': this.fieldname, 'id': 'el_' + this.ec + '_seloptfromdbpreselect', 'name': 'data['+this.ec+'][seloptfromdbpreselect][]'}).addEvent('change', function () { var selectedItems = this.SelOptFromDBPreselect.getSelected().get('value'); switch(this.options.elementtype) { case 'select': Array.each(this.elementtype.getChildren('option'), function (item) { item.selected = selectedItems.contains(item.get('value')); }); break; case 'radio': case 'checkbox': Array.each(this.elementtype.getElements('.inputOption'), function (item) { item.checked = selectedItems.contains(item.get('value')); }); break; } }.bind(this)); if (this.options.multi) { this.SelOptFromDBPreselect.set('multiple', 'multiple') } SelOptFromDBProperties.push([SelOptFromDBPreselectLabel, this.SelOptFromDBPreselect]); SelOptFromDBProperties.inject(SelOptFromDBDiv); this.dataPropTable.push([{'content': '', 'properties': {'class': 'proplabelTd notvisible'}}, {'content': SelOptFromDBDiv, 'properties': {'class': 'propTd'}}]); this.postEvents.push({'obj': 'this.SelOptFromDB', 'typ': 'click'}); if (this.options.seloptfromdb) { this.postEvents.push({'obj': 'this.SelOptFromDBSQLTest', 'typ': 'click'}); } }, addElement: function() { if (this.options.elementtype == 'user' || this.options.elementtype == 'date' || this.options.elementtype == 'ip') { this.ec = this.options.elementtype; this.isFormElement = false; this.hasHeading = true; this.fieldname = 'option_' + this.options.elementtype; if (this.options.elementtype == 'ip') { this.options.label = 'IP'; } else { this.options.label = ucfirst(this.options.elementtype); } if (document.id('option_' + this.options.elementtype).checked == true) { this.fieldlabelhidden = new Element('input', {'class': this.fieldname, 'id': this.options.elementtype+'label', 'type': 'hidden', 'name': 'data['+this.options.elementtype+'][label]', 'value': this.options.label}); this.fieldnamehidden = new Element('input', {'class': this.fieldname, 'id': this.options.elementtype+'fieldname', 'type': 'hidden', 'name': 'data['+this.options.elementtype+'][fieldname]', 'value': this.options.elementtype}); this.fieldlabelhidden.inject(document.id('save'+this.options.elementtype+'td')); this.fieldnamehidden.inject(document.id('save'+this.options.elementtype+'td')); this.addHeading(); (this.options.filterlabel != this.options.label) ? $$('#'+this.fieldname+'_list span.filterlabel').set('html', this.options.filterlabel+'<br/>'+'('+this.options.label+')') : true; this.filterlabellabel = new Element('span', {'class': this.fieldname, 'text': Joomla.JText._('RAFORMS_PROP_FILTER_LABEL'), 'class': 'proplabel'}); this.filterlabel = new Element('input', {'class': this.fieldname, 'type': 'text', 'name': 'data['+this.ec+'][filterlabel]', 'value': this.options.filterlabel}).addEvent( 'keyup', function(){ if (this.filterlabel.get('value') != this.label.get('value')) { if (this.filterlabel.get('value') != '') { $$('#'+this.fieldname+'_filterlist span.filterlabel').set('html', this.filterlabel.get('value')+'<br/>'+'('+this.label.get('value')+')'); } this.options.filterlabel = this.filterlabel.get('value'); } else { $$('#'+this.fieldname+'_filterlist span.filterlabel').set('html', this.filterlabel.get('value')); this.options.filterlabel = this.label.get('value'); } }.bind(this)); this.filterproperties.push([this.filterlabellabel,this.filterlabel]); this.addHeadingSortable(); this.addListviewProperties(); this.addListviewTable(); this.addFilter(); this.addFilterTable(); } else { this.deleteElement(false, false); } } }, addNoData : function() { this.nodata = new Element('input', {'class': this.fieldname, 'type': 'hidden', 'name': 'data['+this.ec+'][nodata]', 'value': 1}); this.nodata.inject(this.divElement); }, postprocessing : function() { if (this.options.elementtype != 'user' && this.options.elementtype != 'date' && this.options.elementtype != 'ip') { // gray hidden elements // Set hidden parameter this.hiddenInput = new Element('input', {'class': this.fieldname, 'type': 'hidden', 'id': this.fieldname+'_hidden', 'name': 'data['+this.ec+'][hidden]', 'value': this.options.hidden}); this.hiddenInput.inject(this.divElement); this.hideElement(this.hidden); // for saving list position information of main element this.posX = (new Element('input', {'class': this.fieldname + ' posX', 'type': 'hidden', 'name': 'data[' + this.ec + '][posX]', 'id': this.fieldname + '-posX', 'value': this.options.posX})).inject(this.divElement); this.posY = (new Element('input', {'class': this.fieldname + ' posY', 'type': 'hidden', 'name': 'data[' + this.ec + '][posY]', 'id': this.fieldname + '-posY', 'value': this.options.posY})).inject(this.divElement); this.sizX = (new Element('input', {'class': this.fieldname + ' sizX', 'type': 'hidden', 'name': 'data[' + this.ec + '][sizX]', 'id': this.fieldname + '-sizX', 'value': this.options.sizX})).inject(this.divElement); this.sizY = (new Element('input', {'class': this.fieldname + ' sizY', 'type': 'hidden', 'name': 'data[' + this.ec + '][sizY]', 'id': this.fieldname + '-sizY', 'value': this.options.sizY})).inject(this.divElement); // if is of type empty if (this.options.elementtype == 'empty') { this.elementDiv.addClass('empty-lines'); } } }, fireAllEvents: function() { this.postEvents.each( function (evnt) { eval( evnt.obj + ".fireEvent('" + evnt.typ + "');"); }.bind(this)); } });