Project

General

Profile

« Previous | Next » 

Revision 30a8ef77

Added by Vinícius Coque over 13 years ago

Converting javascript code to jQuery on installer webgui

View differences:

usr/local/www/installer/installer.php
258 258
	$status = `cat /tmp/.pc-sysinstall/pc-sysinstall.log`;
259 259
	$status = str_replace("\n", "\\n", $status);
260 260
	$status = str_replace("\n", "\\r", $status);
261
	echo "this.document.forms[0].installeroutput.value='$status';\n";
262
	echo "this.document.forms[0].installeroutput.scrollTop = this.document.forms[0].installeroutput.scrollHeight;\n";	
261
	$status = str_replace("'", "\\'", $status);
262
	echo "document.forms[0].installeroutput.value='$status';\n";
263
	echo "document.forms[0].installeroutput.scrollTop = document.forms[0].installeroutput.scrollHeight;\n";	
263 264
	// Find out installer progress
264 265
	$progress = "5";
265 266
	if(strstr($status, "Running: dd")) 
......
319 320
	// Check for error and bail if we see one.
320 321
	if(stristr($status, "error")) {
321 322
		$error = true;
322
		echo "\$('installerrunning').innerHTML='<img class=\"infoboxnpimg\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\"> <font size=\"2\"><b>An error occurred.  Aborting installation.  <a href=\"/installer\">Back</a> to webInstaller'; ";
323
		echo "\$('progressbar').style.width='100%';\n";
323
		echo "\$('#installerrunning').html('<img class=\"infoboxnpimg\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\"> <font size=\"2\"><b>An error occurred.  Aborting installation.  <a href=\"/installer\">Back</a> to webInstaller'); ";
324
		echo "\$('#progressbar').css('width','100%');\n";
324 325
		unlink_if_exists("/tmp/install_complete");
325 326
		return;
326 327
	}
......
328 329
	if($installer_running <> "running") {
329 330
		$ps_running = exec("/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep 'sh /tmp/installer.sh'");
330 331
		if($ps_running)	{
331
			$running = "\$('installerrunning').innerHTML='<table><tr><td valign=\"middle\"><img src=\"/themes/{$g['theme']}/images/misc/loader.gif\"></td><td valign=\"middle\">&nbsp;<font size=\"2\"><b>Installer running ({$progress}% completed)...</td></tr></table>'; ";
332
			$running = "\$('#installerrunning').html('<table><tr><td valign=\"middle\"><img src=\"/themes/{$g['theme']}/images/misc/loader.gif\"></td><td valign=\"middle\">&nbsp;<font size=\"2\"><b>Installer running ({$progress}% completed)...</td></tr></table>'); ";
332 333
			if($running_old <> $running) {
333 334
				echo $running;
334 335
				file_put_contents("/tmp/installer_installer_running", "$running");			
......
336 337
		}
337 338
	}
338 339
	if($progress) 
339
		echo "\$('progressbar').style.width='{$progress}%';\n";
340
		echo "\$('#progressbar').css('width','{$progress}%');\n";
340 341
	if(file_exists("/tmp/install_complete")) {
341
		echo "\$('installerrunning').innerHTML='<img class=\"infoboxnpimg\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\"> <font size=\"+1\">Installation completed.  Please <a href=\"/reboot.php\">reboot</a> to continue';\n";
342
		echo "\$('pbdiv').Fade();\n";
342
		echo "\$('#installerrunning').html('<img class=\"infoboxnpimg\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\"> <font size=\"+1\">Installation completed.  Please <a href=\"/reboot.php\">reboot</a> to continue');\n";
343
		echo "\$('#pbdiv').fadeOut();\n";
343 344
		unlink_if_exists("/tmp/installer.sh");
344 345
		file_put_contents("/tmp/installer_installer_running", "finished");
345 346
	}
......
348 349
function update_installer_status_win($status) {
349 350
	global $g, $fstype, $savemsg;
350 351
	echo "<script type=\"text/javascript\">\n";
351
	echo "	\$('installeroutput').value = '" . str_replace(htmlentities($status), "\n", "") . "';\n";
352
	echo "	\$('#installeroutput').val('" . str_replace(htmlentities($status), "\n", "") . "');\n";
352 353
	echo "</script>\n";
353 354
}
354 355

  
......
410 411
	include("head.inc");
411 412
	echo <<<EOF
412 413
	<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
413
	<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
414
	<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
414
	<script type="text/javascript" src="/javascript/jquery.js"></script>
415
	<script type="text/javascript" src="/javascript/jquery/jquery-ui.custom.min.js"></script>
415 416
	<script type="text/javascript">
416 417
		function getinstallerprogress() {
417 418
			url = '/installer/installer.php';
......
419 420
			callajax(url, pars, installcallback);
420 421
		}
421 422
		function callajax(url, pars, activitycallback) {
422
			var myAjax = new Ajax.Request(
423
			jQuery.ajax(
423 424
				url,
424 425
				{
425
					method: 'post',
426
					parameters: pars,
427
					onComplete: activitycallback
426
					type: 'post',
427
					data: pars,
428
					complete: activitycallback
428 429
				});
429 430
		}
430 431
		function installcallback(transport) {
......
773 774
				{$disk_sizes_js_txt}
774 775
				// Run through all rows and process data
775 776
				for(var x = 0; x<99; x++) { //optimize me better
776
					if(\$('fstype' + x)) {
777
						if(\$('size' + x).value == '')
778
							\$('size' + x).value = disk_sizes[\$('disk' + x).value];
779
						var fstype = \$F('fstype' + x);
777
					if(\$('#fstype' + x).length) {
778
						if(\$('#size' + x).val() == '')
779
							\$('#size' + x).val(disk_sizes[\$('disk' + x).value]);
780
						var fstype = \$('#fstype' + x).val();
780 781
						if(fstype.substring(fstype.length - 4) == ".eli") {
781
							\$('encpass' + x).disabled = 0;
782
							\$('#encpass' + x).prop('disabled',false);
782 783
							if(!encryption_warning_shown) {
783 784
								alert('NOTE: If you define a disk encryption password you will need to enter it on *EVERY* bootup!');
784 785
								encryption_warning_shown = true;
785 786
							}
786 787
						} else { 
787
							\$('encpass' + x).disabled = 1;
788
							\$('#encpass' + x).prop('disabled',true);
788 789
						}
789 790
					}
790 791
					// Calculate size allocations
791
					if(\$('size' + x)) {
792
						if(parseInt($('size' + x).value) > 0)
793
							totalsize += parseInt($('size' + x).value);
792
					if(\$('#size' + x).length) {
793
						if(parseInt($('#size' + x).val()) > 0)
794
							totalsize += parseInt($('#size' + x).val());
794 795
					}
795 796
				}
796 797
				// If the totalsize element exists, set it and disable
797
				if(\$('totalsize')) {
798
					if(\$('totalsize').value != totalsize) {
798
				if(\$('#totalsize').length) {
799
					if(\$('#totalsize').val() != totalsize) {
799 800
						// When size allocation changes, draw attention.
800
 						new Effect.Highlight('totalsize');
801
						\$('totalsize').value = totalsize;
801
 						jQuery('#totalsize').effect('highlight');
802
						\$('#totalsize').val(totalsize);
802 803
					}
803
					\$('totalsize').disabled = 1;
804
					\$('#totalsize').prop('disabled',true);
804 805
				}
805
				if(\$('disktotals')) {
806
				if(\$('#disktotals').length) {
806 807
					var disks_seen = new Array();
807 808
					var tmp_sizedisks = 0;
808 809
					var disksseen = 0;
809 810
					for(var xx = 0; xx<99; xx++) {
810
						if(\$('disk' + xx)) {
811
							if(!disks_seen.in_array(\$('disk' + xx).value)) {
812
								tmp_sizedisks += parseInt(disk_sizes[\$('disk' + xx).value]);
813
								disks_seen[disksseen] = \$('disk' + xx).value;
811
						if(\$('#disk' + xx).length) {
812
							if(!disks_seen.in_array(\$('#disk' + xx).val())) {
813
								tmp_sizedisks += parseInt(disk_sizes[\$('#disk' + xx).val()]);
814
								disks_seen[disksseen] = \$('#disk' + xx).val();
814 815
								disksseen++;
815 816
							}
816 817
						}
817
					\$('disktotals').value = tmp_sizedisks;
818
					\$('disktotals').disabled = 1;
819
					\$('disktotals').setStyle({color:'#000000'});
820
					var remaining = parseInt(\$('disktotals').value) - parseInt(\$('totalsize').value);
818
					\$('#disktotals').val(tmp_sizedisks);
819
					\$('#disktotals').prop('disabled',true);
820
					\$('#disktotals').css('color','#000000');
821
					var remaining = parseInt(\$('#disktotals').val()) - parseInt(\$('#totalsize').val());
821 822
						if(remaining == 0) {
822
							if(\$('totalsize'))
823
								\$('totalsize').setStyle({
824
									background:'#00FF00',
825
									color:'#000000'
823
							if(\$('#totalsize').length)
824
								\$('#totalsize').css({
825
									'background':'#00FF00',
826
									'color':'#000000'
826 827
								});
827 828
						} else {
828
							if(\$('totalsize'))
829
								\$('totalsize').setStyle({
830
									background:'#FFFFFF',
831
									color:'#000000'
829
							if(\$('#totalsize').length)
830
								\$('#totalsize').css({
831
									'background':'#FFFFFF',
832
									'color':'#000000'
832 833
								});
833 834
						}
834
						if(parseInt(\$('totalsize').value) > parseInt(\$('disktotals').value)) {
835
							if(\$('totalsize'))
836
								\$('totalsize').setStyle({
837
									background:'#FF0000',
838
									color:'#000000'
835
						if(parseInt(\$('#totalsize').val()) > parseInt(\$('#disktotals').val())) {
836
							if(\$('#totalsize'))
837
								\$('#totalsize').css({
838
									'background':'#FF0000',
839
									'color':'#000000'
839 840
								});							
840 841
						}
841
						if(\$('availalloc')) {
842
							\$('availalloc').disabled = 1;
843
							\$('availalloc').value = remaining;
844
								\$('availalloc').setStyle({
845
									background:'#FFFFFF',
846
									color:'#000000'
842
						if(\$('#availalloc').length) {
843
							\$('#availalloc').prop('disabled',true);
844
							\$('#availalloc').val(remaining);
845
								\$('#availalloc').css({
846
									'background':'#FFFFFF',
847
									'color':'#000000'
847 848
								});							
848 849
						}
849 850
					}
......
1016 1017
												<tr>
1017 1018
													<td colspan='4'>
1018 1019
													<script type="text/javascript">
1019
														\$('loadingdiv').style.visibility='hidden';
1020
														\$('#loadingdiv').css('visibility','hidden');
1020 1021
													</script>
1021 1022
													<div id='contentdiv' style="display:none;">
1022 1023
														<p/>
......
1027 1028
													</div>
1028 1029
													<script type="text/javascript">
1029 1030
														var encryption_warning_shown = false;
1030
														\$('contentdiv').appear();
1031
														\$('#contentdiv').fadeIn();
1031 1032
														row_helper_dynamic_custom();
1032 1033
													</script>
1033 1034
												</center>

Also available in: Unified diff