diff --git a/ajax/cronservice/cancelRegistration.php b/ajax/cronservice/cancelRegistration.php new file mode 100644 index 0000000000000000000000000000000000000000..abfd1d526695a5b2bb420932818752689c3cea99 --- /dev/null +++ b/ajax/cronservice/cancelRegistration.php @@ -0,0 +1,16 @@ +<?php + +/** + * Requests the server to cancel the registration + * + * @param - The email which was used for registration. + */ +QUI::$Ajax->registerFunction( + 'package_quiqqer_cron_ajax_cronservice_cancelRegistration', + function () { + $CronService = new \QUI\Cron\CronService(); + $CronService->cancelRegistration(); + }, + array(), + '' +); diff --git a/ajax/cronservice/resendActivation.php b/ajax/cronservice/resendActivation.php new file mode 100644 index 0000000000000000000000000000000000000000..deefdbda7346db88bb5b36006317257de293928e --- /dev/null +++ b/ajax/cronservice/resendActivation.php @@ -0,0 +1,16 @@ +<?php + +/** + * Requests the server to resend the activationmail again + * + * @param - The email which was used for registration. + */ +QUI::$Ajax->registerFunction( + 'package_quiqqer_cron_ajax_cronservice_resendActivation', + function () { + $CronService = new \QUI\Cron\CronService(); + $CronService->resendActivationMail(); + }, + array(), + '' +); diff --git a/bin/CronServiceWindow.css b/bin/CronServiceWindow.css index 07e20ae99496e3f9c3c4cb35cefa298f442cad16..826d0880acfae36c82afc003c866a46f4133a99e 100644 --- a/bin/CronServiceWindow.css +++ b/bin/CronServiceWindow.css @@ -1,7 +1,7 @@ .quiqqer-cron-cronservicewindow-btn-openRegistration { - margin : 30px auto 0 auto; float : right; + margin : 30px auto 0 auto; } .quiqqer-cron-cronserviceWindow h2 { @@ -28,8 +28,8 @@ } .quiqqer-cron-cronservicewindow-buttons { - text-align : center; margin-top : 40px; + text-align : center; width : 100%; } @@ -71,12 +71,24 @@ } .quiqqer-cron-cronservicewindow-registration-txt-email { - width : 100%; margin-top : 6px; + width : 100%; } .quiqqer-cron-cronservicewindow-btn-register { - margin-top : 20px; float : right; + margin-top : 20px; +} + +.quiqqer-cron-cronservicewindow-registration-success-btn-confirm { + float : right; + margin : 15px 0 0 0; } +.quiqqer-cron-cronservicewindow-registration-success-btn-cancel-text { + overflow : hidden; + text-align : center; + text-overflow : ellipsis; + white-space : nowrap; + width : 100%; +} \ No newline at end of file diff --git a/bin/CronServiceWindow.js b/bin/CronServiceWindow.js index 0a10bbcdac6fe0cd84e3904bcf77aaf1e87c99e1..f48c08a6e7a3ae4cc5f204583b3f7063fe600590 100644 --- a/bin/CronServiceWindow.js +++ b/bin/CronServiceWindow.js @@ -13,9 +13,10 @@ define('package/quiqqer/cron/bin/CronServiceWindow', [ 'text!package/quiqqer/cron/bin/CronServiceWindow.html', 'text!package/quiqqer/cron/bin/CronServiceWindowRegistration.html', + 'text!package/quiqqer/cron/bin/CronServiceWindowRegistrationSuccess.html', 'css!package/quiqqer/cron/bin/CronServiceWindow.css' -], function (QUI, QUIPopup, QUIButton, Mustache, QUILocale, QUIAjax, QUISheets, template, registrationTemplate) { +], function (QUI, QUIPopup, QUIButton, Mustache, QUILocale, QUIAjax, QUISheets, template, registrationTemplate, registrationSuccessTemplate) { "use strict"; var lg = 'quiqqer/cron'; @@ -101,40 +102,85 @@ define('package/quiqqer/cron/bin/CronServiceWindow', [ })); self.registered = (status['status'] != 0); + self.status = status['status']; var Buttons = Content.getElement('.quiqqer-cron-cronservicewindow-buttons'); - // get the button text : register or unregister - var btnText = QUILocale.get(lg, 'cron.window.cronservice.content.btn.register'); + + // Register/Unregister Button + if (self.status) { + var btnText = QUILocale.get(lg, 'cron.window.cronservice.content.btn.register'); + } if (self.registered) { btnText = QUILocale.get(lg, 'cron.window.cronservice.content.btn.unregister'); } - new QUIButton({ - text : btnText, - textimage: 'fa fa-arrow-right', - events : { - onClick: function (Button) { - if (!self.registered) { - self.showRegistration(); - return; + var Button = null; + if (self.status == 2) { + // Resend Activation Button + Button = new QUIButton({ + text : QUILocale.get(lg, 'cron.window.cronservice.content.btn.resend.activation.mail'), + textimage: 'fa fa-envelope-o', + events : { + onClick: function () { + self.resendActivationMail(); } - Button.setAttribute('text', QUILocale.get('quiqqer/cron', 'cron.window.cronservice.content.btn.unregister.confirm')); - if (Button.getAttribute('clickcnt') == 1) { - self.unregister().then(function () { - self.refresh(); - }); + }, + styles : { + 'float': 'none', + width : 'calc(50% - 5px)' + } + }); + + // Cancel Registration Button + new QUIButton({ + text : '<span class="quiqqer-cron-cronservicewindow-registration-success-btn-cancel-text">' + QUILocale.get(lg, 'cron.window.cronservice.registration.button.text.cancel') + '</span>', + events: { + onClick: function (Button) { + Button.setAttribute('text', QUILocale.get('quiqqer/cron', 'cron.window.cronservice.content.btn.unregister.confirm')); + if (Button.getAttribute('clickcnt') == 1) { + self.cancelRegistration().then(function () { + self.refresh(); + }); + } + Button.setAttribute('clickcnt', 1); } - Button.setAttribute('clickcnt', 1); + }, + styles: { + 'float': 'none', + margin : '0 10px 0 0', + width : 'calc(50% - 5px)' } - }, - styles : { - 'float': 'none', - margin : '0 auto', - width : 200 - } - }).inject(Buttons); + }).inject(Buttons); + } else { + Button = new QUIButton({ + text : btnText, + textimage: 'fa fa-arrow-right', + events : { + onClick: function (Button) { + if (!self.registered) { + self.showRegistration(); + return; + } + Button.setAttribute('text', QUILocale.get('quiqqer/cron', 'cron.window.cronservice.content.btn.unregister.confirm')); + if (Button.getAttribute('clickcnt') == 1) { + self.unregister().then(function () { + self.refresh(); + }); + } + Button.setAttribute('clickcnt', 1); + } + }, + styles : { + 'float': 'none', + margin : '0 auto', + width : 200 + } + }); + } + + Button.inject(Buttons); self.Loader.hide(); }, { @@ -172,8 +218,10 @@ define('package/quiqqer/cron/bin/CronServiceWindow', [ Content.getElement('.quiqqer-cron-cronservicewindow-btn-register').addEvent('click', function () { self.Loader.show(); self.register(Email.value).then(function () { - self.refresh(); + self.Loader.hide(); + self.showRegistrationSuccess(); Sheet.destroy(); + }).catch(function () { self.Loader.hide(); }); @@ -187,6 +235,44 @@ define('package/quiqqer/cron/bin/CronServiceWindow', [ }).inject(this.$Elm).show(); }, + /** + * Shows the registration success sheet, which contains information about the activation email + */ + showRegistrationSuccess: function () { + var self = this; + + new QUISheets({ + header : true, + icon : 'fa fa-cloud', + title : QUILocale.get(lg, 'cron.window.cronservice.title'), + buttons: false, + events : { + onOpen : function (Sheet) { + var Content = Sheet.getContent(); + + self.Loader.show(); + + Content.set('html', Mustache.render(registrationSuccessTemplate, { + cron_window_cronservice_registration_success_title : QUILocale.get(lg, 'cron.window.cronservice.registration.success.title'), + cron_window_cronservice_registration_success_text : QUILocale.get(lg, 'cron.window.cronservice.registration.success.text'), + cron_window_cronservice_content_registration_successfull_btn_confirm: QUILocale.get(lg, 'cron.window.cronservice.registration.success.btn.confirm.text') + })); + + // Click event handler + Content.getElement('.quiqqer-cron-cronservicewindow-registration-success-btn-confirm').addEvent('click', function () { + self.refresh(); + Sheet.destroy(); + }); + + self.Loader.hide(); + }, + onClose: function (Sheet) { + Sheet.destroy(); + } + } + }).inject(this.$Elm).show(); + }, + /** * Register a email to the cron service * @@ -215,6 +301,32 @@ define('package/quiqqer/cron/bin/CronServiceWindow', [ onError : reject }); }); + }, + + /** + * Cancels the registration + * @returns {*} + */ + cancelRegistration: function () { + return new Promise(function (resolve, reject) { + QUIAjax.get('package_quiqqer_cron_ajax_cronservice_cancelRegistration', resolve, { + 'package': lg, + onError : reject + }); + }); + }, + + /** + * Sends the activation mail again + * @returns {*} + */ + resendActivationMail: function () { + return new Promise(function (resolve, reject) { + QUIAjax.get('package_quiqqer_cron_ajax_cronservice_resendActivation', resolve, { + 'package': lg, + onError : reject + }); + }); } }); }); diff --git a/bin/CronServiceWindowRegistrationSuccess.html b/bin/CronServiceWindowRegistrationSuccess.html new file mode 100644 index 0000000000000000000000000000000000000000..ac51651eebe69cc82f852ae3d2c1ba5fbe1bb8af --- /dev/null +++ b/bin/CronServiceWindowRegistrationSuccess.html @@ -0,0 +1,14 @@ +<div class="quiqqer-cron-cronservicewindow-registration"> + <h1 class="quiqqer-cron-cronservicewindow-registration-title"> + {{cron_window_cronservice_registration_success_title}} + </h1> + + <div> + {{{cron_window_cronservice_registration_success_text}}} + </div> + + <div class="quiqqer-cron-cronservicewindow-registration-success-btn-confirm qui-button"> + <span class="fa fa-check"></span> + <span>{{cron_window_cronservice_content_registration_successfull_btn_confirm}}</span> + </div> +</div> \ No newline at end of file diff --git a/bin/CronWindow.css b/bin/CronWindow.css index 64f19b6e3e673254b2eec7cfd23ace25ae400258..4acac11b16baae58069b6dcda370cb78357109cc 100644 --- a/bin/CronWindow.css +++ b/bin/CronWindow.css @@ -14,7 +14,11 @@ .control-cron-add-list { float: left; margin: 0; - width: 230px; + width: 500px; +} + +.control-cron-add-list .qui-select { + width: 100%; } .control-cron-add-intervall { @@ -35,6 +39,11 @@ float: left; } +.control-cron-add-intervall-control { + float: left; + width: calc(100% - 90px); +} + .control-cron-add-intervall-entry { float: left; margin-right: 10px; diff --git a/bin/CronWindow.html b/bin/CronWindow.html index 0c3a1904e2cafad39cddc83054e53cb063b5528a..1191af9a3ba92e390222ac58892598b7f0884276 100644 --- a/bin/CronWindow.html +++ b/bin/CronWindow.html @@ -2,33 +2,11 @@ <label for="control-cron-add-list"> Cron </label> - <select class="control-cron-add-list" id="control-cron-add-list"></select> + <div class="control-cron-add-list" id="control-cron-add-list"></div> <div class="control-cron-add-intervall"> <div class="control-cron-add-intervall-title"></div> - - <div class="control-cron-add-intervall-entries"> - <div class="control-cron-add-intervall-entry"> - <input type="text" name="min" id="control-cron-add-minute"/> - <label for="control-cron-add-minute"></label> - </div> - <div class="control-cron-add-intervall-entry"> - <input type="text" name="hour" id="control-cron-add-hour"/> - <label for="control-cron-add-hour"></label> - </div> - <div class="control-cron-add-intervall-entry"> - <input type="text" name="day" id="control-cron-add-day"/> - <label for="control-cron-add-day"></label> - </div> - <div class="control-cron-add-intervall-entry"> - <input type="text" name="month" id="control-cron-add-month"/> - <label for="control-cron-add-month"></label> - </div> - <div class="control-cron-add-intervall-entry"> - <input type="text" name="dayOfWeek" id="control-cron-add-dayOfWeek"/> - <label for="control-cron-add-dayOfWeek"></label> - </div> - </div> + <div class="control-cron-add-intervall-control"></div> </div> <div class="control-cron-add-params-container"> diff --git a/bin/CronWindow.js b/bin/CronWindow.js index e2a33146744c071724d77bfe89472f47fb10b9e5..ea28628d612cce26c1c7831cab01f4829345fc24 100644 --- a/bin/CronWindow.js +++ b/bin/CronWindow.js @@ -13,14 +13,17 @@ define('package/quiqqer/cron/bin/CronWindow', [ 'qui/controls/windows/Confirm', + 'qui/controls/buttons/Select', 'qui/controls/input/Params', 'Ajax', 'Locale', + 'package/quiqqer/cron/bin/controls/CronTime', + 'text!package/quiqqer/cron/bin/CronWindow.html', 'css!package/quiqqer/cron/bin/CronWindow.css' -], function (QUIConfirm, QUIParams, Ajax, QUILocale, cronWindowTemplate) { +], function (QUIConfirm, QUISelect, QUIParams, Ajax, QUILocale, CronTime, cronWindowTemplate) { "use strict"; var lg = 'quiqqer/cron'; @@ -38,13 +41,13 @@ define('package/quiqqer/cron/bin/CronWindow', [ cronId: null, // if you want to edit a cron - cancel_button : { - text : QUILocale.get('quiqqer/system', 'cancel'), - textimage : 'fa fa-remove' + cancel_button: { + text : QUILocale.get('quiqqer/system', 'cancel'), + textimage: 'fa fa-remove' }, - ok_button : { - text : QUILocale.get('quiqqer/system', 'ok'), - textimage : 'fa fa-check' + ok_button : { + text : QUILocale.get('quiqqer/system', 'ok'), + textimage: 'fa fa-check' } }, @@ -53,11 +56,8 @@ define('package/quiqqer/cron/bin/CronWindow', [ this.$available = []; - this.$List = null; - this.$Min = null; - this.$Hour = null; - this.$Day = null; - this.$Month = null; + this.$List = null; + this.$CronTimeControl = null; this.$ParamsControl = null; }, @@ -81,44 +81,22 @@ define('package/quiqqer/cron/bin/CronWindow', [ '.control-cron-add-intervall-title' ).set('html', QUILocale.get(lg, 'cron.interval')); - Content.getElement( - '[for="control-cron-add-minute"]' - ).set('html', QUILocale.get(lg, 'cron.min')); - - Content.getElement( - '[for="control-cron-add-hour"]' - ).set('html', QUILocale.get(lg, 'cron.hour')); - - Content.getElement( - '[for="control-cron-add-day"]' - ).set('html', QUILocale.get(lg, 'cron.day')); - - Content.getElement( - '[for="control-cron-add-month"]' - ).set('html', QUILocale.get(lg, 'cron.month')); - - Content.getElement( - '[for="control-cron-add-dayOfWeek"]' - ).set('html', QUILocale.get(lg, 'cron.dayOfWeek')); - - Content.getElement( '[for="control-cron-add-params"]' ).set('html', QUILocale.get(lg, 'cron.params')); // data - this.$List = Content.getElement('.control-cron-add-list'); - - this.$Min = Content.getElement('[name="min"]'); - this.$Hour = Content.getElement('[name="hour"]'); - this.$Day = Content.getElement('[name="day"]'); - this.$Month = Content.getElement('[name="month"]'); - this.$DayOfWeek = Content.getElement('[name="dayOfWeek"]'); + //this.$List = Content.getElement('.control-cron-add-list'); + this.$List = new QUISelect({ + showIcons: false + }).inject( + Content.getElement('.control-cron-add-list') + ); this.$Params = Content.getElement('[name="params"]'); - this.$List.addEvent('change', function () { + this.$List.addEvent('change', function (val) { if (!self.$available) { return; } @@ -128,8 +106,7 @@ define('package/quiqqer/cron/bin/CronWindow', [ } var i, len, p, plen; - var val = self.$List.value, - available = self.$available, + var available = self.$available, allowedParams = [], params = []; @@ -149,15 +126,22 @@ define('package/quiqqer/cron/bin/CronWindow', [ self.$ParamsControl.setAttribute('allowedParams', allowedParams); }); + this.$CronTimeControl = new CronTime().inject( + this.$Elm.getElement( + '.control-cron-add-intervall-control' + ) + ); + Ajax.get('package_quiqqer_cron_ajax_getAvailableCrons', function (result) { self.$available = result; for (var i = 0, len = result.length; i < len; i++) { - new Element('option', { - value: result[i].title, - html : result[i].title + ' - ' + result[i].description - }).inject(self.$List); + self.$List.appendChild( + '<b>' + result[i].title + '</b> - ' + result[i].description, + result[i].title, + false + ); } self.$ParamsControl = new QUIParams(self.$Params); @@ -168,16 +152,20 @@ define('package/quiqqer/cron/bin/CronWindow', [ } Ajax.get('package_quiqqer_cron_ajax_cron_get', function (result) { - self.$List.value = result.title; - self.$Min.value = result.min; - self.$Hour.value = result.hour; - self.$Day.value = result.day; - self.$Month.value = result.month; - self.$DayOfWeek.value = result.dayOfWeek; - self.$Params.value = result.params; + self.$List.setValue(result.title); + + self.$CronTimeControl.setValue( + result.min, + result.hour, + result.day, + result.month, + result.dayOfWeek + ); + + self.$Params.value = result.params; self.$Params.fireEvent('change'); - self.$List.fireEvent('change'); + //self.$List.fireEvent('change'); self.Loader.hide(); }, { @@ -209,6 +197,7 @@ define('package/quiqqer/cron/bin/CronWindow', [ return this; } + var CronTime = this.$CronTimeControl.getValue(); if (this.getAttribute('cronId')) { Ajax.post('package_quiqqer_cron_ajax_edit', function () { @@ -217,12 +206,12 @@ define('package/quiqqer/cron/bin/CronWindow', [ }, { 'package': 'quiqqer/cron', cronId : this.getAttribute('cronId'), - cron : this.$List.value, - min : this.$Min.value, - hour : this.$Hour.value, - day : this.$Day.value, - month : this.$Month.value, - dayOfWeek: this.$DayOfWeek.value, + cron : this.$List.getValue(), + min : CronTime.minute, + hour : CronTime.hour, + day : CronTime.day, + month : CronTime.month, + dayOfWeek: CronTime.dayOfWeek, params : JSON.encode(this.$ParamsControl.getValue()) }); @@ -234,12 +223,12 @@ define('package/quiqqer/cron/bin/CronWindow', [ self.close(); }, { 'package': 'quiqqer/cron', - cron : this.$List.value, - min : this.$Min.value, - hour : this.$Hour.value, - day : this.$Day.value, - month : this.$Month.value, - dayOfWeek: this.$DayOfWeek.value, + cron : this.$List.getValue(), + min : CronTime.minute, + hour : CronTime.hour, + day : CronTime.day, + month : CronTime.month, + dayOfWeek: CronTime.dayOfWeek, params : JSON.encode(this.$ParamsControl.getValue()) }); diff --git a/bin/controls/CronTime.css b/bin/controls/CronTime.css new file mode 100644 index 0000000000000000000000000000000000000000..e9ff842c34a14499e4408cfd45fc79979883a305 --- /dev/null +++ b/bin/controls/CronTime.css @@ -0,0 +1,53 @@ +.quiqqer-cron-crontime { + float: left; + width: 100%; +} + +.quiqqer-cron-crontime-interval { + float: left; + width: 20%; +} + +.quiqqer-cron-crontime-interval-select { + width: 110px; +} + +.quiqqer-cron-crontime-options { + float: left; + padding-left: 15px; + width: 80%; +} + +.quiqqer-cron-crontime-options span { + float: left; + line-height: 28px; + padding-right: 5px; +} + +.quiqqer-cron-crontime-options span:not(:first-of-type) { + padding-left: 10px; +} + +.quiqqer-cron-crontime-number-select { + width: 50px; +} + +.quiqqer-cron-crontime-month-select { + width: 100px; +} + +.quiqqer-cron-crontime-dayofweek-select { + width: 120px; +} + +.quiqqer-cron-crontime-cron-label { + float: left; + margin: 0 !important; + padding-right: 10px; + width: 20% !important; +} + +.quiqqer-cron-crontime-cron-label input { + float: left; + width: 100%; +} \ No newline at end of file diff --git a/bin/controls/CronTime.js b/bin/controls/CronTime.js new file mode 100644 index 0000000000000000000000000000000000000000..af492f9e6cf1492b07d0d855603000e6242f7425 --- /dev/null +++ b/bin/controls/CronTime.js @@ -0,0 +1,617 @@ +/** + * Control for setting up cron timetables in a user-friendly fashion + * + * @module package/quiqqer/cron/bin/controls/CronTime + * @author www.pcsg.de (Patrick Müller) + * + * @require qui/controls/Control + * @require Ajax + */ +define('package/quiqqer/cron/bin/controls/CronTime', [ + + 'qui/controls/Control', + 'qui/controls/loader/Loader', + 'qui/controls/buttons/Select', + + 'Locale', + 'Ajax', + + 'css!package/quiqqer/cron/bin/controls/CronTime.css' + +], function (QUIControl, QUILoader, QUISelect, QUILocale, QUIAjax) { + "use strict"; + + var lg = 'quiqqer/cron'; + + return new Class({ + + Extends: QUIControl, + Type : 'package/quiqqer/cron/bin/controls/CronTime', + + Binds: [ + '$loadIntervalOptions', + '$change' + ], + + initialize: function (options) { + this.parent(options); + + this.$CronTime = null; + this.$IntervalSelect = null; + this.$OptionsElm = null; + this.Loader = new QUILoader(); + + this.$SelectMinute = null; + this.$SelectHour = null; + this.$SelectDay = null; + this.$SelectMonth = null; + this.$SelectDayOfWeek = null; + + this.$minute = '*'; + this.$hour = '*'; + this.$day = '*'; + this.$month = '*'; + this.$dayofweek = '*'; + }, + + /** + * create the domnode element + * + * @return {HTMLDivElement} + */ + create: function () { + var i, len, label; + var self = this; + + this.$Elm = new Element('div', { + 'class': 'quiqqer-cron-crontime', + html : '<div class="quiqqer-cron-crontime-interval">' + + '</div>' + + '<div class="quiqqer-cron-crontime-options"></div>' + }); + + //QUILocale.get(lg, 'controls.crontime.label.interval') + + this.$IntervalSelect = new QUISelect({ + 'class' : 'quiqqer-cron-crontime-interval-select', + showIcons: false, + events : { + onChange: this.$loadIntervalOptions + } + }).inject( + this.$Elm.getElement( + '.quiqqer-cron-crontime-interval' + ) + ); + + this.$OptionsElm = this.$Elm.getElement('.quiqqer-cron-crontime-options'); + + var intervals = [ + 'everyminute', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'cron' + ]; + + for (i = 0, len = intervals.length; i < len; i++) { + this.$IntervalSelect.appendChild( + QUILocale.get(lg, 'controls.crontime.intervalselect.option.' + intervals[i]), + intervals[i], + false + ); + } + + this.$SelectMinute = new QUISelect({ + 'class' : 'quiqqer-cron-crontime-number-select', + showIcons: false, + events : { + onChange: function (value) { + self.$minute = value; + self.$change(); + } + } + }); + + for (i = 0; i < 60; i++) { + label = i; + + if (i < 10) { + label = "0" + i; + } + + this.$SelectMinute.appendChild( + label, + i, + false + ); + } + + this.$SelectHour = new QUISelect({ + 'class' : 'quiqqer-cron-crontime-number-select', + showIcons: false, + events : { + onChange: function (value) { + self.$hour = value; + self.$change(); + } + } + }); + + for (i = 0; i < 24; i++) { + label = i; + + if (i < 10) { + label = "0" + i; + } + + this.$SelectHour.appendChild( + label, + i, + false + ); + } + + this.$SelectDay = new QUISelect({ + 'class' : 'quiqqer-cron-crontime-number-select', + showIcons: false, + events : { + onChange: function (value) { + self.$day = value; + self.$change(); + } + } + }); + + for (i = 0; i < 31; i++) { + this.$SelectDay.appendChild( + i + 1 + ".", + i + 1, + false + ); + } + + this.$SelectMonth = new QUISelect({ + 'class' : 'quiqqer-cron-crontime-month-select', + showIcons: false, + events : { + onChange: function (value) { + self.$month = value; + self.$change(); + } + } + }); + + for (i = 0; i < 12; i++) { + this.$SelectMonth.appendChild( + QUILocale.get(lg, 'controls.crontime.month.' + (i + 1)), + i + 1, + false + ); + } + + this.$SelectDayOfWeek = new QUISelect({ + 'class' : 'quiqqer-cron-crontime-dayofweek-select', + showIcons: false, + events : { + onChange: function (value) { + self.$dayofweek = value; + self.$change(); + } + } + }); + + var daysOfWeek = [ + 'su', 'mo', 'tu', 'we', 'th', 'fr', 'sa' + ]; + + for (i = 0, len = daysOfWeek.length; i < len; i++) { + this.$SelectDayOfWeek.appendChild( + QUILocale.get(lg, 'controls.crontime.dayofweek.' + daysOfWeek[i]), + i, + false + ); + } + + return this.$Elm; + }, + + /** + * Load option inputs depending on interval + * + * @param interval + */ + $loadIntervalOptions: function (interval) { + var self = this; + + this.$OptionsElm.set('html', ''); + + this.$minute = '*'; + this.$hour = '*'; + this.$day = '*'; + this.$month = '*'; + this.$dayofweek = '*'; + + switch (interval) { + case 'everyminute': + this.$change(); + break; + + case 'hourly': + this.$OptionsElm.set( + 'html', + '<span>' + QUILocale.get(lg, 'controls.crontime.label.minute') + '</span>' + + '<div class="quiqqer-cron-crontime-hour"></div>' + ); + + this.$SelectMinute.inject( + this.$OptionsElm.getElement( + '.quiqqer-cron-crontime-hour' + ) + ); + this.$SelectMinute.setValue(0); + + break; + + case 'daily': + this.$OptionsElm.set( + 'html', + '<span>' + QUILocale.get(lg, 'controls.crontime.label.at') + '</span>' + + '<div class="quiqqer-cron-crontime-hour"></div>' + + '<span>:</span>' + + '<div class="quiqqer-cron-crontime-minute"></div>' + ); + + this.$SelectHour.inject( + this.$OptionsElm.getElement( + '.quiqqer-cron-crontime-hour' + ) + ); + this.$SelectHour.setValue(0); + + this.$SelectMinute.inject( + this.$OptionsElm.getElement( + '.quiqqer-cron-crontime-minute' + ) + ); + this.$SelectMinute.setValue(0); + + break; + + case 'weekly': + this.$OptionsElm.set( + 'html', + '<span>' + QUILocale.get(lg, 'controls.crontime.label.on') + '</span>' + + '<div class="quiqqer-cron-crontime-dayofweek"></div>' + + '<span>' + QUILocale.get(lg, 'controls.crontime.label.at') + '</span>' + + '<div class="quiqqer-cron-crontime-hour"></div>' + + '<span>:</span>' + + '<div class="quiqqer-cron-crontime-minute"></div>' + ); + + this.$SelectDayOfWeek.inject( + this.$OptionsElm.getElement( + '.quiqqer-cron-crontime-dayofweek' + ) + ); + this.$SelectDayOfWeek.setValue(0); + + this.$SelectHour.inject( + this.$OptionsElm.getElement( + '.quiqqer-cron-crontime-hour' + ) + ); + this.$SelectHour.setValue(0); + + this.$SelectMinute.inject( + this.$OptionsElm.getElement( + '.quiqqer-cron-crontime-minute' + ) + ); + this.$SelectMinute.setValue(0); + + break; + + case 'monthly': + this.$OptionsElm.set( + 'html', + '<span>' + QUILocale.get(lg, 'controls.crontime.label.on') + '</span>' + + '<div class="quiqqer-cron-crontime-day"></div>' + + '<span>' + QUILocale.get(lg, 'controls.crontime.label.at') + '</span>' + + '<div class="quiqqer-cron-crontime-hour"></div>' + + '<span>:</span>' + + '<div class="quiqqer-cron-crontime-minute"></div>' + ); + + this.$SelectDay.inject( + this.$OptionsElm.getElement( + '.quiqqer-cron-crontime-day' + ) + ); + this.$SelectDay.setValue(1); + + this.$SelectHour.inject( + this.$OptionsElm.getElement( + '.quiqqer-cron-crontime-hour' + ) + ); + this.$SelectHour.setValue(0); + + this.$SelectMinute.inject( + this.$OptionsElm.getElement( + '.quiqqer-cron-crontime-minute' + ) + ); + this.$SelectMinute.setValue(0); + + break; + + case 'yearly': + this.$OptionsElm.set( + 'html', + '<span>' + QUILocale.get(lg, 'controls.crontime.label.on') + '</span>' + + '<div class="quiqqer-cron-crontime-day"></div>' + + '<div class="quiqqer-cron-crontime-month"></div>' + + '<span>' + QUILocale.get(lg, 'controls.crontime.label.at') + '</span>' + + '<div class="quiqqer-cron-crontime-hour"></div>' + + '<span>:</span>' + + '<div class="quiqqer-cron-crontime-minute"></div>' + ); + + this.$SelectDay.inject( + this.$OptionsElm.getElement( + '.quiqqer-cron-crontime-day' + ) + ); + this.$SelectDay.setValue(1); + + this.$SelectMonth.inject( + this.$OptionsElm.getElement( + '.quiqqer-cron-crontime-month' + ) + ); + this.$SelectMonth.setValue(1); + + this.$SelectHour.inject( + this.$OptionsElm.getElement( + '.quiqqer-cron-crontime-hour' + ) + ); + this.$SelectHour.setValue(0); + + this.$SelectMinute.inject( + this.$OptionsElm.getElement( + '.quiqqer-cron-crontime-minute' + ) + ); + this.$SelectMinute.setValue(0); + break; + + case 'cron': + var inputs = [ + 'minute', 'hour', 'day', 'month', 'dayofweek' + ]; + + for (var i = 0, len = inputs.length; i < len; i++) { + var Label = new Element('label', { + 'class': 'quiqqer-cron-crontime-cron-label', + html : '<span>' + + QUILocale.get(lg, 'controls.crontime.label.' + inputs[i]) + + '</span>' + }).inject(this.$OptionsElm); + + new Element('input', { + 'class' : 'quiqqer-cron-crontime-cron-input', + 'data-type': inputs[i], + type : 'text', + events : { + change: function (event) { + var Input = event.target; + + Input.value = Input.value.replace(/[^\d\*\\\-]/gi, ''); + + switch (Input.getProperty('data-type')) { + case 'minute': + self.$minute = Input.value; + break; + + case 'hour': + self.$hour = Input.value; + break; + + case 'day': + self.$day = Input.value; + break; + + case 'month': + self.$month = Input.value; + break; + + case 'dayofweek': + self.$dayofweek = Input.value; + break; + } + + self.$change(); + } + } + }).inject(Label, 'top'); + } + + this.$Elm.getElement( + '.quiqqer-cron-crontime-cron-input' + ).focus(); + + break; + } + }, + + /** + * Fires change event with current value + */ + $change: function () { + this.fireEvent( + 'change', + [this.$minute, this.$hour, this.$day, this.$month, this.$dayofweek, this] + ); + }, + + /** + * Set value to control + * + * @param minute + * @param hour + * @param day + * @param month + * @param dayofweek + */ + setValue: function (minute, hour, day, month, dayofweek) { + if (minute.match(/[^\d\*]/gi) || + hour.match(/[^\d\*]/gi) || + day.match(/[^\d\*]/gi) || + month.match(/[^\d\*]/gi) || + dayofweek.match(/[^\d\*]/gi) + ) { + this.$showCronStyleInput( + minute, + hour, + day, + month, + dayofweek + ); + + return; + } + + + if (minute == '*' && + hour == '*' && + day == '*' && + month == '*' && + dayofweek == '*') { + this.$IntervalSelect.setValue('everyminute'); + return; + } + + if (minute != '*' && + hour == '*' && + day == '*' && + month == '*' && + dayofweek == '*') { + this.$IntervalSelect.setValue('hourly'); + this.$SelectMinute.setValue(minute); + return; + } + + if (minute != '*' && + hour != '*' && + day == '*' && + month == '*' && + dayofweek == '*') { + this.$IntervalSelect.setValue('daily'); + this.$SelectMinute.setValue(minute); + this.$SelectHour.setValue(hour); + return; + } + + if (minute != '*' && + hour != '*' && + day == '*' && + month == '*' && + dayofweek != '*') { + this.$IntervalSelect.setValue('weekly'); + this.$SelectMinute.setValue(minute); + this.$SelectHour.setValue(hour); + this.$SelectDayOfWeek.setValue(dayofweek); + return; + } + + if (minute != '*' && + hour != '*' && + day != '*' && + month == '*' && + dayofweek == '*') { + this.$IntervalSelect.setValue('monthly'); + this.$SelectMinute.setValue(minute); + this.$SelectHour.setValue(hour); + this.$SelectDay.setValue(day); + return; + } + + if (minute != '*' && + hour != '*' && + day != '*' && + month != '*' && + dayofweek == '*') { + this.$IntervalSelect.setValue('yearly'); + this.$SelectMinute.setValue(minute); + this.$SelectHour.setValue(hour); + this.$SelectDay.setValue(day); + this.$SelectMonth.setValue(month); + return; + } + + this.$showCronStyleInput( + minute, + hour, + day, + month, + dayofweek + ); + }, + + /** + * Show cron style type input + * + * @param {string} m + * @param {string} h + * @param {string} d + * @param {string} mo + * @param {string} dw + */ + $showCronStyleInput: function (m, h, d, mo, dw) { + this.$IntervalSelect.setValue('cron'); + + var cronStyleInputs = this.$Elm.getElements( + '.quiqqer-cron-crontime-cron-input' + ); + + for (var i = 0, len = cronStyleInputs.length; i < len; i++) { + var Elm = cronStyleInputs[i]; + + switch (Elm.getProperty('data-type')) { + case 'minute': + Elm.value = m; + break; + + case 'hour': + Elm.value = h; + break; + + case 'day': + Elm.value = d; + break; + + case 'month': + Elm.value = mo; + break; + + case 'dayofweek': + Elm.value = dw; + break; + } + } + }, + + /** + * Get current cron time values + * + * @return {Object} + */ + getValue: function () { + return { + minute : this.$minute, + hour : this.$hour, + day : this.$day, + month : this.$month, + dayOfWeek: this.$dayofweek + }; + } + }); +}); diff --git a/composer.json b/composer.json index 8ac8868bac29d360cfe671c576d1b1c60360137b..45f97163dbf5d5f15ecc1c3e759c6313c8c4a2ac 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "quiqqer\/cron", "type": "quiqqer-module", - "description": "Provided currency calculation and a automtatic cron to get the Euro foreign exchange reference rates.", + "description": "Prodives cron API and execution of registered crons", "version": "dev-master", "license": "GPL-2.0+", "authors": [ @@ -25,4 +25,4 @@ "QUI": "src\/" } } -} \ No newline at end of file +} diff --git a/locale.xml b/locale.xml index a479c7efb574af5ba8ee6623e62e881c3d24d00b..ab4e64bec090a2826303a7f52b2218186231922a 100644 --- a/locale.xml +++ b/locale.xml @@ -164,6 +164,171 @@ <de><![CDATA[Aufgabenverlauf]]></de> <en><![CDATA[Cron history]]></en> </locale> + + + <locale name="permission.quiqqer.cron._header"> + <de><![CDATA[Aufgaben / Tasks]]></de> + <en><![CDATA[Tasks]]></en> + </locale> + <locale name="permission.quiqqer.cron.execute"> + <de><![CDATA[Darf Aufgaben / Tasks ausführen.]]></de> + <en><![CDATA[Can execute tasks.]]></en> + </locale> + <locale name="permission.quiqqer.cron.add"> + <de><![CDATA[Darf Aufgaben / Tasks hinzufügen.]]></de> + <en><![CDATA[Can add tasks.]]></en> + </locale> + <locale name="permission.quiqqer.cron.edit"> + <de><![CDATA[Darf Aufgaben / Tasks bearbeiten.]]></de> + <en><![CDATA[Can edit tasks.]]></en> + </locale> + <locale name="permission.quiqqer.cron.delete"> + <de><![CDATA[Darf Aufgaben / Tasks löschen.]]></de> + <en><![CDATA[Can delete tasks.]]></en> + </locale> + <locale name="permission.quiqqer.cron.activate"> + <de><![CDATA[Darf Aufgaben / Tasks aktivieren.]]></de> + <en><![CDATA[Can activate tasks.]]></en> + </locale> + <locale name="permission.quiqqer.cron.deactivate"> + <de><![CDATA[Darf Aufgaben / Tasks deaktivieren.]]></de> + <en><![CDATA[Can deactivate tasks.]]></en> + </locale> + + <locale name="controls.crontime.intervalselect.option.everyminute"> + <de><![CDATA[Jede Minute]]></de> + <en><![CDATA[Every minute]]></en> + </locale> + <locale name="controls.crontime.intervalselect.option.hourly"> + <de><![CDATA[Stündlich]]></de> + <en><![CDATA[Hourly]]></en> + </locale> + <locale name="controls.crontime.intervalselect.option.daily"> + <de><![CDATA[Täglich]]></de> + <en><![CDATA[Daily]]></en> + </locale> + <locale name="controls.crontime.intervalselect.option.weekly"> + <de><![CDATA[Wöchentlich]]></de> + <en><![CDATA[Weekly]]></en> + </locale> + <locale name="controls.crontime.intervalselect.option.monthly"> + <de><![CDATA[Monatlich]]></de> + <en><![CDATA[Monthly]]></en> + </locale> + <locale name="controls.crontime.intervalselect.option.yearly"> + <de><![CDATA[Jährlich]]></de> + <en><![CDATA[Yearly]]></en> + </locale> + <locale name="controls.crontime.intervalselect.option.cron"> + <de><![CDATA[Cron-Stil]]></de> + <en><![CDATA[Cron style]]></en> + </locale> + <locale name="controls.crontime.dayofweek.su"> + <de><![CDATA[Sonntag]]></de> + <en><![CDATA[Sunday]]></en> + </locale> + <locale name="controls.crontime.dayofweek.mo"> + <de><![CDATA[Montag]]></de> + <en><![CDATA[Monday]]></en> + </locale> + <locale name="controls.crontime.dayofweek.tu"> + <de><![CDATA[Dienstag]]></de> + <en><![CDATA[Tuesday]]></en> + </locale> + <locale name="controls.crontime.dayofweek.we"> + <de><![CDATA[Mittwoch]]></de> + <en><![CDATA[Wednesday]]></en> + </locale> + <locale name="controls.crontime.dayofweek.th"> + <de><![CDATA[Donnerstag]]></de> + <en><![CDATA[Thursday]]></en> + </locale> + <locale name="controls.crontime.dayofweek.fr"> + <de><![CDATA[Freitag]]></de> + <en><![CDATA[Friday]]></en> + </locale> + <locale name="controls.crontime.dayofweek.sa"> + <de><![CDATA[Samstag]]></de> + <en><![CDATA[Saturday]]></en> + </locale> + <locale name="controls.crontime.month.1"> + <de><![CDATA[Januar]]></de> + <en><![CDATA[January]]></en> + </locale> + <locale name="controls.crontime.month.2"> + <de><![CDATA[Februar]]></de> + <en><![CDATA[February]]></en> + </locale> + <locale name="controls.crontime.month.3"> + <de><![CDATA[März]]></de> + <en><![CDATA[March]]></en> + </locale> + <locale name="controls.crontime.month.4"> + <de><![CDATA[April]]></de> + <en><![CDATA[April]]></en> + </locale> + <locale name="controls.crontime.month.5"> + <de><![CDATA[Mai]]></de> + <en><![CDATA[May]]></en> + </locale> + <locale name="controls.crontime.month.6"> + <de><![CDATA[Juni]]></de> + <en><![CDATA[June]]></en> + </locale> + <locale name="controls.crontime.month.7"> + <de><![CDATA[Juli]]></de> + <en><![CDATA[July]]></en> + </locale> + <locale name="controls.crontime.month.8"> + <de><![CDATA[August]]></de> + <en><![CDATA[August]]></en> + </locale> + <locale name="controls.crontime.month.9"> + <de><![CDATA[September]]></de> + <en><![CDATA[September]]></en> + </locale> + <locale name="controls.crontime.month.10"> + <de><![CDATA[Oktober]]></de> + <en><![CDATA[October]]></en> + </locale> + <locale name="controls.crontime.month.11"> + <de><![CDATA[November]]></de> + <en><![CDATA[November]]></en> + </locale> + <locale name="controls.crontime.month.12"> + <de><![CDATA[Dezember]]></de> + <en><![CDATA[December]]></en> + </locale> + <locale name="controls.crontime.label.minute"> + <de><![CDATA[Minute]]></de> + <en><![CDATA[minute]]></en> + </locale> + <locale name="controls.crontime.label.hour"> + <de><![CDATA[Stunde]]></de> + <en><![CDATA[hour]]></en> + </locale> + <locale name="controls.crontime.label.day"> + <de><![CDATA[Tag]]></de> + <en><![CDATA[day]]></en> + </locale> + <locale name="controls.crontime.label.month"> + <de><![CDATA[Monat]]></de> + <en><![CDATA[month]]></en> + </locale> + <locale name="controls.crontime.label.dayofweek"> + <de><![CDATA[Tag d. Woche]]></de> + <en><![CDATA[Day of week]]></en> + </locale> + <locale name="controls.crontime.label.at"> + <de><![CDATA[Um]]></de> + <en><![CDATA[At]]></en> + </locale> + <locale name="controls.crontime.label.interval"> + <de><![CDATA[Intervall]]></de> + <en><![CDATA[Interval]]></en> + </locale> + + <!-- Cronservice --> <locale name="cron.panel.manager.btn.cronservice.register"> <de><![CDATA[Cronservice]]></de> <en><![CDATA[Cronservice]]></en> @@ -265,34 +430,27 @@ This is works with an external server on which QUIQQER systems can register them <de><![CDATA[Registrierung entfernen]]></de> <en><![CDATA[Unregister]]></en> </locale> - - <locale name="permission.quiqqer.cron._header"> - <de><![CDATA[Aufgaben / Tasks]]></de> - <en><![CDATA[Tasks]]></en> - </locale> - <locale name="permission.quiqqer.cron.execute"> - <de><![CDATA[Darf Aufgaben / Tasks ausführen.]]></de> - <en><![CDATA[Can execute tasks.]]></en> - </locale> - <locale name="permission.quiqqer.cron.add"> - <de><![CDATA[Darf Aufgaben / Tasks hinzufügen.]]></de> - <en><![CDATA[Can add tasks.]]></en> + <locale name="cron.window.cronservice.registration.success.title"> + <de><![CDATA[Registrierung erfolgreich]]></de> + <en><![CDATA[Registration successfull]]></en> </locale> - <locale name="permission.quiqqer.cron.edit"> - <de><![CDATA[Darf Aufgaben / Tasks bearbeiten.]]></de> - <en><![CDATA[Can edit tasks.]]></en> + <locale name="cron.window.cronservice.registration.success.text" html="true"> + <de> + <![CDATA[Die Registrierung war erfolgreich! <br /> Bitte überprüfen Sie nun das angegebene Email Postfach und bestätigen Sie die Registrierung. <br /> Bitte bedenken Sie, dass die Email im Spamordner gelandet sein könnte.]]></de> + <en> + <![CDATA[The registration was successfull. Please check your email inbox and confirm the registration. <br /> Bear in mind that the email could have been marked as spam.]]></en> </locale> - <locale name="permission.quiqqer.cron.delete"> - <de><![CDATA[Darf Aufgaben / Tasks löschen.]]></de> - <en><![CDATA[Can delete tasks.]]></en> + <locale name="cron.window.cronservice.content.btn.resend.activation.mail"> + <de><![CDATA[Mail erneut senden]]></de> + <en><![CDATA[Resend activationmail]]></en> </locale> - <locale name="permission.quiqqer.cron.activate"> - <de><![CDATA[Darf Aufgaben / Tasks aktivieren.]]></de> - <en><![CDATA[Can activate tasks.]]></en> + <locale name="cron.window.cronservice.registration.success.btn.confirm.text"> + <de><![CDATA[Verstanden]]></de> + <en><![CDATA[Okay]]></en> </locale> - <locale name="permission.quiqqer.cron.deactivate"> - <de><![CDATA[Darf Aufgaben / Tasks deaktivieren.]]></de> - <en><![CDATA[Can deactivate tasks.]]></en> + <locale name="cron.window.cronservice.registration.button.text.cancel"> + <de><![CDATA[Registrierung abbrechen]]></de> + <en><![CDATA[Cancel registration]]></en> </locale> </groups> </locales> \ No newline at end of file diff --git a/src/QUI/Cron/CronService.php b/src/QUI/Cron/CronService.php index 1d3c0ae39fb7fe9764d2f192dba8e6d7a44ab84a..6a2f45976f4fed20d533872c7a1cceb6d16da469 100644 --- a/src/QUI/Cron/CronService.php +++ b/src/QUI/Cron/CronService.php @@ -25,7 +25,7 @@ class CronService $url_dir = QUI::$Conf->get("globals", "url_dir"); // VHost Domain - $vhost = QUI::getProjectManager()->getStandard()->getVHost(true, true); + $vhost = QUI::getProjectManager()->getStandard()->getVHost(true, true); // Check if https should be used. if (substr($vhost, 0, 8) == 'https://') { @@ -106,6 +106,43 @@ class CronService )); } + /** + * Requests the cronservice to resend the activation email + * @throws Exception + */ + public function resendActivationMail() + { + if (!isset($this->domain) || empty($this->domain)) { + throw new Exception("Could not get the instances domain."); + } + + $this->makeServerAjaxCall( + "package_pcsg_cronservice_ajax_resendActivationMail", + array( + "domain" => $this->domain + ) + ); + } + + /** + * Attempts to cancel the registration on the server + * @throws Exception + */ + public function cancelRegistration() + { + Log::addDebug(""); + if (!isset($this->domain) || empty($this->domain)) { + throw new Exception("Could not get the instances domain."); + } + + $this->makeServerAjaxCall( + "package_pcsg_cronservice_ajax_cancelRegistration", + array( + "domain" => $this->domain + ) + ); + } + /** * Sends an ajax request to the cronservice server. * @@ -250,7 +287,6 @@ class CronService } $token = file_get_contents($fileName); - if ($token === false) { throw new Exception("Could not read tokenfile."); } diff --git a/src/QUI/Cron/Manager.php b/src/QUI/Cron/Manager.php index 1bb9fb3166452f4764e4e093950b32e690051b24..293b1e3b35a48fb9d4c703e9313af50b94db540c 100644 --- a/src/QUI/Cron/Manager.php +++ b/src/QUI/Cron/Manager.php @@ -217,8 +217,8 @@ class Manager $month = $entry['month']; $dayOfWeek = '*'; - if (isset($entry['dayOfMonth']) && !empty($entry['dayOfMonth'])) { - $dayOfWeek = $entry['dayOfMonth']; + if (isset($entry['dayOfWeek']) && !empty($entry['dayOfWeek'])) { + $dayOfWeek = $entry['dayOfWeek']; }