Skip to content

Commit

Permalink
Fixed issue #10117: replaced dialog by modal and corrected js
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Dec 16, 2015
1 parent d2a4243 commit 89e0c3a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 49 deletions.
18 changes: 18 additions & 0 deletions application/views/admin/labels/_labelviewquickadd_view.php
@@ -0,0 +1,18 @@
<div class="modal fade" tabindex="-1" role="dialog" id='quickadd'>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title"><?php eT('Enter your labels:') ?></h4>
</div>
<div class="modal-body">
<textarea id='quickaddarea' name='quickaddarea' class='tipme' title='<?php eT('Enter one label per line. You can provide a code by separating code and label text with a semikolon or tab. For multilingual surveys you add the translation(s) on the same line separated with a semikolon or tab.') ?>' rows='20' cols='100' style='width:570px;'></textarea>
</div>
<div class="modal-footer button-list">
<button id='btnqareplace' type='button' class="btn btn-default"><?php eT('Replace') ?></button>
<button id='btnqainsert' type='button' class="btn btn-default"><?php eT('Add') ?></button>
<button id='btnqacancel' type='button' class="btn btn-warning"><?php eT('Cancel') ?></button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
4 changes: 3 additions & 1 deletion application/views/admin/labels/_labelviewtabcontent_view.php
Expand Up @@ -72,7 +72,9 @@
<?php $i++;?>

<div class="action-buttons">
<button class='btnquickadd btn btn-default' id='btnquickadd_<?php echo $i ?>' type='button' ><?php eT('Quick add...') ?></button>
<button type="button" id='btnquickadd_<?php echo $i ?>' class="btnquickadd btn btn-default btn-lg" data-toggle="modal" data-target="#quickadd">
<?php eT('Quick add...') ?>
</button>
</div>
<p>
<input type='submit' class='hidden' name='method' value='<?php eT("Save changes") ?>' id='saveallbtn_<?php echo $lslanguage ?>' />
Expand Down
18 changes: 4 additions & 14 deletions application/views/admin/labels/labelview_view.php
@@ -1,8 +1,11 @@
<script type='text/javascript'>
var duplicatelabelcode='<?php eT('Error: You are trying to use duplicate label codes.','js'); ?>';
var otherisreserved='<?php eT("Error: 'other' is a reserved keyword.",'js'); ?>';
var quickaddtitle='<?php eT('Quick-add subquestion or answer items','js'); ?>';
</script>

<!-- quick add popup -->
<?php $this->renderPartial("./labels/_labelviewquickadd_view", array()); ?>

<div class="col-sm-12 labels">
<h3 class="pagetitle"><?php eT("Labels") ?></h3>
<div class="row">
Expand Down Expand Up @@ -37,16 +40,3 @@
</div>
</div>
</div>

<div id='quickadd' style='display:none;'>
<div style='float:left;'>
<label for='quickaddarea'><?php eT('Enter your labels:') ?></label>
<br />
<textarea id='quickaddarea' name='quickaddarea' class='tipme' title='<?php eT('Enter one label per line. You can provide a code by separating code and label text with a semikolon or tab. For multilingual surveys you add the translation(s) on the same line separated with a semikolon or tab.') ?>' rows='30' cols='100' style='width:570px;'></textarea>
<p class='button-list'>
<button id='btnqareplace' type='button'><?php eT('Replace') ?></button>
<button id='btnqainsert' type='button'><?php eT('Add') ?></button>
<button id='btnqacancel' type='button'><?php eT('Cancel') ?></button>
</p>
</div>
</div>
60 changes: 26 additions & 34 deletions scripts/admin/labels.js
Expand Up @@ -19,6 +19,7 @@ $(document).on('click','[data-action="deletelabelset"]',function(event){
sendPost($(this).data('url'),'',['action','lid'],[$(this).data('action'),$('[name="lid"]').val()]);
}
});

$(document).ready(function(){
$('#btnDumpLabelSets').click(function(){
if ($('#labelsets > option:selected').size()==0)
Expand All @@ -44,21 +45,6 @@ $(document).ready(function(){
distance:2
});

$('#quickadd').dialog({
autoOpen: false,
modal: true,
width:600,
title: quickaddtitle
});

$('.btnquickadd').click(function(){
$('#quickadd').dialog('open');
});

$('#btnqacancel').click(function(){
$('#quickadd').dialog('close');
});


$('#btnqareplace').click(quickaddfunction);
$('#btnqainsert').click(quickaddfunction);
Expand Down Expand Up @@ -121,7 +107,6 @@ function quickaddfunction(){
}



$(lsrows).each(function(index,element){
code = undefined;

Expand All @@ -132,35 +117,37 @@ function quickaddfunction(){
k++;
}

event = {};
event.target = $(".btnaddanswer:last");
var retcode = add_label(event);

if(lsreplace)
{
if (index!=0 || (!lsreplace && $("div[id^='newedit']:not(:last) tbody>tr").length > 0)){
alert('ko');
event = {};
event.target = $(".btnaddanswer:last");

}
else{
var retcode = add_label();
}

event = {};
event.target = $(".btnaddanswer:last");
var retcode = add_label(event);
/*
if (index!=0 || (!lsreplace && $("div[id^='newedit']:not(:last) tbody>tr").length > 0)){
event = {};
event.target = $(".btnaddanswer:last");
var retcode = add_label(event);
}
else{
var retcode = add_label();
}
*/





// seems always undefined
if (typeof(code)!="undefined") {
$("#code_"+retcode).val(code);
}

$(".lslanguage").each(function(i){
console.log("input[name=title_"+$(this).val()+"_"+retcode+"]");
//console.log("input[name=title_"+$(this).val()+"_"+retcode+"]");
$("input[name=title_"+$(this).val()+"_"+retcode+"]").val(params[k]);
if (typeof(code)!="undefined" && i > 0) {
if (typeof(code)!="undefined" && i > 0)
{
$("#row_"+$(this).val()+"_"+retcode+" td:first").text(code);
}
k++;
Expand All @@ -169,7 +156,7 @@ function quickaddfunction(){

});
$("#quickaddarea").val('');
$('#quickadd').dialog('close');
$('#quickadd').modal('hide');
}


Expand Down Expand Up @@ -218,6 +205,7 @@ function add_label(event)
{
next_code='L001';
}

while ($('.answertable').find('input[value="'+next_code+'"]').length>0 && next_code!=$(event.target).closest('tr').find('.codeval').val())
{
next_code=getNextCode(next_code);
Expand All @@ -228,7 +216,8 @@ function add_label(event)
next_code='L001';
}

console.log(next_code);
//alert('nextcode: '+next_code);
console.log('nextcode: '+next_code);

var html = createNewLabelTR(true,true);

Expand Down Expand Up @@ -256,14 +245,17 @@ function add_label(event)
html = str_replace("###codeval###",next_code,html);
html = str_replace("###next###",randomid,html);

// Seems not to work
$(".not_first").each(function(index,element){

var temp_html = str_replace("###lang###",$(".lslanguage",element).val(),html);
if (row_id >= 0){
$($("tbody",element).children()[row_id]).after(temp_html);
}
else
{
alert(row_id );
$(".answertable tbody",$(element)).append(temp_html);
}

});

Expand Down

0 comments on commit 89e0c3a

Please sign in to comment.