File manager - Edit - /home/wwwroot/camplus.hk/master.camplus.hk/public_html/application/views/form-builder/js.php
Back
var cols = 2; var grid_count = 2; $(document).on('click','.addQuestion',function(){ var dis = $(this); var questionType = $(this).data('action'); <?php if(!empty($apprisal_form) && $apprisal_form==true):?> var isDelete = $(this).data('delete'); var overallUser = ''; var overallUserId = 0; if($(this).data('overalluser')!=undefined){ overallUser = $(this).data('overalluser'); overallUserId = $(this).data('overalluserid'); } <?php endif?> grid_count = 2; $.ajax({ url: <?php echo $url; ?>, type: 'POST', data: <?php echo $data;?>, success: function (data) { <?php if(!empty($apprisal_form) && $apprisal_form==true):?> if(dis.parents('.panel-body').find('.questionsContainer').find('.questionList').length == 0) dis.parents('.panel-body').find('.questionsContainer').html(data); else dis.parents('.panel-body').find('.questionsContainer .questionList:last').after(data); $( ".questionsContainer" ).sortable(); if(isDelete==1) dis.remove(); <?php else: ?> if($('.questionsContainer').find('.questionList').length == 0) $('.questionsContainer').html(data); else $('.questionsContainer .questionList:last').after(data); <?php endif; ?> initDt(); } }); }) $(document).on('click','.removeQuestion',function(){ $(this).parents('.questionList').remove(); }) $(document).on('click','.removeSection',function(){ $(this).parents('.panel').remove(); }) $(document).on('click','.hideSection',function(){ $(this).parents('.sections').attr('data-action','delete'); $(this).parents('.sections').hide(); }) $(document).on('click','.hideQuestion',function(){ $(this).parents('.questionList').attr('data-action','delete'); $(this).parents('.questionList').hide(); }) <?php if(empty($apprisal_form)):?> $(document).on('change','select[name="template_id"]',function(){ var id = $(this).val(); var current = $(this).data('current'); if($(this).val() == ''){ $('.questionsContainer').find('.questionList').each(function(i,v) { $(v).attr('data-action','delete'); $(v).hide(); }); return false; } $.ajax({ <?php if(!empty($oa) && $oa){?> url: BASE_URL + 'appraisal/overall_appraisals/getTemplate/', <?php }else{?> url: BASE_URL + 'appraisal/units/getTemplate/', <?php }?> type: 'POST', data: 'id='+id+'&year_id='+$('select[name="financial_year_id"]').val()+'¤t='+current<?php if($this->uri->segment(4)!=null) { echo "+'&unit='+" . $this->uri->segment(4);}?>, success: function (data) { $('.questionsContainer').find('.questionList').each(function(i,v) { if($(v).attr('data-action') == 'add') $(v).remove(); }); $('.questionsContainer .questionList').attr('data-action','delete'); $('.questionsContainer .questionList').hide(); if($('.questionsContainer').find('.questionList').length == 0) $('.questionsContainer').html(data); else $('.questionsContainer .questionList:last').after(data); initDt(); } }); }); <?php endif ?> <?php if(!empty($apprisal_form) && $apprisal_form==true):?> $(document).on('change','select[name="template_id[]"]',function(){ var dis = $(this); console.log(dis); if($(this).val() == ''){ dis.parents('.panel-body').find('.questionsContainer').html(''); return false; } $.ajax({ url: BASE_URL + 'appraisal/appraisal_form/getTemplate/', type: 'POST', data: 'id='+$(this).val(), success: function (data) { dis.parents('.panel-body').find('.questionsContainer').html(data); initDt(); tableSort(); $( ".questionsContainer" ).sortable(); } }); }); <?php endif ?> $(document).on('click','.editPopover',function(){ $('#EditPopover').modal('show'); var questionType = $(this).data('questiontype'); var str = ''; str += '<form role="form" action="#">'; str += '<div class="form-group">'; str += '<label for="question"><?php echo $this->lang->line("question");?></label>'; str += '<input type="text" class="form-control popoverQuestion" placeholder="" value="'+$(this).parents('.questionList').find('.qLabel').html()+'">'; str += '</div>'; if(questionType == 'SINGLE_LINE' || questionType == 'MULTIPLE_LINE' || questionType == 'NUMBER' || questionType == 'DATETIME' || questionType == 'DATE') { str += '<div class="form-group">'; str += '<label for="question"><?php echo $this->lang->line("Placeholder");?></label>'; str += '<input type="text" class="form-control popoverPlaceholder" placeholder="" value="'+$(this).parents('.questionList').find('.placeholder').attr('placeholder')+'">'; str += '<label for="question">token</label>'; str += '<input type="text" class="form-control popoverToken" ></input> '; str += '</div>'; } if(questionType == 'SUGGESTED') { str += '<div class="form-group">'; str += '<label for="option"><?php echo $this->lang->line("Options");?></label>'; str += '<textarea class="form-control popoverOptions" placeholder="" >' +$(this).parents('.questionList').find('.placeholder').attr('placeholder').replace(/,/g,'\n') + '</textarea>'; str += '<label for="question">token</label>'; str += '<input type="text" class="form-control popoverToken" value="'+$(this).parents('.questionList').find('.qToken').html()+'"></input>'; str += '</div>'; } if(questionType == 'LABEL') { var oldColor = $(this).parents(".questionList").find(".section_header").css('background-color'); var oldSize = $(this).parents(".questionList").find(".section_header").css('font-size'); str += '<div><label for="question"><?php echo $this->lang->line("color");?></label>'; str += '<input type="color" class="colorpicker" value="' + rgb2hex(oldColor) + '"></div>'; str += '<div><label for="question"><?php echo $this->lang->line("font_size");?></label>'; str += '<input type="number" class="fontsizepicker" min="10" max="40" value="' + oldSize.slice(0,-2) + '"></div>'; } if(questionType == 'RADIO_BUTTON') { var options = ''; var optArr = []; $(this).parents('.questionList').find('input:radio').each(function() { optArr.push($(this).val()); }); $.each(optArr,function(i,v){ options += v+'\n'; }) str += '<div class="form-group">'; str += '<label for="question"><?php echo $this->lang->line("Options");?></label>'; str += '<textarea class="form-control popoverOptions" placeholder="" >'+options+'</textarea>'; str += '</div>'; } if(questionType == 'CHECKBOX') { var options = ''; var optArr = []; $(this).parents('.questionList').find('.form-group input:checkbox').each(function() { optArr.push($(this).val()); }); $.each(optArr,function(i,v){ options += v+'\n'; }) str += '<div class="form-group">'; str += '<label for="question"><?php echo $this->lang->line("Options");?></label>'; str += '<textarea class="form-control popoverOptions" placeholder="" >'+options+'</textarea>'; str += '</div>'; } if(questionType == 'DROPDOWN') { var options = ''; var optArr = []; $(this).parents('.questionList').find('select option').each(function() { optArr.push($(this).val()); }); $.each(optArr,function(i,v){ options += v+'\n'; }) str += '<div class="form-group">'; str += '<label for="question"><?php echo $this->lang->line("Options");?></label>'; str += '<textarea class="form-control popoverOptions" placeholder="" >'+options+'</textarea>'; str += '</div>'; } if(questionType == 'TABLE') { var options = ''; var optArr = []; $(this).parents('.questionList').find('table tbody tr td').each(function() { optArr.push($(this).html()); }); $.each(optArr,function(i,v){ options += v+'\n'; }) str += '<div class="form-group">'; str += '<label for="question"><?php echo $this->lang->line("Options");?></label>'; str += '<textarea class="form-control popoverOptions" placeholder="" >'+options+'</textarea>'; str += '</div>'; } if(questionType == 'GRID') { grid_count = 2; str += '<div class="form-group">'; str += '<label for="question"><?php echo $this->lang->line("table");?> <?php echo $this->lang->line("title");?></label>'; str += '<input type="text" class="form-control tableTitle" placeholder="" value="'+$(this).parents('.questionList').find('.gridTable > thead > tr:eq(0) > th:first').html()+'">'; str += '</div>'; } str += '<div class="form-group">'; str += '<label for="question"><?php echo $this->lang->line("description");?></label>'; str += '<textarea class="form-control description" placeholder="" >'+$(this).parents('.questionList').find('.help-block').html()+'</textarea>'; str += '</div>'; str += '<div class="form-actions">' +'<button type="button" class="btn red cancelPopover btn-sm" style="margin-right:10px">Cancel</button>' +'<button type="button" class="btn blue btn-sm savePopover" data-questiontype="'+questionType+'" data-index="'+$(this).closest('.questionsContainer').find('.questionList').index($(this).parents('.questionList'))+'">Save</button>' +'</div>'; str += '</form>'; //$('.popover-content').html(str); $('#EditPopover').find('.modal-body').html(str); }) $(document).on('click','.cancelPopover',function(){ $('#EditPopover').modal('hide'); }) $(document).on('click','.savePopover',function(){ if(!checkPopover()) return false; var questionType = $(this).data('questiontype'); var ind = $(this).data('index'); var token = $('.popover-content').find('.popoverToken').val(); var question = $('.popover-content').find('.popoverQuestion').val(); var placeholder = $('.popover-content').find('.popoverPlaceholder').val(); var description = $('.popover-content').find('.description').val(); if(questionType == 'SINGLE_LINE' || questionType == 'MULTIPLE_LINE' || questionType == 'NUMBER' || questionType == 'DATETIME' || questionType == 'DATE' || questionType == 'TIME') { $('.questionsContainer').find('.questionList:eq('+ind+')').find('.placeholder').attr('placeholder',placeholder); $('.questionsContainer').find('.questionList:eq('+ind+')').find('.qToken').html(token); } if(questionType == 'SUGGESTED') { console.log(token); var options = ''; var lines = $('.popover-content').find('.popoverOptions').val().replace(/\n/g,","); $('.questionsContainer').find('.questionList:eq('+ind+')').find('.placeholder').attr('placeholder',lines); $('.questionsContainer').find('.questionList:eq('+ind+')').find('.qToken').html(token); } if(questionType == 'RADIO_BUTTON') { var options = ''; var lines = $('.popover-content').find('.popoverOptions').val().split(/\n/); var texts = []; for (var i=0; i < lines.length; i++) { // only push this line if it contains a non whitespace character. if (/\S/.test(lines[i])) { texts.push($.trim(lines[i])); } } $.each(texts,function(i,v){ options += '<label><input type="radio" name="optionsRadios" value="'+v+'"> '+v+'</label>'; }); $('.questionsContainer').find('.questionList:eq('+ind+')').find('.radio-list').html(options); } if(questionType == 'LABEL') { var color = $('.popover-content').find('.colorpicker').val(); var size = $('.popover-content').find('.fontsizepicker').val(); $('.questionsContainer').find('.questionList:eq('+ind+')').find('.qLabel').css('background-color', color); $('.questionsContainer').find('.questionList:eq('+ind+')').find('.qLabel').css('font-size', size+"px"); } if(questionType == 'CHECKBOX') { var options = ''; var lines = $('.popover-content').find('.popoverOptions').val().split(/\n/); var texts = []; for (var i=0; i < lines.length; i++) { // only push this line if it contains a non whitespace character. if (/\S/.test(lines[i])) { texts.push($.trim(lines[i])); } } $.each(texts,function(i,v){ options += '<label><input type="checkbox" name="optionsCheckbox" value="'+v+'"> '+v+'</label>'; }); $('.questionsContainer').find('.questionList:eq('+ind+')').find('.checkbox-list').html(options); } if(questionType == 'DROPDOWN') { var options = ''; var lines = $('.popover-content').find('.popoverOptions').val().split(/\n/); var texts = []; for (var i=0; i < lines.length; i++) { // only push this line if it contains a non whitespace character. if (/\S/.test(lines[i])) { texts.push($.trim(lines[i])); } } $.each(texts,function(i,v){ options += '<option value="'+v+'"> '+v+'</option>'; }); $('.questionsContainer').find('.questionList:eq('+ind+')').find('select').html(options); } if(questionType == 'TABLE') { var options = ''; var lines = $('.popover-content').find('.popoverOptions').val().split(/\n/); var texts = []; for (var i=0; i < lines.length; i++) { // only push this line if it contains a non whitespace character. if (/\S/.test(lines[i])) { texts.push($.trim(lines[i])); } } $.each(texts,function(i,v){ options += '<td> '+v+'</td>'; }); $('.questionsContainer').find('.questionList:eq('+ind+')').find('table tbody tr').html(options); } if(questionType == 'GRID') { var tableTitle = $('.popover-content').find('.tableTitle').val(); $('.questionsContainer').find('.questionList:eq('+ind+')').find('.gridTable > thead > tr:eq(0) > th:first').html(tableTitle); } $('.questionsContainer').find('.questionList:eq('+ind+')').find('.qLabel').html(question); $('.questionsContainer').find('.questionList:eq('+ind+')').find('.help-block').html(description); $('#EditPopover').modal('hide'); }) $(document).on('click','.addGridQuestion',function(){ var totalLength = $(this).parents('.questionList').find('table tr').length; console.log('addGridQuestion clicked with length ' . totalLength ); console.log($(this)); var row_count = parseInt($(this).parents('.questionList').find('.gridTable tr').length)-1; if(row_count > 0) { if($(this).parents('.questionList').find('.gridTable tbody tr:last').find('textarea[name="gridQ"]').length > 0) { if($.trim($(this).parents('.questionList').find('.gridTable tbody tr:last').find('textarea[name="gridQ"]').val()) == '' || (!isNaN($.trim($(this).parents('.questionList').find('.gridTable tbody tr:last').find('input[name="gridN"]').val())) && $.trim($(this).parents('.questionList').find('.gridTable tbody tr:last').find('input[name="gridN"]').val()) <= 0)) { alert('Please fill above row'); return false; } } } if($(this).parents('.questionList').find('.gridTable tbody tr:last').find('textarea[name="gridQ"]').length > 0) { alert('First Save above row'); return false; } var str = ''; var g_count = parseInt($(this).parents('.questionList').find('.gridTable tr th').length)-4; str += '<tr><td><textarea type="text" name="gridQ" placeholder="Question" class="form-control"></textarea></td><td colspan="'+g_count+'"></textarea><input type="number" name="gridN" placeholder="Number of options" class="form-control"></td><td><input type="checkbox" name="gridR" ></td><td><input type="checkbox" name="gridNA" ></td><td><button type="button" class="btn btn-xs blue saveGridQ"><i class="fa fa-save"></i></button><button type="button" class="btn btn-xs red removeGridQ"><i class="fa fa-times"></i></button></td></tr>'; $(this).parents('.questionList').find('.gridTable').append(str); }) $(document).on('click','.removeGridQ',function(){ $(this).parents('tr').remove(); }) /*$(document).on('keyup','textarea[name="gridQ"]',function(e){ var textVal = $(this).val(); if(e.which == 13) { $(this).parents('td').html(textVal); } })*/ $(document).on('click','.saveGridQ',function(e){ var textVal = 0; if(isNaN(parseInt($(this).parents('tr').find('input[name="gridN"]').val()))) textVal = 0; else textVal = parseInt($(this).parents('tr').find('input[name="gridN"]').val()); //console.log(textVal); if($(this).parents('tr').find('textarea[name="gridQ"]').length > 0 && (textVal <= 0 || $.trim($(this).parents('tr').find('textarea[name="gridQ"]').val()) == '')) { alert('Please fill this row correctly'); return false; } if($(this).parents('tr').find('textarea[name="gridQ"]').length > 0 && $.trim($(this).parents('tr').find('textarea[name="gridQ"]').val()) != '') { $(this).parents('tr').find('textarea[name="gridQ"]').parents('td').html($(this).parents('tr').find('textarea[name="gridQ"]').val()); } var gridTds = ''; var tableStr = ''; var rowCount = $(this).parents('table tbody').find('tr').length - 1; var dis = $(this); var new_dis =dis.parents('table'); var gCount = $(this).parents('table tbody').find('tr:first td').length - 4; if(textVal > gCount) { var i = 0; dis.parents('.questionList').find('table tr').each(function(i,v) { if(i==0){ tableStr += '<thead><tr><th>'+$(v).find('th:first').html()+'</th>'; for(j=1;j<=textVal;j++) { tableStr += '<th>'+j+'</th>'; } tableStr += '<th>Remark</th>'; tableStr += '<th>N/A</th>'; tableStr += '<th> </th>'; tableStr += '</tr></thead>'; } else { tableStr += '<tr>'; tableStr += '<td>'+$(v).find('td:first').html()+'</td>'; if($(v).find('input[name="radioBox"]').length>0) { for(j=1;j<=textVal;j++) { if($(v).find('input[name="radioBox"]').length>=j){ var sel = ''; //console.log($(v).find('input[name="radioBox"]')); if($(v).find('td:eq('+parseInt(j)+')').find('input[name="radioBox"]:checked').length>0) sel = 'checked="checked"'; tableStr += '<td><input type="checkbox" name="radioBox" value="'+j+'" '+sel+'></td>'; } else tableStr += '<td></td>'; } } else { for(j=1;j<=textVal;j++) { tableStr += '<td><input type="checkbox" name="radioBox" value="'+j+'"></td>'; } } tableStr += '<td>'+$(v).find('input[name="gridR"]').parent().html()+'</td>'; tableStr += '<td>'+$(v).find('input[name="gridNA"]').parent().html()+'</td>'; tableStr += '<td><button type="button" class="btn btn-xs green editGridQ"><i class="fa fa-edit"></i></button><button type="button" class="btn btn-xs red removeGridQ"><i class="fa fa-times"></i></button></td>'; tableStr += '</tr>'; } i++; }); grid_count = textVal; dis.parents('table').html(tableStr); tableSort(); //$(this).parents('table').find('.optionStr').html(optionStr); } else { /*if(textVal == gCount) { var tr = '<th>'+dis.parents('table').find('thead tr th:first').html()+'</th>'; for(j=1;j<=textVal;j++) { tr += '<th>'+j+'</th>'; } tr += '<th>Remark</th>'; tr += '<th>N/A</th>'; tr += '<th> </th>'; dis.parents('table').find('tr:first').html(tr); }*/ var v = dis.parents('tr'); tableStr += '<tr>'; tableStr += '<td>'+$(v).find('td:first').html()+'</td>'; for(j=1;j<=gCount;j++) { if(textVal>=j) tableStr += '<td><input type="checkbox" name="radioBox" value="'+j+'"></td>'; else tableStr += '<td></td>'; } tableStr += '<td>'+$(v).find('input[name="gridR"]').parent().html()+'</td>'; tableStr += '<td>'+$(v).find('input[name="gridNA"]').parent().html()+'</td>'; tableStr += '<td><button type="button" class="btn btn-xs green editGridQ"><i class="fa fa-edit"></i></button><button type="button" class="btn btn-xs red removeGridQ"><i class="fa fa-times"></i></button></td>'; tableStr += '</tr>'; dis.parents('table').append(tableStr); dis.parents('tr').remove(); tableSort(); } }) $(document).on('click','input[type="checkbox"]',function(){ if ($(this).is(':checked')) $(this).attr('checked','checked'); else $(this).removeAttr('checked'); }) $(document).on('click','.editGridQ',function(){ var str = ''; var g_count = parseInt($(this).parents('tr').find('td').length)-4; str += '<td><textarea type="text" name="gridQ" placeholder="Question" class="form-control" >'+$(this).parents('tr').find('td:first').html()+'</textarea></td><td colspan="'+g_count+'"><input type="number" name="gridN" placeholder="Number of options" class="form-control" value="'+$(this).parents('tr').find('input[name=radioBox]').length+'"></td><td>'+$(this).parents('tr').find('input[name="gridR"]').parent().html()+'</td><td>'+$(this).parents('tr').find('input[name="gridNA"]').parent().html()+'</td><td><button type="button" class="btn btn-xs blue saveGridQ"><i class="fa fa-save"></i></button><button type="button" class="btn btn-xs red removeGridQ"><i class="fa fa-times"></i></button></td>'; //console.log(str); $(this).parents('tr').html(str); }) function rgb2hex(rgb) { //change r g b array to hex rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); function hex(x) { return ("0" + parseInt(x).toString(16)).slice(-2); } return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); } function checkPopover() { var counter = 0; if($('.popoverQuestion').length > 0) { if($.trim($('.popoverQuestion').val()) == '') { counter = 0; $('.popover-content').find('form').before('<label class="error">* Please fill required fields</label>'); return false; } else counter++; } if($('.popoverPlaceholder').length > 0) { if($.trim($('.popoverPlaceholder').val()) == '') { counter = 0; $('.popover-content').find('form').before('<label class="error">* Please fill required fields</label>'); return false; } else counter++; } if($('.popoverOptions').length > 0) { if($.trim($('.popoverOptions').val()) == '') { counter = 0; $('.popover-content').find('form').before('<label class="error">* Please fill required fields</label>'); return false; } else counter++; } if(counter > 0) return true; }
| ver. 1.4 |
Github
|
.
| PHP 7.2.34 | Generation time: 0.2 |
proxy
|
phpinfo
|
Settings