~bestpractical/rt/master

« back to all changes in this revision

Viewing changes to share/html/Elements/AuthToken/Create

  • Committer: sunnavy
  • Date: 2023-10-19 19:45:11 UTC
  • mfrom: (8471.1.577)
  • Revision ID: git-v1:9fca83d11d15fb8034308194b9c9052d5df7d454
Merge branch '5.0-trunk'

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
        </a>
56
56
      </div>
57
57
      <div class="modal-body">
58
 
        <form method="POST">
 
58
        <form method="POST" id="createAuthToken">
59
59
          <input type="hidden" name="Owner" value="<% $Owner %>">
60
60
%         if ( $require_password ){
61
61
          <div class="row mt-2">
76
76
              <input class="form-control" type="text" name="Description" value="<% $Description %>" size="16" />
77
77
            </div>
78
78
          </div>
 
79
          <div class="row">
 
80
            <div class="label col-4">
 
81
              <span class="prev-icon-helper"><&|/l&>Expires</&>:</span>\
 
82
<span class="far fa-question-circle icon-helper" data-toggle="tooltip" data-placement="top" data-original-title="<% loc("Set an optional Expires date?") %>"></span>
 
83
            </div>
 
84
            <div class="col-8 mt-2">
 
85
              <div class="form-check">
 
86
                <input type="checkbox" id="ExpiresCheckbox" name="ExpiresCheckbox" class="form-check-input checkbox" value="0" />
 
87
                <label class="form-check-label" for="ExpiresCheckbox">Set Expires Date</label>
 
88
              </div>
 
89
            </div>
 
90
          </div>
 
91
          <div class="row mt-2">
 
92
            <div class="label col-4">
 
93
            </div>
 
94
            <div class="col-8">
 
95
              <select name="ExpiresSelect" id="ExpiresSelect" class="form-control selectpicker">
 
96
                <option value="1M" ><&|/l, 1 &>[quant,_1,Month,Months]</&></option>
 
97
                <option value="3M"><&|/l, 3 &>[quant,_1,Month,Months]</&></option>
 
98
                <option value="6M"><&|/l, 6 &>[quant,_1,Month,Months]</&></option>
 
99
                <option value="1Y"><&|/l, 1 &>[quant,_1,Year,Years]</&></option>
 
100
                <option value="Custom"><&|/l&>Custom Date</&></option>
 
101
              </select>
 
102
            </div>
 
103
          </div>
 
104
          <div class="row mt-2">
 
105
            <div class="label col-4">
 
106
            </div>
 
107
            <div class="col-8">
 
108
              <& /Elements/SelectDate, Name=>"Expires", id=>"Expires", Default => $Expires, ShowTime => 1 &>
 
109
            </div>
 
110
          </div>
79
111
 
80
112
          <& /Elements/Submit, Label => loc("Create"), Name => 'Create', FullWidth => 1 &>
81
113
        </form>
84
116
  </div>
85
117
</div>
86
118
 
 
119
<script>
 
120
  jQuery("#ExpiresSelect").prop( "disabled", true );
 
121
  jQuery("#Expires").prop( "disabled", true );
 
122
 
 
123
  // Expires input needs to be enabled when the form is submitted to read its value
 
124
  jQuery("#createAuthToken").submit(
 
125
    function(e){
 
126
      jQuery("#Expires").prop( "disabled", false );
 
127
      return true;
 
128
    }
 
129
  );
 
130
 
 
131
  var onExpiresSelectChange = function() {
 
132
    var expiresSelectVal = jQuery("#ExpiresSelect option:selected").val();
 
133
    var expires          = jQuery("#Expires");
 
134
 
 
135
    // make sure expires is enabled so we can change value
 
136
    expires.prop( "disabled", false );
 
137
    if ( jQuery("#ExpiresSelect").prop("disabled") ) {
 
138
      // Expires date options are disabled so Expires should be blank
 
139
      expires.val("");
 
140
    } else {
 
141
      // Expires date options are enabled so determine what we should set
 
142
      // Expires value to based on selected Expires option
 
143
      if ( expiresSelectVal != 'Custom' ) {
 
144
        var date   = new Date();
 
145
        var regexp = /(\d)(\w)/;
 
146
        var match  = expiresSelectVal.match(regexp);
 
147
 
 
148
        if ( match != null ) {
 
149
          if ( match[2] == "M" ) {
 
150
            date.setMonth( date.getMonth() + parseInt( match[1] ) );
 
151
          } else {
 
152
            date.setFullYear( date.getFullYear() + parseInt( match[1] ) );
 
153
          }
 
154
          expires.val( date.toISOString().substr(0, 10) + ' 00:00:00' );
 
155
        }
 
156
      }
 
157
    }
 
158
 
 
159
    // now enable/disable expires
 
160
    expires.prop( "disabled", expiresSelectVal != "Custom" );
 
161
  };
 
162
 
 
163
  jQuery("#ExpiresCheckbox").click(
 
164
    function(){
 
165
      var expiresSelect = jQuery("#ExpiresSelect");
 
166
 
 
167
      var disable = true;
 
168
      if ( expiresSelect.prop("disabled") ) {
 
169
        // user is enabling the Expires date options
 
170
        disable = false;
 
171
      } else {
 
172
        // user is disabling the Expires date options
 
173
        disable = true;
 
174
 
 
175
        // set back to default value
 
176
        expiresSelect.val("1M");
 
177
 
 
178
        jQuery(".selectpicker").selectpicker("refresh");
 
179
      }
 
180
 
 
181
      expiresSelect.prop( "disabled", disable );
 
182
 
 
183
      jQuery(".selectpicker").selectpicker("refresh");
 
184
      onExpiresSelectChange();
 
185
    }
 
186
  );
 
187
  jQuery("#ExpiresSelect").change(
 
188
    function(){
 
189
      onExpiresSelectChange();
 
190
    }
 
191
  );
 
192
</script>
 
193
 
87
194
<%INIT>
88
195
# Don't require password for systems with some form of federated auth,
89
196
# or if configured to not require a password
97
204
<%ARGS>
98
205
$Owner
99
206
$Description => ''
 
207
$Expires => ''
100
208
</%ARGS>