Scott Baker | 2cbb607 | 2014-12-16 22:49:42 -0800 | [diff] [blame] | 1 | function init_picker(selector, ordered) { |
| 2 | //console.log("init_picker"); |
| 3 | //console.log($(selector)); |
| 4 | |
| 5 | var addBtn = $(selector).find(".btn-picker-add"); |
| 6 | var removeBtn = $(selector).find(".btn-picker-remove"); |
| 7 | var upBtn = $(selector).find(".btn-picker-up"); |
| 8 | var downBtn = $(selector).find(".btn-picker-down"); |
| 9 | var from = $(selector).find(".select-picker-from"); |
| 10 | var to = $(selector).find(".select-picker-to"); |
| 11 | |
| 12 | if (!ordered) { |
| 13 | upBtn.hide(); |
| 14 | downBtn.hide(); |
| 15 | } |
| 16 | |
| 17 | addBtn.click(function(){ |
| 18 | console.log("add"); |
| 19 | from.find(":selected").each( function() { |
| 20 | to.append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
|
| 21 | $(this).remove();
|
| 22 | });
|
| 23 | });
|
| 24 | removeBtn.click(function(){
|
| 25 | console.log("remove");
|
| 26 | to.find(":selected").each( function() {
|
| 27 | from.append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
|
| 28 | $(this).remove();
|
| 29 | });
|
| 30 | });
|
| 31 | upBtn.bind('click', function() {
|
| 32 | to.find(":selected").each( function() {
|
| 33 | var newPos = to.find('option').index(this) - 1;
|
| 34 | if (newPos > -1) {
|
| 35 | to.find("option").eq(newPos).before("<option value='"+$(this).val()+"' selected='selected'>"+$(this).text()+"</option>");
|
| 36 | $(this).remove();
|
| 37 | }
|
| 38 | });
|
| 39 | });
|
| 40 | downBtn.bind('click', function() {
|
| 41 | var countOptions = to.find("option").size();
|
| 42 | to.find(":selected").each( function() {
|
| 43 | var newPos = to.find("option").index(this) + 1;
|
| 44 | if (newPos < countOptions) {
|
| 45 | to.find("option").eq(newPos).after("<option value='"+$(this).val()+"' selected='selected'>"+$(this).text()+"</option>");
|
| 46 | $(this).remove();
|
| 47 | }
|
| 48 | });
|
| 49 | });
|
| 50 | };
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame^] | 51 |
|
| 52 | function init_spinner(selector, value) {
|
| 53 | var spinner = $(selector).spinner( "value", value);
|
| 54 | };
|