1 /** 2 * FilterForm 3 */ 4 wso2vis.f.form.FilterForm = function() { 5 wso2vis.f.BasicFilter.call(this); 6 }; 7 8 wso2vis.extend(wso2vis.f.form.FilterForm, wso2vis.f.BasicFilter); 9 10 wso2vis.f.form.FilterForm.prototype.property("canvas"); 11 12 wso2vis.f.form.FilterForm.prototype.create = function() { 13 var i = 0; 14 var content; 15 content = '<form>' + 16 '<table width="100%" border="0">' + 17 '<tr>' + 18 ' <td width="13%" rowspan="4"><select name="FilterFormList1_'+this.getID()+'" id="FilterFormList1_'+this.getID()+'" size="10" style="width: 110px">'; 19 for (i = 0; i < this.remainingArray.length; i++) { 20 if (i == 0) 21 content += '<option value="'+i+'" selected>' + this.remainingArray[i] +'</option>'; 22 else 23 content += '<option value="'+i+'">' + this.remainingArray[i] +'</option>'; 24 } 25 content += ' </select></td>' + 26 ' <td width="6%"> </td>' + 27 ' <td width="14%" rowspan="4"><select name="FilterFormList2_'+this.getID()+'" id="FilterFormList2_'+this.getID()+'" size="10" style="width: 110px">'; 28 if (this.filterArray() !== undefined) { 29 for (i = 0; i < this.filterArray().length; i++) { 30 if (i == 0) 31 content += '<option value="'+i+'" selected>' + this.filterArray()[i] +'</option>'; 32 else 33 content += '<option value="'+i+'">' + this.filterArray()[i] +'</option>'; 34 } 35 } 36 content += ' </select></td>' + 37 ' <td width="7%"> </td>' + 38 ' <td width="60%" rowspan="4"> </td>' + 39 '</tr>' + 40 '<tr>' + 41 ' <td><div align="center">' + 42 ' <input type="button" name="buttonLeft" id="buttonLeft" value="Add" style="width: 50px" onclick="FilterFormButtonLeft('+this.getID()+');"/>' + 43 ' </div></td>' + 44 ' <td><div align="center">' + 45 ' <input type="button" name="buttonUp" id="buttonUp" value="Up" style="width: 50px" onclick="FilterFormButtonUp('+this.getID()+');"/>' + 46 ' </div></td>' + 47 '</tr>' + 48 '<tr>' + 49 ' <td><div align="center">' + 50 ' <input type="button" name="buttonRight" id="buttonRight" value="Remove" style="width: 50px" onclick="FilterFormButtonRight('+this.getID()+');"/>' + 51 ' </div></td>' + 52 ' <td><div align="center">' + 53 ' <input type="button" name="buttonDown" id="buttonDown" value="Down" style="width: 50px" onclick="FilterFormButtonDown('+this.getID()+');"/>' + 54 ' </div></td>' + 55 '</tr>' + 56 '<tr>' + 57 ' <td> </td>' + 58 ' <td> </td>' + 59 '</tr>' + 60 '<tr>' + 61 ' <td colspan="5">' + 62 ' <input type="button" name="buttonApply" id="buttonApply" value="Apply" style="width: 50px" onclick="FilterFormButtonApply('+this.getID()+')"/>' + 63 ' <input type="button" name="buttonCancel" id="buttonCancel" value="Cancel" style="width: 50px" onclick="FilterFormButtonCancel('+this.getID()+')"/></td>' + 64 '</tr>' + 65 '</table>' + 66 '</form>'; 67 68 return content; 69 } 70 71 wso2vis.f.form.FilterForm.prototype.load = function() { var canvas = document.getElementById(this.canvas()); canvas.innerHTML = this.create(); }; 72 wso2vis.f.form.FilterForm.prototype.unload = function() { var canvas = document.getElementById(this.canvas()); canvas.innerHTML = ""; }; 73 74 wso2vis.f.form.FilterForm.prototype.onApply = function(data) { 75 }; 76 77 wso2vis.f.form.FilterForm.prototype.create.onCancel = function() { 78 }; 79 80 FilterFormButtonUp = function(id) { 81 FilterFormItemMoveWithin(true, "FilterFormList2_"+id); 82 }; 83 84 FilterFormButtonDown = function(id) { 85 FilterFormItemMoveWithin(false, "FilterFormList2_"+id); 86 }; 87 88 FilterFormButtonLeft = function(id) { 89 FilterFormItemMoveInbetween("FilterFormList1_"+id, "FilterFormList2_"+id); 90 }; 91 92 FilterFormButtonRight = function(id) { 93 FilterFormItemMoveInbetween("FilterFormList2_"+id, "FilterFormList1_"+id); 94 }; 95 96 FilterFormButtonApply = function(id) { 97 var basicDataFilter = wso2vis.fn.getFilterFromID(id); 98 var list2Element = document.getElementById("FilterFormList2_" + id); 99 var i = 0; 100 basicDataFilter.filterArray([]); 101 for (i = 0; i < list2Element.length; i++) { 102 basicDataFilter.filterArray().push(list2Element.options[i].text); 103 } 104 basicDataFilter.onApply(basicDataFilter.filterArray()); 105 }; 106 107 FilterFormButtonCancel = function(id) { 108 var FilterForm = wso2vis.fn.getFilterFromID(id); 109 FilterForm.onCancel(); 110 }; 111 112 FilterFormItemMoveInbetween = function(listName, listName2) { 113 var src = document.getElementById(listName); 114 var dst = document.getElementById(listName2); 115 var idx = src.selectedIndex; 116 if (idx==-1) 117 alert("You must first select the item to move."); 118 else { 119 var oldVal = src[idx].value; 120 var oldText = src[idx].text; 121 src.remove(idx); 122 123 var nxidx; 124 if (idx>=src.length-1) 125 nxidx=src.length-1; 126 else 127 nxidx=idx; 128 if (src.length > 0) { 129 src.selectedIndex = nxidx; 130 } 131 132 var opNew = document.createElement('option'); 133 opNew.text = oldText; 134 opNew.value = oldVal; 135 try { 136 dst.add(opNew, null); // standards compliant; doesn't work in IE 137 } 138 catch(ex) { 139 dst.add(opNew); // IE only 140 } 141 dst.selectedIndex = dst.length - 1; 142 } 143 }; 144 145 FilterFormItemMoveWithin = function(bDir,sName) { 146 var el = document.getElementById(sName); 147 var idx = el.selectedIndex 148 if (idx==-1) 149 alert("You must first select the item to reorder.") 150 else { 151 var nxidx = idx+( bDir? -1 : 1) 152 if (nxidx<0) nxidx=el.length-1 153 if (nxidx>=el.length) nxidx=0 154 var oldVal = el[idx].value 155 var oldText = el[idx].text 156 el[idx].value = el[nxidx].value 157 el[idx].text = el[nxidx].text 158 el[nxidx].value = oldVal 159 el[nxidx].text = oldText 160 el.selectedIndex = nxidx 161 } 162 }; 163 164