Skip to content
Code-Schnipsel Gruppen Projekte
CronWindow.js 7,17 KiB
Newer Older
  • Learn to ignore specific revisions
  •  * Cron Window
    
     * @module URL_OPT_DIR/quiqqer/cron/bin/CronWindow
    
     * @author www.namerobot.com (Henning Leutz)
     */
    
    define([
    
    Henning Leutz's avatar
    Henning Leutz committed
    
        'qui/controls/windows/Confirm',
    
        'qui/controls/input/Params',
    
    Henning Leutz's avatar
    Henning Leutz committed
        'Ajax',
    
    
    Henning Leutz's avatar
    Henning Leutz committed
        'css!package/quiqqer/cron/bin/CronWindow.css'
    
    ], function(QUIConfirm, QUIParams, Ajax)
    
    Henning Leutz's avatar
    Henning Leutz committed
    {
        "use strict";
    
    
        return new Class({
    
    
    Henning Leutz's avatar
    Henning Leutz committed
            Type : 'package/quiqqer/cron/bin/CronWindow',
    
    Henning Leutz's avatar
    Henning Leutz committed
            Extends : QUIConfirm,
    
            options : {
    
                title     : 'Cron hinzufügen',
                icon      : 'icon-time',
    
                maxWidth  : 440,
                maxHeight : 500,
    
    
                cronId : null // if you want to edit a cron
    
    Henning Leutz's avatar
    Henning Leutz committed
            },
    
            initialize : function(options)
            {
                this.parent( options );
    
                this.$available = [];
    
                this.$List  = null;
                this.$Min   = null;
                this.$Hour  = null;
                this.$Day   = null;
                this.$Month = null;
    
    
                this.$ParamsControl = null;
    
    Henning Leutz's avatar
    Henning Leutz committed
            },
    
            /**
             * Open the Window
             *
             * @return {self}
             */
            open : function()
            {
                this.parent();
                this.Loader.show();
    
                var self    = this,
                    Content = this.getContent();
    
                Content.set(
                    'html',
    
                    '<div class="control-cron-add">' +
                        '<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-intervall">' +
                            '<div class="control-cron-add-intervall-title">' +
                                'Intervall:' +
                            '</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">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">Stunde</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">Tag</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">Monat</label>' +
                                '</div>' +
                            '</div>' +
                        '</div>' +
    
    
                        '<div class="control-cron-add-params-container">' +
                            '<label for="control-cron-add-params">' +
                                'Parameter' +
                            '</label>' +
                            '<input type="text" name="params" id="control-cron-add-params"  />' +
                        '</div>' +
    
    Henning Leutz's avatar
    Henning Leutz committed
                    '</div>'
                );
    
                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.$Params = Content.getElement( '[name="params"]' );
    
    
    Henning Leutz's avatar
    Henning Leutz committed
    
                Ajax.get('package_quiqqer_cron_ajax_getAvailableCrons', function(result)
                {
                    var i, len;
    
    
                    var size = self.getElm().getSize();
    
    
    Henning Leutz's avatar
    Henning Leutz committed
                    self.$available = result;
    
                    for ( i = 0, len = result.length; i < len; i++ )
                    {
                        new Element('option', {
    
                            value : result[ i ].title,
    
                            html  : result[ i ].title +' - '+ result[ i ].description
    
    Henning Leutz's avatar
    Henning Leutz committed
                        }).inject( self.$List );
                    }
    
    
                    self.$ParamsControl = new QUIParams( self.$Params, {
                        windowMaxHeight : size.y,
                        windowMaxWidth  : size.x
                    } );
    
    
                    if ( !self.getAttribute( 'cronId' ) )
                    {
                        self.Loader.hide();
                        return;
                    }
    
                    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.$Params.value = result.params;
    
    
                        self.$Params.fireEvent( 'change' );
    
    
                        self.Loader.hide();
                    }, {
                        'package' : 'quiqqer/cron',
                        cronId    : self.getAttribute( 'cronId' )
                    });
    
    Henning Leutz's avatar
    Henning Leutz committed
    
                }, {
                    'package' : 'quiqqer/cron'
                });
    
    
                return this;
            },
    
            /**
             * Add the Cron to the list
             *
             * @return {self}
             */
            submit : function()
            {
    
    Henning Leutz's avatar
    Henning Leutz committed
                if ( !this.$List ) {
                    return this;
                }
    
                if ( !this.getContent() ) {
                    return this;
                }
    
    
                if ( this.getAttribute( 'cronId' ) )
                {
                    Ajax.post('package_quiqqer_cron_ajax_edit', function(result)
                    {
                        self.fireEvent( 'submit' );
                        self.close();
                    }, {
                        '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,
    
                        params : JSON.encode( this.$ParamsControl.getValue() )
    
    Henning Leutz's avatar
    Henning Leutz committed
                Ajax.post('package_quiqqer_cron_ajax_add', function(result)
                {
    
    Henning Leutz's avatar
    Henning Leutz committed
                    self.close();
    
    Henning Leutz's avatar
    Henning Leutz committed
                }, {
    
                    'package' : 'quiqqer/cron',
    
                    cron   : this.$List.value,
                    min    : this.$Min.value,
                    hour   : this.$Hour.value,
                    day    : this.$Day.value,
                    month  : this.$Month.value,
    
                    params : JSON.encode( this.$ParamsControl.getValue() )
    
    Henning Leutz's avatar
    Henning Leutz committed
                });