Commit 080e4c2b authored by Robert Lyon's avatar Robert Lyon Committed by Cecilia Vela Gurovic
Browse files

Bug 1796600: Getting progress meter to display again



Getting it to flow more smoothly as well

Note: does not fix copy page to existing group members as that form
breaks horible when submitting as js

behatnotneeded

Change-Id: Icbf437990ae06fc717199b6735007d9dcb2c885a
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 5ce877c0
......@@ -35,6 +35,10 @@ $EDITROLES = group_get_editroles_options();
$form = array(
'name' => 'uploadcsv',
'jsform' => true,
'jssuccesscallback' => 'pmeter_success',
'jserrorcallback' => 'pmeter_error',
'presubmitcallback' => 'pmeter_presubmit',
'elements' => array(
'institution' => get_institution_selector(),
'file' => array(
......@@ -120,7 +124,7 @@ function uploadcsv_validate(Pieform $form, $values) {
$i = ($csvgroups->get('headerExists')) ? ($key + 2) : ($key + 1);
// In adding 5000 groups, this part was approx 10% of the wall time.
if (!($key % 25)) {
if (!($key % 5)) {
set_progress_info('uploadgroupscsv', $key, $num_lines * 10, get_string('validating', 'admin'));
}
......@@ -274,7 +278,7 @@ function uploadcsv_submit(Pieform $form, $values) {
foreach ($CSVDATA as $record) {
if (!($key % 25)) {
if (!($key % 5)) {
set_progress_info('uploadgroupscsv', $num_lines + $key * 9, $num_lines * 10, get_string('committingchanges', 'admin'));
}
$key++;
......@@ -342,7 +346,10 @@ function uploadcsv_submit(Pieform $form, $values) {
set_progress_done('uploadgroupscsv');
redirect('/admin/groups/uploadcsv.php');
$form->reply(PIEFORM_OK, array(
'message' => get_string('csvfileprocessedsuccessfully', 'admin'),
'goto' => '/admin/groups/uploadcsv.php',
));
}
$grouptypes = "<ul class=fieldslist>\n";
......
......@@ -37,6 +37,10 @@ $GROUPS = array(); // Map gid to group shortnames
$form = array(
'name' => 'uploadcsv',
'jsform' => true,
'jssuccesscallback' => 'pmeter_success',
'jserrorcallback' => 'pmeter_error',
'presubmitcallback' => 'pmeter_presubmit',
'elements' => array(
'institution' => get_institution_selector(),
'file' => array(
......@@ -117,7 +121,7 @@ function uploadcsv_validate(Pieform $form, $values) {
$i = ($csvgroups->get('headerExists')) ? ($key + 2) : ($key + 1);
// In adding 5000 groups, this part was approx 8% of the wall time.
if (!($key % 25)) {
if (!($key % 5)) {
set_progress_info('uploadgroupmemberscsv', $key, $num_lines * 10, get_string('validating', 'admin'));
}
......@@ -227,7 +231,11 @@ function uploadcsv_submit(Pieform $form, $values) {
$SESSION->add_ok_msg(get_string('numbergroupsupdated', 'admin', 0));
}
set_progress_done('uploadgroupmemberscsv');
redirect('/admin/groups/uploadmemberscsv.php');
$form->reply(PIEFORM_OK, array(
'message' => get_string('csvfileprocessedsuccessfully', 'admin'),
'goto' => '/admin/groups/uploadmemberscsv.php',
));
}
$uploadcsvpagedescription = get_string('uploadgroupmemberscsvpagedescription3', 'admin',
......
......@@ -129,7 +129,7 @@ function bulkexport_submit(Pieform $form, $values) {
$num_users = count($usernames);
foreach ($usernames as $username) {
if (!($exportcount % 25)) {
if (!($exportcount % 5)) {
set_progress_info('bulkexport', $exportcount, $num_users, get_string('validating', 'admin'));
}
......@@ -199,6 +199,10 @@ if (count($authinstances) > 0) {
$form = array(
'name' => 'bulkexport',
'jsform' => true,
'jssuccesscallback' => 'pmeter_success',
'jserrorcallback' => 'pmeter_error',
'presubmitcallback' => 'pmeter_presubmit',
'elements' => array(
'authinstance' => $authinstanceelement,
'usernames' => array(
......
......@@ -74,6 +74,10 @@ $prefs = (object) expected_account_preferences();
$form = array(
'name' => 'uploadcsv',
'jsform' => true,
'jssuccesscallback' => 'pmeter_success',
'jserrorcallback' => 'pmeter_error',
'presubmitcallback' => 'pmeter_presubmit',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => array(
......@@ -240,7 +244,7 @@ function uploadcsv_validate(Pieform $form, $values) {
// If headers exists, increment i = key + 2 for actual line number
$i = ($csvusers->get('headerExists')) ? ($key + 2) : ($key + 1);
if (!($key % 25)) {
if (!($key % 5)) {
set_progress_info('uploaduserscsv', $key, $num_lines * $steps_total, get_string('validating', 'admin'));
}
......@@ -351,7 +355,7 @@ function uploadcsv_validate(Pieform $form, $values) {
foreach ($usernames as $lowerusername => $data) {
if (!($key % 25)) {
if (!($key % 5)) {
set_progress_info('uploaduserscsv', $num_lines + $key, $num_lines * $steps_total, get_string('checkingupdates', 'admin'));
}
$key++;
......@@ -503,7 +507,7 @@ function uploadcsv_submit(Pieform $form, $values) {
foreach ($CSVDATA as $record) {
if (!($key % 25)) {
if (!($key % 5)) {
// This part has three times the weight of the other two steps.
set_progress_info('uploaduserscsv', $num_lines * $steps_done + $key * 3, $num_lines * $steps_total, get_string('committingchanges', 'admin'));
}
......@@ -616,7 +620,10 @@ function uploadcsv_submit(Pieform $form, $values) {
set_progress_done('uploaduserscsv');
redirect('/admin/users/uploadcsv.php');
$form->reply(PIEFORM_OK, array(
'message' => get_string('csvfileprocessedsuccessfully', 'admin'),
'goto' => '/admin/users/uploadcsv.php',
));
}
// Get a list of all profile fields, to inform the user on what fields they can
......
......@@ -154,18 +154,15 @@ function formStartProcessing(form, btn) {
button.prop('disabled', true);
button.trigger("blur");
// Start the progress meter if it is enabled.
if (form && form.elements && form.elements['progress_meter_token']) {
meter_update_timer(form.elements['progress_meter_token'].value);
}
}
}
var meter_timeout;
function meter_update_timer(instance) {
sendjsonrequest(config.wwwroot + 'json/progress_meter.php', { 'instance' : instance }, 'GET', function(data) {
if (typeof(data) != 'undefined') {
if (!data.data.finished || !jQuery('#meter_overlay').is(':visible')) {
setTimeout(function() { meter_update_timer(instance) }, 1000);
if (!data.finished || !jQuery('#meter_overlay').is(':visible')) {
meter_timeout = setTimeout(function() { meter_update_timer(instance) }, 300);
}
meter_update(data.data);
}
......@@ -760,6 +757,12 @@ function meter_update(data) {
}
if (data.finished) {
if (data.error) {
jQuery('#meter_fill').animate({width: 0}); // remove bar filled before hiding
}
else {
jQuery('#meter_fill').animate({width: jQuery('#meter_wrap').width()}); // show bar filled before hiding
}
jQuery('#meter_overlay').hide();
if (typeof(data.redirect) !== 'undefined') {
......@@ -780,7 +783,7 @@ function meter_update(data) {
else {
new_width = 0;
}
jQuery('#meter_fill').width(new_width);
jQuery('#meter_fill').animate({width: new_width});
return true;
}
......@@ -1099,4 +1102,36 @@ jQuery(function($) {
e.preventDefault();
$(this).next().trigger('click');
});
});
\ No newline at end of file
});
function pmeter_success(form, data) {
jQuery('#meter_fill').animate({width: jQuery('#meter_wrap').width()}); // show bar filled before hiding
formSuccess(form, data);
if (typeof(data.goto) !== 'undefined') {
window.location.href = data.goto;
}
return true;
}
function pmeter_error(form, data) {
formError(form, data);
var data = {finished:true, error:true};
meter_update(data);
clearTimeout(meter_timeout);
}
function pmeter_presubmit(form, btn) {
var startmeter = false;
if ($('#' + form.name + '_progress_meter_token').length) {
startmeter = true;
}
if (startmeter) {
// Start the progress meter.
if (form && form.elements && form.elements['progress_meter_token']) {
meter_update_timer(form.elements['progress_meter_token'].value);
}
}
formStartProcessing(form, btn);
}
......@@ -937,9 +937,9 @@ class Pieform {/*{{{*/
/**
* Sends a message back to a form
*/
public function reply($returncode, $message) {
public function reply($returncode, $message, $replacehtml=null) {
if ($this->submitted_by_js()) {
$this->json_reply($returncode, $message);
$this->json_reply($returncode, $message, $replacehtml);
}
$function = $this->get_property('replycallback');
......
......@@ -218,7 +218,7 @@ var Pieform = (function($) {
var temp = $('<div>').append(data.replaceHTML);
data.javascript = '';
temp.find('*').each(function() {
if ($(this).prop('nodeName') === 'SCRIPT' && $(this).prop('src') === '') {
if ($(this).prop('nodeName') === 'SCRIPT' && $(this).prop('src') === '' && $(this).prop('type') !== 'text/x-tmpl') {
data.javascript += $(this).prop('innerHTML');
}
});
......
......@@ -516,7 +516,7 @@ function editaccess_submit(Pieform $form, $values) {
$key = 0;
$total = count($groupmembers);
foreach ($groupmembers as $groupmember) {
if (!($key % 25)) {
if (!($key % 5)) {
set_progress_info('copyviewexistingmembersprogress', $key, $total, get_string('copyforexistingmembersprogress', 'view'));
}
$key++;
......@@ -530,7 +530,6 @@ function editaccess_submit(Pieform $form, $values) {
$userobj->copy_group_views_collections_to_existing_members($values['views']);
}
}
set_progress_done('copyviewexistingmembersprogress');
}
}
......@@ -596,7 +595,7 @@ function editaccess_submit(Pieform $form, $values) {
}
$SESSION->add_ok_msg(get_string('updatedaccessfornumviews1', 'view', count($toupdate)));
set_progress_done('copyviewexistingmembersprogress');
if ($view->get('owner')) {
redirect('/view/share.php');
}
......@@ -606,7 +605,6 @@ function editaccess_submit(Pieform $form, $values) {
if ($view->get('institution')) {
redirect(get_config('wwwroot') . '/view/institutionshare.php?institution=' . $view->get('institution'));
}
$view->post_edit_redirect();
}
$form = pieform($form);
......
......@@ -436,7 +436,7 @@ function accessurl_submit(Pieform $form, $values) {
$key = 0;
$total = count($groupmembers);
foreach ($groupmembers as $groupmember) {
if (!($key % 25)) {
if (!($key % 5)) {
set_progress_info('copyviewexistingmembersprogress', $key, $total, get_string('copyforexistingmembersprogress', 'view'));
}
$key++;
......@@ -450,7 +450,6 @@ function accessurl_submit(Pieform $form, $values) {
$userobj->copy_group_views_collections_to_existing_members(array($view->get('id')));
}
}
set_progress_done('copyviewexistingmembersprogress');
}
}
......@@ -504,17 +503,16 @@ function accessurl_submit(Pieform $form, $values) {
$view->add_access($viewaccess);
}
}
set_progress_done('copyviewexistingmembersprogress');
if ($view->get('owner')) {
redirect(get_config('wwwroot') . '/view/blocks.php?id=' . $view->get('id'));
redirect(get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id'));
}
if ($view->get('group')) {
redirect(get_config('wwwroot') . '/group/shareviews.php?group=' . $view->get('group'));
redirect(get_config('wwwroot') . 'group/shareviews.php?group=' . $view->get('group'));
}
if ($view->get('institution')) {
redirect(get_config('wwwroot') . '/view/institutionshare.php?institution=' . $view->get('institution'));
redirect(get_config('wwwroot') . 'view/institutionshare.php?institution=' . $view->get('institution'));
}
$view->post_edit_redirect();
}
$form = pieform($form);
......
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