Commit df05b2bf authored by Dave Lane's avatar Dave Lane
Browse files

added admin interface for implementation-specific settings, added full...

added admin interface for implementation-specific settings, added full language support for all user visible text strings, bumped version to 2.0.0
parent d11c6366
input.error, span.description {
display: block;
}
.error {
color: #C60C0C;
margin-top: 0.3em;
line-height: 1.15em;
}
<?php
$bff_strings = array(
'supported_feeds_found' => __('We have identified the following supported feeds.', 'oeru-bff'),
'select_best_choice' => __('Please select the one you think the best choice:', 'oeru-bff'),
'entitled' => __('entitled', 'oeru-bff'),
'format' => __('Format', 'oeru-bff'),
'select_feed' => __('Select Feed', 'oeru-bff'),
'feed' => __('feed', 'oeru-bff'),
'selected' => __('selected', 'oeru-bff'),
'we_found_a_feed' => __('We found a feed', 'oeru-bff'),
'blog_feed_already_set_to' => __('blog feed already set to', 'oeru-bff'),
'existing_blog_feed' => __('existing blog feed', 'oeru-bff'),
'replace' => __('Replace', 'oeru-bff'),
'assign' => __('Assign', 'oeru-bff'),
'assign_blog_feed_to_any_courses' => __('You can assign this blog feed to any of your courses, or use it to replace any existing assignments:', 'oeru-bff'),
'all_your_blog_feeds_already_set_to_this_feed' => __('All of your blog feeds are already set to this feed! There\'s nothing you need to do. Well done!', 'oeru-bff'),
'ready' => __('Ready', 'oeru-bff'),
'updated_to' => __('updated to', 'oeru-bff'),
'updated_blog_feed_to' => __('updated blog feed to', 'oeru-bff'),
'success' => __('Success', 'oeru-bff'),
);
// see http://solislab.com/blog/5-tips-for-using-ajax-in-wordpress/
// and https://pippinsplugins.com/using-ajax-your-plugin-wordpress-admin/
var DEBUG = true; // set to false to disable debugging
function LOG() { if (DEBUG) { console.log.apply(this, arguments); }}
LOG('BFF-Admin DEBUG =', DEBUG); // only prints if DEBUG = true
jQuery(document).ready(function() {
LOG('bff admin:', bff_data);
var $ = jQuery;
var form = '#bff-settings-form';
// Form validation
$(form).validate({
defaults: {
debug: true,
},
rules: {
'organisation-name': {
required: true,
minlength: 2
}
}
});
// on load, disable the submit button until
// a child input of the form is altered, because until then,
// we have nothing to change.
$('#bff-status').html('Ready. Nothing changed yet...');
$('#bff-submit').attr('disabled', true);
// if an org code is set, reflect it in the details shown
code = $('#organisation-code').val();
LOG('#organisation-code', code);
if (code != '') {
if ($('.bff-partner option[value='+code+']').length > 0) {
$('.bff-partner').find('option[value='+code).prop('selected', true).change();
$('#organisation-prefix').prop('checked', false);
LOG('changed option with value ', code);
} else {
$('.bff-partner').find('option[value='+code+'-article]').prop('selected', true).change()
$('#organisation-prefix').prop('checked', true);
LOG('changed option with value '+code+'-article');
}
} else {
LOG('no #organisation code!');
}
// something in the form changed...
$(form).on('keyup change', function() {
LOG('this = ', this);
if ($(this).valid()) {
$('#bff-status').html('Settings changed...');
$('#bff-submit').attr('disabled', false);
} else {
$('#bff-status').html('Form has to be valid before submitting.');
$('#bff-submit').attr('disabled', true);
}
});
// if the partner is set, use the associated values
// to populate the form
$('.bff-partner').on('change', function() {
if (this.value === 'default') return;
codearray = this.value.split('-');
code = codearray[0];
article = false;
if (typeof codearray[1] != 'undefined' ) {
article = true;
}
fullname = name = $(this).find('option:selected').text();
if (article) {
name = name.replace('The ','');
}
LOG('value: ' + code + ', text: ' + name);
$('#organisation-code').prop('value', code);
$('#organisation-name').val(name);
LOG('article = ', article);
$('#organisation-prefix').prop('checked', article);
$(form).trigger('change');
});
// if a partner has been selected but the user then changes
// either the org name or prefix checkbox, reset the partner
// to default and remove the org code value.
$('#organisation-name, #organisation-prefix').on('input select', function() {
LOG('resetting partner to default');
$('.bff-partner').val('default');
if ($('#organisation-code').val() != '') {
LOG('set org-code to empty string');
$('#organisation-code').val('');
}
});
$(form).submit(function() {
LOG('in submit function');
checked = false;
if ($('#organisation-prefix').is(':checked')) {
LOG('checkbox is checked!');
checked = true;
}
$('#bff-status').html('Processing...');
$.ajax({
type: 'POST',
dataType: 'json',
url: bff_data.ajaxurl,
data: {
'action': 'bff_settings_submit',
'nonce': bff_data.nonce,
'site_id': bff_data.site_id,
'organisation_name': $.trim($('#organisation-name').val()),
'organisation_prefix': checked,
'organisation_code': $.trim($('#organisation-code').val()),
'support_forum': $.trim($('#support-forum-url').val()),
'support_blog': $.trim($('#support-blog-url').val())
},
success: function(data) {
var msg = '';
LOG('Success: data: ', data);
if (data.hasOwnProperty('success')) {
// strip links out
msg = data.message.replace(/<a[^>]*>[^<]*<\/a>/g, '');
console.log('Success msg', msg);
$('#bff-status').html(msg);
// disable the form until further changes are made
$('#bff-submit').attr('disabled', true);
} else if (data.hasOwnProperty('error')) {
msg = data.message;
LOG('message:', msg);
$('#bff-status').html(msg);
}
return true;
},
failure: function() {
LOG('Failure: data: ', data);
$('#bff-status').text('Error!');
}
});
// if nothing else returns this first, there was a problem...
return false;
});
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment