[795] | 1 | |
---|
| 2 | // class NanoAjaxSelectBox |
---|
| 3 | function NanoAjaxSelectBox( selectbox_id ) |
---|
| 4 | { |
---|
| 5 | // Pre Check: is |
---|
| 6 | if( selectbox_id == null || !$(selectbox_id) ) |
---|
| 7 | { |
---|
| 8 | alert( 'No SelectBox ID given!!!\nTerminating!' ); |
---|
| 9 | return; |
---|
| 10 | } |
---|
| 11 | |
---|
| 12 | // ------------------------------------------------------------------------- |
---|
| 13 | // Private variables |
---|
| 14 | |
---|
| 15 | var _mObjSelectbox = $(selectbox_id); |
---|
| 16 | |
---|
| 17 | // ######################################################################### |
---|
| 18 | // Privileged Method (has public access and can access private vars & funcs) |
---|
| 19 | this.fillSelectBoxByArray = _fillSelectBoxByArray; |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 23 | // PRIVATE Methods |
---|
| 24 | |
---|
| 25 | function _fillSelectBoxByArray( data_array, fields_to_add, pre_entries, index_selected ) |
---|
| 26 | { |
---|
| 27 | var is_selected = false; |
---|
| 28 | var new_data_array = []; |
---|
| 29 | |
---|
| 30 | if( _mObjSelectbox.length > 0) |
---|
| 31 | { |
---|
| 32 | _deleteAllEntries(); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | if(pre_entries.length > 0) |
---|
| 36 | { |
---|
| 37 | for(var i=0;i<pre_entries.length;i++) |
---|
| 38 | { |
---|
| 39 | new_data_array.push(pre_entries[i]); |
---|
| 40 | } |
---|
| 41 | for(var i=0;i<data_array.length;i++) |
---|
| 42 | { |
---|
| 43 | new_data_array.push(data_array[i]); |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | else |
---|
| 47 | { |
---|
| 48 | new_data_array = data_array; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | for( i=0; i<new_data_array.length; i++ ) |
---|
| 52 | { |
---|
| 53 | _addSelectBoxEntry( (fields_to_add.length == 0) ? new_data_array[i] : new_data_array[i][fields_to_add[0]], |
---|
| 54 | (fields_to_add.length == 0) ? new_data_array[i] : new_data_array[i][fields_to_add[1]], |
---|
| 55 | ((i == index_selected) ? true : false), |
---|
| 56 | ((i == index_selected) ? true : false) ); |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | function _addSelectBoxEntry(value, desc, default_entry, is_selected) |
---|
| 61 | { |
---|
| 62 | _mObjSelectbox.options[_mObjSelectbox.length] = new Option(desc, value, default_entry, is_selected); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | function _deleteAllEntries() |
---|
| 66 | { |
---|
| 67 | var i = (_mObjSelectbox.length-1); |
---|
| 68 | |
---|
| 69 | while( _mObjSelectbox.length > 0 ) |
---|
| 70 | { |
---|
| 71 | _mObjSelectbox.options[i] = null; |
---|
| 72 | --i; |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | function _deleteFirstEntry() |
---|
| 77 | { |
---|
| 78 | _mObjSelectbox.options[0] = null; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | function _deleteLastEntry() |
---|
| 82 | { |
---|
| 83 | _mObjSelectbox.options[_mObjSelectbox.length - 1] = null; |
---|
| 84 | } |
---|
| 85 | } |
---|