Elgg  Version 2.3
upgrades.js
Go to the documentation of this file.
1 
6 define(function(require) {
7  var $ = require('jquery');
8  var elgg = require('elgg');
9 
10  // The already displayed messages are saved here
11  var errorMessages = [];
12 
18  var run = function(e) {
19  e.preventDefault();
20 
21  // The total amount of items to be upgraded
22  var total = $('#upgrade-total').text();
23 
24  // Initialize progressbar
25  $('.elgg-progressbar').progressbar({
26  value: 0,
27  max: total
28  });
29 
30  // Replace button with spinner when upgrade starts
31  $('#upgrade-run').addClass('hidden');
32  $('#upgrade-spinner').removeClass('hidden');
33 
34  // Start upgrade from offset 0
35  upgradeBatch(0);
36  };
37 
43  var upgradeBatch = function(offset) {
44  var options = {
45  data: {
46  offset: offset
47  },
48  dataType: 'json'
49  };
50 
51  options.data = elgg.security.addToken(options.data);
52 
53  var upgradeCount = $('#upgrade-count');
54  var action = $('#upgrade-run').attr('href');
55 
56  options.success = function(json) {
57  // Append possible errors after the progressbar
58  if (json.system_messages.error.length) {
59  // Display only the errors that haven't already been shown
60  $(json.system_messages.error).each(function(key, message) {
61  if (jQuery.inArray(message, errorMessages) === -1) {
62  var msg = '<li class="elgg-message elgg-state-error">' + message + '</li>';
63  $('#upgrade-messages').append(msg);
64 
65  // Add this error to the displayed errors
66  errorMessages.push(message);
67  }
68  });
69  }
70 
71  // Increase success statistics
72  var numSuccess = $('#upgrade-success-count');
73  var successCount = parseInt(numSuccess.text()) + json.output.numSuccess;
74  numSuccess.text(successCount);
75 
76  // Increase error statistics
77  var numErrors = $('#upgrade-error-count');
78  var errorCount = parseInt(numErrors.text()) + json.output.numErrors;
79  numErrors.text(errorCount);
80 
81  // Increase total amount of processed items
82  var numProcessed = successCount + errorCount;
83  upgradeCount.text(numProcessed);
84 
85  // Increase the progress bar
86  $('.elgg-progressbar').progressbar({ value: numProcessed });
87  var total = $('#upgrade-total').text();
88 
89  var percent = 100;
90  if (numProcessed < total) {
91  percent = parseInt(numProcessed * 100 / total);
92 
97  upgradeBatch(errorCount);
98  } else {
99  $('#upgrade-spinner').addClass('hidden');
100 
101  if (errorCount > 0) {
102  // Upgrade finished with errors. Give instructions on how to proceed.
103  elgg.register_error(elgg.echo('upgrade:finished_with_errors'));
104  } else {
105  // Upgrade is finished. Make one more call to mark it complete.
106  elgg.action(action, {'upgrade_completed': 1});
107  elgg.system_message(elgg.echo('upgrade:finished'));
108  }
109  }
110 
111  // Increase percentage
112  $('#upgrade-counter').text(percent + '%');
113  };
114 
115  // We use post() instead of action() so we can catch error messages
116  // and display them manually underneath the upgrade view.
117  return elgg.post(action, options);
118  };
119 
120  $('#upgrade-run').click(run);
121 });
elgg
Definition: install.js:23
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a and you may at your option offer warranty protection in exchange for a fee You may modify your copy or copies of the Program or any portion of thus forming a work based on the and copy and distribute such modifications or work under the terms of Section provided that you also meet all of these that in whole or in part contains or is derived from the Program or any part to be licensed as a whole at no charge to all third parties under the terms of this License c If the modified program normally reads commands interactively when run
Definition: GPL-LICENSE.txt:87
define(function(require){var $=require('jquery');var elgg=require('elgg');var errorMessages=[];var run=function(e){e.preventDefault();var total=$('#upgrade-total').text();$('.elgg-progressbar').progressbar({value:0, max:total});$('#upgrade-run').addClass('hidden');$('#upgrade-spinner').removeClass('hidden');upgradeBatch(0);};var upgradeBatch=function(offset){var options={data:{offset:offset}, dataType: 'json'};options.data=elgg.security.addToken(options.data);var upgradeCount=$('#upgrade-count');var action=$('#upgrade-run').attr('href');options.success=function(json){if(json.system_messages.error.length){$(json.system_messages.error).each(function(key, message){if(jQuery.inArray(message, errorMessages)===-1){var msg= '< li class="elgg-message elgg-state-error">'+message+ '</li >';$('#upgrade-messages').append(msg);errorMessages.push(message);}});}var numSuccess=$('#upgrade-success-count');var successCount=parseInt(numSuccess.text())+json.output.numSuccess;numSuccess.text(successCount);var numErrors=$('#upgrade-error-count');var errorCount=parseInt(numErrors.text())+json.output.numErrors;numErrors.text(errorCount);var numProcessed=successCount+errorCount;upgradeCount.text(numProcessed);$('.elgg-progressbar').progressbar({value:numProcessed});var total=$('#upgrade-total').text();var percent=100;if(numProcessed< total){percent=parseInt(numProcessed *100/total);upgradeBatch(errorCount);}else{$('#upgrade-spinner').addClass('hidden');if(errorCount > 0){elgg.register_error(elgg.echo('upgrade:finished_with_errors'));}else{elgg.action(action,{'upgrade_completed':1});elgg.system_message(elgg.echo('upgrade:finished'));}}$('#upgrade-counter').text(percent+ '%');};return elgg.post(action, options);};$('#upgrade-run').click(run);})
Provides functions for site upgrades performed through XHR.
elgg require
Throw an error if the required package isn&#39;t present.
Definition: elgglib.js:164
function elgg combo checkbox click(function(){if($(this).is(':checked')){$(this).prev().attr('disabled', true);$(this).prev().val('');}else{$(this).prev().attr('disabled', false);}})
elgg input text
Definition: admin.css.php:505
elgg message
Definition: admin.css.php:240
elgg action
Definition: ajax.js:200