Viewing File: /usr/local/cpanel/base/frontend/jupiter/mail/editquota.html.tt

[%
SET CPANEL.CPVAR.dprefix = "../";
USE CPMath;

Api2.pre_exec("Email", "getdiskusage");
SET diskusage = Api2.exec("Email", "getdiskusage", {"domain"=>(RAW_FORM.domain), "user"=>(RAW_FORM.email)} );
Api2.post_exec("Email", "getdiskusage");
IF diskusage.size();
    SET diskused = diskusage.0.diskused;
END;

SET get_pop_quota_response = execute("Email", "get_pop_quota", {
    "email" => RAW_FORM.email,
    "domain" => RAW_FORM.domain
});

IF get_pop_quota_response.status;
    IF get_pop_quota_response.data == "unlimited";
        SET popquota = locale.maketext("unlimited");
    ELSE;
        SET popquota = CPMath.int(get_pop_quota_response.data);
    END;

    js_code = PROCESS js_block;
END;
%]

[% WRAPPER '_assets/master.html.tt'
    app_key = 'email_accounts'
    page_js = js_code
-%]
<div class="body-content">
    [% IF get_pop_quota_response.status %]
    <p class="description" id="descMailLimit">
        [% locale.maketext("Please enter the limit for the user’s mailbox, in megabytes.")  %]
        [% locale.maketext("To set no limit (an infinite quota), simply enter “unlimited”.")  %]
    </p>

    <form name="quotaform" id="quotaform" method="post" action="doeditquota.html">
        <input type="hidden" id="email" name="email" value="[% FORM.email %]" />
        <input type="hidden" id="domain" name="domain" value="[% FORM.domain %]" />

        <div class="form-group">
            <label id="lblEmail">
                [% locale.maketext("Email") %]
            </label>
            <div class="row">
                <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <span id="email">[% FORM.email.split('=').item(0) %]@[% FORM.domain %]</span>
                </div>
                <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6"></div>
            </div>
        </div>

        <div class="form-group">
            <label id="lblUsage" for="add_email_account">
                [% locale.maketext("Usage") %]
            </label>
            <div class="row">
                <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <span id="usage">[% diskused %]</span> <acronym title="[% locale.maketext("Megabytes") %]">MB</acronym>
                </div>
                <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6"></div>
            </div>
        </div>

        <div class="form-group">
            <label id="lblNewQuota" for="add_email_account">
                [% locale.maketext("New Quota") %]
            </label>
            <div class="row">
                <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="input-group">
                        <input type="text" size="10" id="quota" value="[% popquota %]" class="form-control" />
                        <acronym class="input-group-addon" title="[% locale.maketext("Megabytes") %]">MB</acronym>
                    </div>
                    <input type="hidden" name="quota" id="real_quota" value="250" />
                </div>
                <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6" id="quota_error"></div>
            </div>
        </div>

        <div class="form-group">
            <input type="submit" class="btn btn-primary" id="submit_quota" value="[% locale.maketext("Change") %]" />
        </div>
    </form>
    [% ELSE %]
        <div class="alert alert-danger" role="alert">
            <span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span>
            <div class="alert-message">
                <strong class="alert-title">[% locale.maketext('Error:') %]</strong>
                <span class="alert-body">
                    [% FOREACH err IN get_pop_quota_response.errors %]
                        [% err.html() %]
                    [% END %]
                </span>
            </div>
        </div>
    [% END %]

    [% INCLUDE _assets/return_link.html.tt return_location='../index.html' return_link_text=locale.maketext('Go Back') %]

</div><!-- end body-content -->
[% END #wrapper %]

[% BLOCK js_block %]
<script type="text/javascript">
(function() {

    var MAX_EMAIL_QUOTA = new Number([% execute("Email", "get_max_email_quota_mib").data.json() %]);
    var QUOTA_VAL = new CPANEL.validate.validator("[% locale.maketext("Quota Input") %]");

    /**
     * custom validation function for the quota input
     * @return {Boolean}
     */
    var mailbox_quota = function () {
        var quota = DOM.get("quota").value;

        // add a fallback to check for the english "unlimited" in case they felt like
        // typing in "unlimited" in english instead of their selected locale
        if (quota === [% JSON.stringify(locale.maketext("unlimited")) %] ||
            quota === "unlimited") {
            return true;
        }

        if (CPANEL.validate.integer(quota) === true) {
            return true;
        }

        return false;
    };

    /**
     * Custom validation function for the mailbox quota. This function is a little weird; basically
     * I needed a way to show the user something if they enter a number over 2 gigs, but I didn't want
     * to show them the same error text for the other validation function.
     * @return {Boolean}
     */
    var quota_over_2gigs = function() {
       var quota = DOM.get("quota").value;
       if (CPANEL.validate.integer(quota) == true && (parseInt(quota, 10) > parseInt(MAX_EMAIL_QUOTA, 10))) {
          return false;
       }
       return true;
    };

    /**
     * Check the quota
     */
    var check_quota = function() {
        if (quota_over_2gigs() === false) {
            DOM.get("quota").value = [% JSON.stringify(locale.maketext("unlimited")) %];
            QUOTA_VAL.verify();
        }
    };

    /**
     * Set the quota value to 0 before we submit the form if it's set to unlimited in the interface
     * @return {[type]} [description]
     */
    var fill_in_quota = function() {
        var quota_field_input = DOM.get("quota").value;
        DOM.get("real_quota").value = parseInt(quota_field_input, 10);
        // add a fallback to check for the english "unlimited" in case they felt like
        // typing in "unlimited" in english instead of their selected locale
        if (quota_field_input === [% JSON.stringify(locale.maketext("unlimited")) %] ||
            quota_field_input === "unlimited") {
            DOM.get("real_quota").value = 0;
        }
    };

    /**
     * Initialize the page
     */
    var page_init = function() {
       QUOTA_VAL.add("quota", quota_over_2gigs, [% JSON.stringify(locale.maketext('Quotas cannot exceed [format_bytes,_1].', execute("Email", "get_max_email_quota").data)) %]);
       QUOTA_VAL.add("quota", mailbox_quota, [% JSON.stringify(locale.maketext('Quota must be a number or unlimited.')) %]);
       QUOTA_VAL.attach();

       YAHOO.util.Event.on("quota", "blur", check_quota);

       CPANEL.validate.attach_to_form("submit_quota", QUOTA_VAL, fill_in_quota);
    }

    YAHOO.util.Event.onDOMReady(page_init);
})();
</script>
[% END %]
Back to Directory File Manager