From: Loic Baron Date: Tue, 6 Jan 2015 14:26:22 +0000 (+0100) Subject: Registration: authority is checked in python, combobox value and text displayed are... X-Git-Tag: myslice-1.3~127 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=e950c3f3208648fab672a254b57710f4a7c3f77c;p=myslice.git Registration: authority is checked in python, combobox value and text displayed are different if we have the authority name from the query --- diff --git a/portal/static/css/jquery.ui.combobox.css b/portal/static/css/jquery.ui.combobox.css new file mode 100644 index 00000000..fab8f48a --- /dev/null +++ b/portal/static/css/jquery.ui.combobox.css @@ -0,0 +1,16 @@ +.custom-combobox { + position: relative; + display: inline-block; +} +.custom-combobox-toggle { + position: absolute; + top: 0; + bottom: 0; + margin-left: -1px; + padding: 0; +} +.custom-combobox-input { + margin: 0; + padding: 5px 10px; + width: 350px; +} diff --git a/portal/static/js/jquery-ui-combobox.js b/portal/static/js/jquery-ui-combobox.js new file mode 100644 index 00000000..ac1ff6fb --- /dev/null +++ b/portal/static/js/jquery-ui-combobox.js @@ -0,0 +1,129 @@ +(function( $ ) { + $.widget( "custom.combobox", { + _create: function() { + this.wrapper = $( "" ) + .addClass( "custom-combobox" ) + .insertAfter( this.element ); + + this.element.hide(); + this._createAutocomplete(); + this._createShowAllButton(); + }, + + _createAutocomplete: function() { + var selected = this.element.children( ":selected" ), + value = selected.val() ? selected.text() : ""; + + this.input = $( "" ) + .appendTo( this.wrapper ) + .val( value ) + .attr( "title", "" ) + .addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" ) + .autocomplete({ + delay: 0, + minLength: 0, + source: $.proxy( this, "_source" ) + }) + .tooltip({ + tooltipClass: "ui-state-highlight" + }); + + this._on( this.input, { + autocompleteselect: function( event, ui ) { + ui.item.option.selected = true; + this._trigger( "select", event, { + item: ui.item.option + }); + }, + + autocompletechange: "_removeIfInvalid" + }); + }, + + _createShowAllButton: function() { + var input = this.input, + wasOpen = false; + + $( "" ) + .attr( "tabIndex", -1 ) + .attr( "title", "Show All Items" ) + .tooltip() + .appendTo( this.wrapper ) + .button({ + icons: { + primary: "ui-icon-triangle-1-s" + }, + text: false + }) + .removeClass( "ui-corner-all" ) + .addClass( "custom-combobox-toggle ui-corner-right" ) + .mousedown(function() { + wasOpen = input.autocomplete( "widget" ).is( ":visible" ); + }) + .click(function() { + input.focus(); + + // Close if already visible + if ( wasOpen ) { + return; + } + + // Pass empty string as value to search for, displaying all results + input.autocomplete( "search", "" ); + }); + }, + + _source: function( request, response ) { + var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" ); + response( this.element.children( "option" ).map(function() { + var text = $( this ).text(); + if ( this.value && ( !request.term || matcher.test(text) ) ) + return { + label: text, + value: text, + option: this + }; + }) ); + }, + + _removeIfInvalid: function( event, ui ) { + + // Selected an item, nothing to do + if ( ui.item ) { + return; + } + + // Search for a match (case-insensitive) + var value = this.input.val(), + valueLowerCase = value.toLowerCase(), + valid = false; + this.element.children( "option" ).each(function() { + if ( $( this ).text().toLowerCase() === valueLowerCase ) { + this.selected = valid = true; + return false; + } + }); + + // Found a match, nothing to do + if ( valid ) { + return; + } + + // Remove invalid value + this.input + .val( "" ) + .attr( "title", value + " didn't match any item" ) + .tooltip( "open" ); + this.element.val( "" ); + this._delay(function() { + this.input.tooltip( "close" ).attr( "title", "" ); + }, 2500 ); + this.input.autocomplete( "instance" ).term = ""; + }, + + _destroy: function() { + this.wrapper.remove(); + this.element.show(); + } + }); + })( jQuery ); diff --git a/portal/templates/onelab/onelab_registration_view.html b/portal/templates/onelab/onelab_registration_view.html index b9a61a52..d3de3a6b 100644 --- a/portal/templates/onelab/onelab_registration_view.html +++ b/portal/templates/onelab/onelab_registration_view.html @@ -30,10 +30,24 @@ {% csrf_token %}

- + +

Organization not listed? Request its addition now.

@@ -487,7 +501,7 @@ $(document).ready(function(){ {% if authorities %} {% for authority in authorities %} {% if authority.name %} - {value:"{{ authority.name }}",label:"{{authority.name}}"}, + {value:"{{ authority.authority_hrn }}",label:"{{authority.name}}"}, // show hrn if we don't have the name {% else %} {value:"{{ authority.authority_hrn }}",label:"{{authority.authority_hrn}}"}, @@ -498,6 +512,7 @@ $(document).ready(function(){ {% endif %} ]; // sorting the list + availableTags.sort(function(a,b){ var nameA=a.value.toLowerCase(), nameB=b.value.toLowerCase(); if (nameA < nameB) { @@ -509,15 +524,7 @@ $(document).ready(function(){ return 0; }); // auto-complete the form - $( "#authority_hrn" ).autocomplete({ - source: availableTags, - minLength: 0, - change: function (event, ui) { - if(!ui.item){ - jQuery("#authority_hrn").val(""); - } - } - }); + jQuery("#org_name").combobox(); $('[title!=""]').qtip(); $("form").validate(); $("form").submit(function() {