| 1 |
/** |
| 2 |
* |
| 3 |
*/ |
| 4 |
|
| 5 |
/** |
| 6 |
* |
| 7 |
*/ |
| 8 |
(function($) { |
| 9 |
|
| 10 |
/** |
| 11 |
* |
| 12 |
*/ |
| 13 |
var CJTInstallerForm = { |
| 14 |
|
| 15 |
/** |
| 16 |
* put your comment there... |
| 17 |
* |
| 18 |
*/ |
| 19 |
installationForm : null, |
| 20 |
|
| 21 |
/** |
| 22 |
* Start installation process. |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
_oninstall : function() { |
| 27 |
var operations = []; |
| 28 |
// Don't process if not confirmed! |
| 29 |
if (!confirm(CJTInstallerDefaultI18N.confirmMessage)) { |
| 30 |
return; |
| 31 |
} |
| 32 |
// Operations to process. |
| 33 |
this.installationForm.find('ul.installation-list').each($.proxy( |
| 34 |
function(listIndex, list) { |
| 35 |
var typeName = list.className.split(' ').pop(); |
| 36 |
$(list).find('li').each($.proxy( |
| 37 |
function(index, li) { |
| 38 |
var operation = li.className.split(' '); |
| 39 |
// Include operation if not installed (has no'installed' class ), |
| 40 |
// AND if the operation is mandatory OR its optional with the checkbox checked! |
| 41 |
var operationCheckbox = $(li).find('input:checkbox'); |
| 42 |
var included = (operation[1] === undefined) && // Not insatlled (not installed class!) |
| 43 |
((operationCheckbox.get(0).className != 'optional') || (operationCheckbox.prop('checked'))); |
| 44 |
// Build operation object! |
| 45 |
if (included) { |
| 46 |
// Add to operations list! |
| 47 |
operations.push({type : typeName, name : operation[0]}); |
| 48 |
} |
| 49 |
}, this) |
| 50 |
); |
| 51 |
}, this) |
| 52 |
); |
| 53 |
// Create installer object! |
| 54 |
var installer = new CJTInstaller(operations); |
| 55 |
// Disable form to disallow repeating actions! |
| 56 |
this.installationForm.find('input').prop('disabled', 'disabled'); |
| 57 |
//For each operation progress the installation! |
| 58 |
installer.install($.proxy( |
| 59 |
function(promise, operationId, operation) { |
| 60 |
// Get li node from operation details. |
| 61 |
var li = this.installationForm.find('ul.installation-list.' + operation.type + ' li.' + operation.name); |
| 62 |
// Show loading progress and hide checkbox. |
| 63 |
li.addClass('progress').find('input:checkbox').hide(); |
| 64 |
// We need to know when operation faild or success. |
| 65 |
promise.done($.proxy( // Operation installation successed. |
| 66 |
function() { |
| 67 |
// Mark as installed! |
| 68 |
li.addClass('installed'); |
| 69 |
}, this) |
| 70 |
).fail($.proxy( // Operation installation faild! |
| 71 |
function() { |
| 72 |
console.log(operation.name + ' is faild'); |
| 73 |
}, this) |
| 74 |
).complete($.proxy( |
| 75 |
function() { |
| 76 |
// Stop progressing! |
| 77 |
li.removeClass('progress'); |
| 78 |
}, this) |
| 79 |
); |
| 80 |
// Always do the operation! |
| 81 |
return true; |
| 82 |
}, this) |
| 83 |
).done($.proxy( // Overall installation completed with success! |
| 84 |
function() { |
| 85 |
// Show success message! |
| 86 |
alert(CJTInstallerDefaultI18N.successMessage); |
| 87 |
// Setup START button! |
| 88 |
this.installationForm.find('input:button') |
| 89 |
// Enable button. |
| 90 |
.prop('disabled', '') |
| 91 |
// Change button caption to done! |
| 92 |
.val(CJTInstallerDefaultI18N.startButtonText) |
| 93 |
// Unbind uninstall method! |
| 94 |
.unbind('click', this._oninstall) |
| 95 |
// Bind to start method. |
| 96 |
.bind('click', this._onstart); |
| 97 |
}, this) |
| 98 |
).fail($.proxy( // Overall installation completed with error! |
| 99 |
function() { |
| 100 |
// Enable form to accept other actions! |
| 101 |
this.installationForm.find('input').prop('disabled', 'disabled'); |
| 102 |
}, this) |
| 103 |
); |
| 104 |
}, |
| 105 |
|
| 106 |
/** |
| 107 |
* |
| 108 |
*/ |
| 109 |
_onstart : function() { |
| 110 |
// Just refresh window and server will do the rest! |
| 111 |
window.location.reload(); |
| 112 |
}, |
| 113 |
|
| 114 |
/** |
| 115 |
* put your comment there... |
| 116 |
* |
| 117 |
*/ |
| 118 |
init : function() { |
| 119 |
// Initialize vars! |
| 120 |
this.installationForm = $('form[name="installation-form"]'); |
| 121 |
// Bind events! |
| 122 |
this.installationForm.find('input:button').click($.proxy(this._oninstall, this)); |
| 123 |
} |
| 124 |
|
| 125 |
} // End CJTInstallerform. |
| 126 |
|
| 127 |
// Initioalize form when document ready! |
| 128 |
$($.proxy(CJTInstallerForm.init, CJTInstallerForm)); |
| 129 |
|
| 130 |
})(jQuery); |