{% extends "base.html" %} {% import "macro/M_input.macro" as M_input %} {% import "macro/block.macro" as Block %} {% if row['id'] | default("", true) == "" %} {% set title = "Nouveau Bloc" %} {% else %} {% set title = "Modifier Bloc" %} {% endif %} {% set dash_color = dashboard.color %} {% block actions %} {% endblock %} {% block content %}
{{ M_input.select_block_type( "block_type", current=row['block_type'] ) | safe }}
{{ M_input.select_color( "color", current=row['color'] ) | safe }}
{{ M_input.select_color( "colortext", current=row['color_text'] ) | safe }}
{{ M_input.select_icon( "icon", current=row['icon'] ) | safe }}
{# To do: configure the History-View (if it applies) #} {# To do: configure the block parameters (python dictionnary) within a TextArea #} {# Submit button #}
{% endblock %} {% block javascript %} $(function() { $("#source").on('change', function() { console.debug( 'source changed' ); loadTopics(); }); }); function loadTopics( ) { // reload the content of topics list bases on the selection of the source runningRequest = true; // create an url like /source/__/topics where __ must still be // replaced var baseUrl = '{{ url_for('source_topics', source_name='__') }}'; request = $.ajax({ type: 'GET', url: baseUrl.replace( '__', $('#source').val() ), success: function( data ){ console.debug('get Ajax response'); if ( !$.isEmptyObject(data)) { // return [ {topic:x, history:y}, ... ] console.debug( 'get a result' ); var select = $('#topic'); select.empty(); select.append( $(""). attr("disabled", "disabled"). attr("selected","selected"). text("Choisir un topic") ); for( var value in data ){ console.debug( "Add value "+data[value]['topic'] ); select.append( $(""). attr("value", data[value]['topic']). text( data[value]['topic'] ) ); } // update the content (previously .material_select() ) select.formSelect(); } else { console.error( 'AJAX: contenu vide!' ); M.toast({html: 'AJAX: contenu vide!', classes:'red'}); } }, complete: function(){ runningRequest = false; }, error: function (xhr, ajaxOptions, thrownError) { console.error( 'AJAX Error! Status:'+ xhr.status ); console.error( thrownError ); M.toast({html: 'Erreur AJAX!
Status:'+xhr.status+'
Message:'+thrownError, displayLength : 10000, classes:'red'}); } }) } function checkSubmit(){ var bError = false; if ( $("#title").val().trim().length == 0 ){ M.toast( { html: 'Le bloc doit avoir un titre', classes : 'red' } ); bError = true; } if ( !( $("#block_type").val() ) ){ M.toast( { html: 'Le bloc doit avoir un type', classes : 'red' } ); bError = true; } if ( !( $("#source").val() ) ){ M.toast( { html: 'Le bloc doit avoir une source de donnée', classes : 'red' } ); bError = true; } if ( !( $("#topic").val() ) ){ M.toast( { html: 'Le bloc doit avoir un topic', classes : 'red' } ); bError = true; } return !(bError); } {% endblock %}