diff --git a/coinmanager/coinc/static/coinc/main.js b/coinmanager/coinc/static/coinc/main.js index 2b11a5d..8d442ae 100644 --- a/coinmanager/coinc/static/coinc/main.js +++ b/coinmanager/coinc/static/coinc/main.js @@ -267,11 +267,13 @@ $(document).ready(function() { let args = { data: data, - td: this - } + td: this } + + let name = $(this).find('div.special_name').html(); + let input = (name) ? {name: name} : null if ([201, 202, 203].includes(value) && data['exists']) { - let modal = new Modal('add_coin_name', add_coin_name, args); + let modal = new Modal('add_coin_name', add_coin_name, args, input); modal.show(); } else { add_coin_name(args); @@ -381,8 +383,7 @@ $(document).ready(function() { // modal #add_user $('#show_add_user').click(function() { - let args = ''; - let modal = new Modal('add_user', add_user, args); + let modal = new Modal('add_user', add_user); modal.show(); function add_user(args='', response='') { diff --git a/coinmanager/coinc/static/coinc/modules/modal.mjs b/coinmanager/coinc/static/coinc/modules/modal.mjs index 96f0cf9..2a71e05 100644 --- a/coinmanager/coinc/static/coinc/modules/modal.mjs +++ b/coinmanager/coinc/static/coinc/modules/modal.mjs @@ -21,15 +21,26 @@ /* create a modal dialog */ class Modal { - constructor(modal, callback, callback_arguments) { + constructor(div, callback, callback_arguments=null, input=null) { - this.modal = modal; + this.div = '#' + div; this.callback = callback; this.callback_arguments = callback_arguments; + this.input = input; + let self = this; - $('#' + this.modal + '_show') - .bind('click', {this: this}, function(event) { - event.data.this.show(); + if (this.input) { + $(this.div + ' input[type=text]').each(function() { + let name = $(this).prop('name'); + if (name in self.input) { + $(this).val(self.input[name]); + } + }); + } + + $(this.div + '_show') + .bind('click', function(event) { + self.show(); }); } @@ -37,51 +48,52 @@ class Modal { /* show the modal dialog */ show() { - $('#' + this.modal).fadeIn('fast'); + let self = this; + + $(this.div).fadeIn('fast'); /* close modal on click outside of modal */ $(document) - .bind('click', {this: this}, function(event) { - let scope = event.data.this - if ($('#' + scope.modal).is(':visible')) { - if ($(event.target).attr('id') === scope.modal) { - hide(scope.modal); + .bind('click', function(event) { + if ($(self.div).is(':visible')) { + if ($(event.target).attr('id') == self.div.substring(1)) { + hide(self.div); } } }); /* close modal on keypress ESC, send modal on keypress ENTER */ $(document) - .bind('keypress', {this: this}, function(event) { + .bind('keypress', function(event) { if (event.keyCode == 27) { - hide(event.data.this.modal); + hide(self.div); $(document).off('keypress'); } else if (event.keyCode == 13) { - event.data.this.submit(); + self.submit(); } }); /* close modal on button #_close */ - $('#' + this.modal + '_close') - .bind('click', {this: this}, function(event) { - hide(event.data.this.modal); + $(this.div + '_close') + .bind('click', function(event) { + hide(self.div); }); /* trigger callback on button #_action */ - $('#' + this.modal + '_action') - .bind('click', {this: this}, function(event) { - event.data.this.submit(); + $(this.div + '_action') + .bind('click', function(event) { + self.submit(); }); /* focus first input text element */ - $('#' + this.modal + ' input:text:visible:first').focus(); + $(this.div + ' input:text:visible:first').focus(); } /*submit modal */ submit() { let response = {}; - $('#' + this.modal + ' input[type=text]').each(function() { + $(this.div + ' input[type=text]').each(function() { response[$(this).attr('name')] = $(this).val(); }); this.callback(this.callback_arguments, response); @@ -90,17 +102,17 @@ class Modal { } /* hide the modal dialog */ -function hide(modal) { - $('#' + modal).fadeOut('fast'); +function hide(div) { + $(div).fadeOut('fast'); } /* detach all eventTypes */ -function detach(modal) { - hide(modal); - $('#' + modal + '_action').off('click'); - $('#' + modal + '_close').off('click'); +function detach(div) { + hide(div); + $(div + '_action').off('click'); + $(div + '_close').off('click'); $(document).off('keypress click'); - $('#' + modal + ' input:text:visible').each(function() { + $(div + ' input:text:visible').each(function() { $(this).val(''); }); } diff --git a/coinmanager/coinc/static/coinc/styles.css b/coinmanager/coinc/static/coinc/styles.css index ad566f4..432cbf4 100644 --- a/coinmanager/coinc/static/coinc/styles.css +++ b/coinmanager/coinc/static/coinc/styles.css @@ -327,9 +327,7 @@ div.found { /* special coins */ -div.special1_name, -div.special2_name, -div.special3_name { +div.special_name { display: none; height: 40px; width: 146px; diff --git a/coinmanager/coinc/templates/coinc/coin.html b/coinmanager/coinc/templates/coinc/coin.html index 0d41f6a..b210c3a 100644 --- a/coinmanager/coinc/templates/coinc/coin.html +++ b/coinmanager/coinc/templates/coinc/coin.html @@ -1,7 +1,7 @@
{{ marker }}
{% if name %} - {% if value == 201 %}
{{ name }}
{% endif %} - {% if value == 202 %}
{{ name }}
{% endif %} - {% if value == 203 %}
{{ name }}
{% endif %} + {% if value == 201 %}
{{ name }}
{% endif %} + {% if value == 202 %}
{{ name }}
{% endif %} + {% if value == 203 %}
{{ name }}
{% endif %} {% endif %}