Skip to content

Commit

Permalink
added option to set default result and email template
Browse files Browse the repository at this point in the history
  • Loading branch information
zubairraeen committed Feb 19, 2024
1 parent 1d9e62f commit 02d301a
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 41 deletions.
10 changes: 7 additions & 3 deletions css/qsm-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -512,20 +512,23 @@ span.qsm-quiz-name {
background: #F8F9F9;
padding: 10px;
position: relative;
border: 1px solid #dfd4d4;
}
.qsm-result-condition-title,
.qsm-email-condition-title {
font-size: 16px;
display: block;
margin-bottom: 7px;
}
.qsm-result-condition-mode,
.qsm-email-condition-mode {
margin-bottom: 15px;
}
.results-page-condition .qsm-result-condition-container select, .qsm_tab_content .results-page-condition .qsm-result-condition-container input[type="text"], .email-condition .qsm-email-condition-container select, .qsm_tab_content .email-condition .qsm-email-condition-container input[type="text"] {
.results-page-condition select, .qsm_tab_content .results-page-condition .qsm-result-condition-container input[type="text"], .email-condition select, .qsm_tab_content .email-condition .qsm-email-condition-container input[type="text"] {
min-width: auto;
width: 100%;
border-radius: 4px;
border-color: #1e1e1e;
border-color: #ccc;
}
.results-page-condition .qsm-result-condition-container, .email-condition .qsm-email-condition-container {
display: flex;
Expand All @@ -538,7 +541,8 @@ span.qsm-quiz-name {
transition-duration: 200ms;
position: absolute;
right: 0;
top: 10px;
top: 8px;
color: #d63638;
}
.delete-condition-button:hover {
transform: scale(1.1);
Expand Down
46 changes: 27 additions & 19 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ if(current_id == 'qsm_variable_text'){ jQuery(".current_variable")[0].click();}
}
}
}

//Show autocomplete modal
function showAutocomplete( editor, clear =false ) {
removeAutocomplete( editor, clear );
Expand All @@ -1242,7 +1242,7 @@ if(current_id == 'qsm_variable_text'){ jQuery(".current_variable")[0].click();}
} else {
qsm_search = '';
}

if ( 0 < newCommand.length ) {
let var_group = [];
newCommand.forEach( function( command ) {
Expand All @@ -1253,7 +1253,7 @@ if(current_id == 'qsm_variable_text'){ jQuery(".current_variable")[0].click();}
item_group.className = 'qsm-autocomplete-item-group';
item_group.textContent = command.group;
autocomplete.appendChild(item_group);
}
}
//Add Item
var item = document.createElement('div');
item.className = 'qsm-autocomplete-item';
Expand All @@ -1265,7 +1265,7 @@ if(current_id == 'qsm_variable_text'){ jQuery(".current_variable")[0].click();}
}
//editor.insertContent( command.description );
editor.execCommand('mceInsertContent', false, '<span class="qsm-var-wrapper" >'+command.value+'</span> ' );

autocomplete.remove();
editor.getContainer().setAttribute('qsm_search', '');
editor.qsmShowAutocomplete = false;
Expand Down Expand Up @@ -1293,16 +1293,16 @@ if(current_id == 'qsm_variable_text'){ jQuery(".current_variable")[0].click();}
}
if ( true === clear ) {
var qsm_search = editor.getContainer().getAttribute('qsm_search');
if ( 'undefined' !== typeof qsm_search && null !== qsm_search && '' !== qsm_search ) {
if ( 'undefined' !== typeof qsm_search && null !== qsm_search && '' !== qsm_search ) {
editor.getContainer().setAttribute('qsm_search', '');
}
}
editor.qsmShowAutocomplete = false;
}

//on keydowm inside editor
editor.on('keydown', function(e) {

if (e.keyCode === 191 && e.ctrlKey === false && e.altKey === false && e.shiftKey === false) {
// "/" key pressed, trigger autocomplete
showAutocomplete( editor, true );
Expand All @@ -1326,13 +1326,13 @@ if(current_id == 'qsm_variable_text'){ jQuery(".current_variable")[0].click();}
qsm_search += e.key;
}
editor.getContainer().setAttribute('qsm_search', qsm_search);

showAutocomplete(editor);
}

}
}

});
});
}
Expand Down Expand Up @@ -1630,12 +1630,14 @@ var QSMContact;
} else {
email_content = $(this).find('.email-template').val()
}
let default_mark = $(this).find('.qsm-mark-as-default:checked').length ? $(this).find('.qsm-mark-as-default:checked').val() : false;
email = {
'conditions': [],
'to': $(this).find('.qsm-to-email').val(),
'subject': $(this).find('.qsm-email-subject').val(),
'content': email_content,
'replyTo': $(this).find('.reply-to').prop('checked'),
'default_mark': default_mark,
};
$(this).find('.email-condition').each(function () {
email.conditions.push({
Expand Down Expand Up @@ -1687,7 +1689,7 @@ var QSMContact;
.done(function (emails) {
$('#qsm_emails').find('.qsm-spinner-loader').remove();
emails.forEach(function (email, i, emails) {
QSMAdminEmails.addEmail(email.conditions, email.to, email.subject, email.content, email.replyTo);
QSMAdminEmails.addEmail(email.conditions, email.to, email.subject, email.content, email.replyTo, email.default_mark);
});
QSMAdmin.clearAlerts();
})
Expand Down Expand Up @@ -1722,10 +1724,10 @@ var QSMContact;
newCondition: function ($email) {
QSMAdminEmails.addCondition($email, 'quiz', '', 'score', 'equal', 0);
},
addEmail: function (conditions, to, subject, content, replyTo) {
addEmail: function (conditions, to, subject, content, replyTo, default_mark = false) {
QSMAdminEmails.total += 1;
var template = wp.template('email');
$('#qsm_emails').append(template({ id: QSMAdminEmails.total, to: to, subject: subject, content: content, replyTo: replyTo }));
$('#qsm_emails').append(template({ id: QSMAdminEmails.total, to: to, subject: subject, content: content, replyTo: replyTo, default_mark: default_mark }));
conditions.forEach(function (condition, i, conditions) {
QSMAdminEmails.addCondition(
$('.qsm-email:last-child'),
Expand Down Expand Up @@ -1803,7 +1805,7 @@ var QSMContact;
event.preventDefault();
QSMAdminEmails.saveEmails();
});
$('#qsm_emails').on('click', '.new-condition', function (event) {
$('#qsm_emails').on('click', '.qsm-new-condition', function (event) {
event.preventDefault();
$page = $(this).closest('.qsm-email');
QSMAdminEmails.newCondition($page);
Expand Down Expand Up @@ -3644,11 +3646,14 @@ var import_button;
var pages = [];
var page = {};
var redirect_value = '';
let default_mark = false;
$('.results-page').each(function () {
default_mark = $(this).find('.qsm-mark-as-default:checked').length ? $(this).find('.qsm-mark-as-default:checked').val() : false;
page = {
'conditions': [],
'page': wp.editor.getContent($(this).find('.results-page-template').attr('id')),
'redirect': false,
default_mark: default_mark,
};
redirect_value = $(this).find('.results-page-redirect').val();
if ('' != redirect_value) {
Expand Down Expand Up @@ -3703,7 +3708,7 @@ var import_button;
.done(function (pages) {
$('#results-pages').find('.qsm-spinner-loader').remove();
pages.forEach(function (page, i, pages) {
QSMAdminResults.addResultsPage(page.conditions, page.page, page.redirect);
QSMAdminResults.addResultsPage(page.conditions, page.page, page.redirect, page.default_mark);
});
QSMAdmin.clearAlerts();
})
Expand Down Expand Up @@ -3739,10 +3744,10 @@ var import_button;
newCondition: function ($page) {
QSMAdminResults.addCondition($page, 'quiz', '', 'score', 'equal', 0);
},
addResultsPage: function (conditions, page, redirect) {
addResultsPage: function (conditions, page, redirect, default_mark = false) {
QSMAdminResults.total += 1;
var template = wp.template('results-page');
$('#results-pages').append(template({ id: QSMAdminResults.total, page: page, redirect: redirect }));
$('#results-pages').append(template({ id: QSMAdminResults.total, page: page, redirect: redirect, default_mark: default_mark }));
conditions.forEach(function (condition, i, conditions) {
QSMAdminResults.addCondition(
$('.results-page:last-child'),
Expand Down Expand Up @@ -3790,7 +3795,7 @@ var import_button;
let result_page = jQuery(this).closest("header").next("main");
let conditions = [];
let redirect_value = result_page.find('.results-page-redirect').val();
let page = wp.editor.getContent( result_page.find('.results-page-template').attr('id') );
let page = wp.editor.getContent(result_page.find('.results-page-template').attr('id'));
result_page.find('.results-page-condition').each(function () {
conditions.push({
'category': $(this).find('.results-page-condition-category').val(),
Expand All @@ -3807,7 +3812,7 @@ var import_button;
event.preventDefault();
QSMAdminResults.saveResults();
});
$('#results-pages').on('click', '.new-condition', function (event) {
$('#results-pages').on('click', '.qsm-new-condition', function (event) {
event.preventDefault();
$page = $(this).closest('.results-page');
QSMAdminResults.newCondition($page);
Expand All @@ -3826,6 +3831,9 @@ var import_button;
});
}
}
jQuery(document).on('click', '.qsm-mark-as-default', function () {
jQuery('.qsm-mark-as-default').not(jQuery(this)).prop('checked', false);
})
function qsmHandleConditionChange(containerClass, extraCategoryClass, operatorClass, criteriaClass, defaultValueClass) {
jQuery(document).on('change', '.' + containerClass + '-category', function () {
let container = jQuery(this).closest('.' + containerClass);
Expand Down
2 changes: 1 addition & 1 deletion mlw_quizmaster2.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public function qsm_admin_scripts_style( $hook ) {
'questions_not_found' => __("Question not found!", 'quiz-master-next'),
'add_more' => __("Add", 'quiz-master-next'),
'_X_validation_fails' => __("Please enter an appropriate value for 'X'", 'quiz-master-next'),
'qsm_variables' => function_exists( 'qsm_text_template_variable_list' ) ? qsm_text_template_variable_list() : ''
'qsm_variables' => function_exists( 'qsm_text_template_variable_list' ) ? qsm_text_template_variable_list() : '',
);
$qsm_admin_messages = apply_filters( 'qsm_admin_messages_after', $qsm_admin_messages );
wp_localize_script( 'qsm_admin_js', 'qsm_admin_messages', $qsm_admin_messages );
Expand Down
14 changes: 10 additions & 4 deletions php/admin/options-page-email-tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,15 @@ function qsm_options_emails_tab_template() {
<header class="qsm-email-header">
<strong><?php esc_html_e( 'Email Template ', 'quiz-master-next' ); ?> {{data.id}}</strong>
<div class="qsm-template-btn-group">
<button class="qsm-delete-email-button"><span class="dashicons dashicons-trash"></span></button>
<button class="qsm-duplicate-email-template-button"><span class="dashicons dashicons-admin-page"></span></button>
<button class="qsm-toggle-email-template-button"><span class="dashicons dashicons-arrow-down-alt2"></span></button>
<label class="qsm-template-mark-as-default">
<input type="checkbox" name="qsm_mark_as_default" value="{{data.id}}" <# if( undefined != data.default_mark && data.default_mark == data.id ) { #> checked <# } #> class="qsm-mark-as-default"/>
<?php esc_html_e( 'Mark as default', 'quiz-master-next' ); ?>
</label>
<div class="qsm-actions-link-box">
<a href="javascript:void(0)" class="qsm-delete-email-button"><span class="dashicons dashicons-trash"></span></a>
<a href="javascript:void(0)" class="qsm-duplicate-email-template-button"><span class="dashicons dashicons-admin-page"></span></a>
<a href="javascript:void(0)" class="qsm-toggle-email-template-button"><span class="dashicons dashicons-arrow-down-alt2"></span></a>
<div>
<div>
</header>
<main class="qsm-email-content">
Expand All @@ -186,7 +192,7 @@ function qsm_options_emails_tab_template() {
<div class="email-when-conditions">
<!-- Conditions go here. Review template below. -->
</div>
<a class="new-condition" href="javascript:void(0);"><span class="dashicons dashicons-plus-alt2"></span><?php esc_html_e( 'Add condition', 'quiz-master-next' ); ?></a>
<a class="qsm-new-condition qsm-block-btn qsm-dashed-btn" href="javascript:void(0);">+<?php esc_html_e( 'Add condition', 'quiz-master-next' ); ?></a>
</div>
<div class="email-show">
<div class="email-content-header">
Expand Down
16 changes: 11 additions & 5 deletions php/admin/options-page-results-page-tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,15 @@ function qsm_options_results_tab_template(){
<header class="results-page-header">
<strong><?php esc_html_e( 'Result Page ', 'quiz-master-next' ); ?> {{data.id}}</strong>
<div class="qsm-template-btn-group">
<button class="qsm-delete-result-button"><span class="dashicons dashicons-trash"></span></button>
<button class="qsm-duplicate-result-page-button"><span class="dashicons dashicons-admin-page"></span></button>
<button class="qsm-toggle-result-page-button"><span class="dashicons dashicons-arrow-down-alt2"></span></button>
<label class="qsm-template-mark-as-default">
<input type="checkbox" name="qsm_mark_as_default" value="{{data.id}}" <# if( undefined != data.default_mark && data.default_mark == data.id ) { #> checked <# } #> class="qsm-mark-as-default"/>
<?php esc_html_e( 'Mark as default', 'quiz-master-next' ); ?>
</label>
<div class="qsm-actions-link-box">
<a href="javascript:void(0)" class="qsm-delete-result-button"><span class="dashicons dashicons-trash"></span></a>
<a href="javascript:void(0)" class="qsm-duplicate-result-page-button"><span class="dashicons dashicons-admin-page"></span></a>
<a href="javascript:void(0)" class="qsm-toggle-result-page-button"><span class="dashicons dashicons-arrow-down-alt2"></span></a>
<div>
<div>
</header>
<main class="results-page-content">
Expand All @@ -216,7 +222,7 @@ function qsm_options_results_tab_template(){
<div class="results-page-when-conditions">
<!-- Conditions go here. Review template below. -->
</div>
<a class="new-condition" href="javascript:void(0);"><span class="dashicons dashicons-plus-alt2"></span><?php esc_html_e( 'Add condition', 'quiz-master-next' ); ?></a>
<a class="qsm-new-condition qsm-block-btn qsm-dashed-btn" href="javascript:void(0);">+ <?php esc_html_e( 'Add condition', 'quiz-master-next' ); ?></a>
</div>
<div class="results-page-show">
<div class="results-page-content-header">
Expand All @@ -236,7 +242,7 @@ function qsm_options_results_tab_template(){
<script type="text/template" id="tmpl-results-page-condition">
<div class="results-page-condition">
<div class="qsm-result-condition-mode">
<span class="qsm-result-condition-title"><?php esc_html_e( 'Select Mode', 'quiz-master-next' ); ?>:</span>
<label class="qsm-result-condition-title"><?php esc_html_e( 'Select Mode', 'quiz-master-next' ); ?>:</label>
<select class="results-page-condition-category">
<option value="quiz" <# if (data.category == 'quiz' || data.category == '') { #>selected<# } #>><?php esc_html_e( 'Quiz', 'quiz-master-next' ); ?></option>
<?php if ( ! empty( $categories ) ) {
Expand Down
Loading

0 comments on commit 02d301a

Please sign in to comment.