App-Netdisco

 view release on metacpan or  search on metacpan

share/views/ajax/admintask/users.tt  view on Meta::CPAN

            <input data-form="del" name="username" type="hidden" value="[% row.username | html_entity %]">
          </div>
          <div class="modal-footer">
            <button class="btn btn-success" data-dismiss="modal" aria-hidden="true">Cancel</button>
            <button class="btn btn-danger nd_adminbutton" name="del" data-dismiss="modal">Confirm</button>
          </div>
        </div>
      </td>
    </tr>
    [% END %]
  </tbody>
</table>

<div id="nd_token-reveal" class="nd_modal nd_deep-horizon modal hide fade" tabindex="-1" role="dialog">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">x</button>
    <h3>API Token</h3>
  </div>
  <div class="modal-body">
    <p class="text-info">Copy this token — it will not be shown again.</p>
    <div class="input-append">
      <input id="nd_token-value" type="text" class="span4" readonly>
      <button class="btn" id="nd_token-copy" type="button"><i class="icon-copy"></i> Copy</button>
    </div>
  </div>
  <div class="modal-footer">
    <button class="btn btn-success" data-dismiss="modal">Done</button>
  </div>
</div>

<script>
$(document).ready(function() {
  function toggleTokenFields(select) {
    var row  = $(select).closest('tr');
    var pw   = row.find('.nd_pw_field');
    var cell = pw.closest('td');
    var hint = row.find('.nd_token_hint');
    var ips  = row.find('.nd_allowed_ips_field');
    var btn  = row.find('.nd_tokenbutton');
    if ($(select).val() === 'permanent_token') {
      pw.hide().val('').prop('disabled', true);
      cell.addClass('nd_center-middle-cell');
      cell.removeClass('nd_center-cell');
      hint.show();
      btn.show();
      ips.prop('disabled', false);
    } else {
      pw.show().prop('disabled', false).attr('placeholder', '');
      cell.addClass('nd_center-cell');
      cell.removeClass('nd_center-middle-cell');
      hint.hide();
      btn.hide();
      ips.val('').prop('disabled', true);
    }
  }
  $('.nd_auth_method').each(function() { toggleTokenFields(this); });
  $(document).on('change', '.nd_auth_method', function() { toggleTokenFields(this); });

  $('#nd_token-reveal').modal({show: false});
  $('#nd_token-copy').on('click', function() {
    navigator.clipboard.writeText($('#nd_token-value').val());
    $(this).html('<i class="icon-ok"></i> Copied');
  });

  // Called by admintask.js when the server returns a data-nd-api-key span
  window.nd_show_api_token = function(apiKey) {
    $('#nd_token-value').val(apiKey);
    $('#nd_token-copy').html('<i class="icon-copy"></i> Copy');
    $('#nd_token-reveal').one('hidden', function() {
      var tab = '[% task.tag | html_entity %]';
      $('#' + tab + '_form').trigger('submit');
    });
    $('#nd_token-reveal').modal('show');
  };

  $(document).on('click', '.nd_tokenbutton', function() {
    var username  = $(this).data('username');
    var hint = $(this).closest('td').find('.nd_token-hint-value');
    $.get(uri_base + '/ajax/control/admin/users/token', { username: username, permanent: 1 }, function(apiKey) {
      apiKey = $.trim(apiKey);
      if (apiKey && typeof window.nd_show_api_token === 'function') {
        $(hint).text('...' + apiKey.slice(-8));
        window.nd_show_api_token(apiKey);
      } else {
        toastr.error('Could not retrieve token');
      }
    }, 'text').fail(function() {
      toastr.error('Could not retrieve token');
    });
  });

  $('#data-table').dataTable({
    "columnDefs": [
      {
        "targets": [ 2, 3, 4, 5, 6, 7, 8, 9, 10 ],
        "searchable": false
      },
      {
        "targets": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ],
        "orderable": false
      }
    ],
[% INCLUDE 'ajax/datatabledefaults.tt' -%]
  } );
} );
</script>



( run in 1.599 second using v1.01-cache-2.11-cpan-84e82930d8c )