| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 1 | /** |
| 2 | * New Project page |
| 3 | **/ |
| 4 | function handleTypeChoose(type) { |
| 5 | resetStartFromInputs() |
| 6 | $('#projectType').val(type); |
| 7 | $('#startGroup').show(); |
| 8 | $('input[id="scratch"]').prop('checked', true); |
| 9 | $('#startButtonsSelect label').removeClass("active"); |
| 10 | $('#s-scratch').addClass("active"); |
| 11 | $('#createButton').prop('disabled', false); |
| 12 | //$('#projectName').val('New_'+type+'_project') |
| 13 | } |
| 14 | |
| 15 | function startFromChoose(start) { |
| 16 | resetStartFromInputs() |
| 17 | //resetSelectors(); |
| 18 | var type = $('#select_type').val(); |
| 19 | |
| 20 | if (start == 'files') |
| 21 | $('#div-file-upload-' + type).show(); |
| 22 | else if (start == 'example') |
| 23 | //document.getElementById['#div-example-' + type].style.display = "block"; |
| 24 | $('#div-example-' + type).css("display", "inline"); |
| 25 | |
| 26 | } |
| 27 | |
| 28 | function resetStartFromInputs() { |
| 29 | $('div[class="start-selector"]').hide(); |
| 30 | $('input[type="file"]').val(''); |
| 31 | $('select[class="example-selector"]').val(null).trigger("change"); |
| 32 | } |
| 33 | |
| 34 | $(document).ready(function () { |
| 35 | |
| 36 | // init selector |
| 37 | $(".start-selector").css("display", "inline"); |
| 38 | $('#select_type').select2({ |
| 39 | placeholder: { |
| 40 | id: '-1', |
| 41 | text: 'Select an option' |
| 42 | }, |
| 43 | data: data_type_selector |
| 44 | }); |
| 45 | |
| 46 | |
| 47 | $('#select_type').on("select2:select", function (evt) { |
| 48 | if (evt) { |
| 49 | var args = evt.params; |
| 50 | handleTypeChoose(args.data.value) |
| 51 | } |
| 52 | }); |
| 53 | |
| 54 | if (type_example_files) { |
| 55 | for (var key in type_example_files) { |
| 56 | $('select[id="example-' + key + '"]').select2({ |
| 57 | placeholder: { |
| 58 | id: '-1', |
| 59 | text: 'Select an option' |
| 60 | }, |
| 61 | data: type_example_files[key] |
| 62 | }); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | } |
| 67 | |
| 68 | |
| 69 | |
| 70 | $("#startButtonsSelect :input").change(function () { |
| 71 | startFromChoose(this.value); |
| 72 | }); |
| 73 | |
| 74 | |
| 75 | |
| 76 | $("body").bind("ajaxSend", function (elm, xhr, s) { |
| 77 | if (s.type == "POST") { |
| 78 | xhr.setRequestHeader('csrftoken', $('#csrfmiddlewaretoken').val()); |
| 79 | } |
| 80 | }); |
| 81 | |
| 82 | $(".start-selector").css("display", "none"); |
| 83 | |
| 84 | }); |