/** * Copyright JS Foundation and other contributors, http://js.foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ RED.projects.userSettings = (function() { var gitUsernameInput; var gitEmailInput; function createGitUserSection(pane) { var currentGitSettings = RED.settings.get('git') || {}; currentGitSettings.user = currentGitSettings.user || {}; var title = $('
').text("Committer Details").appendTo(pane); var gitconfigContainer = $('').appendTo(pane); $('').appendTo(gitconfigContainer).text("Leave blank to use system default"); var row = $('').appendTo(gitconfigContainer); $('').text('Username').appendTo(row); gitUsernameInput = $('').appendTo(row); gitUsernameInput.val(currentGitSettings.user.name||""); row = $('').appendTo(gitconfigContainer); $('').text('Email').appendTo(row); gitEmailInput = $('').appendTo(row); gitEmailInput.val(currentGitSettings.user.email||""); } function createSSHKeySection(pane) { var container = $('').appendTo(pane); var popover; var title = $('').text("SSH Keys").appendTo(container); var addKeyButton = $('') .appendTo(title) .click(function(evt) { addKeyButton.attr('disabled',true); addKeyDialog.slideDown(200); keyNameInput.focus(); saveButton.attr('disabled',true); }); var validateForm = function() { var validName = /^[a-zA-Z0-9\-_]+$/.test(keyNameInput.val()); var passphrase = passphraseInput.val(); var validPassphrase = passphrase.length === 0 || passphrase.length >= 8; saveButton.attr('disabled',!validName || !validPassphrase); keyNameInput.toggleClass('input-error',keyNameInputChanged&&!validName); passphraseInput.toggleClass('input-error',!validPassphrase); if (!validPassphrase) { passphraseInputSubLabel.text("Passphrase too short"); } else if (passphrase.length === 0) { passphraseInputSubLabel.text("Optional"); } else { passphraseInputSubLabel.text(""); } if (popover) { popover.close(); popover = null; } }; var row = $('').appendTo(container); var addKeyDialog = $('').hide().appendTo(row); $('',{style:"min-height: 80px"}).appendTo(row); var spinner = utils.addSpinnerOverlay(keyBox).addClass('projects-dialog-spinner-contain'); var options = { url: 'settings/user/keys/'+entry.name, type: "GET", responses: { 200: function(data) { keyBox.text(data.publickey); spinner.remove(); }, 400: { 'unexpected_error': function(error) { console.log(error); spinner.remove(); } }, } } utils.sendRequest(options); var formButtons = $('').appendTo(row); $('') .appendTo(formButtons) .click(function(evt) { evt.preventDefault(); document.getSelection().selectAllChildren(keyBox[0]); var ret = document.execCommand('copy'); document.getSelection().empty(); }); return row; } var keyList = $('').appendTo(row).editableList({ height: 'auto', addButton: false, scrollOnAdd: false, addItem: function(row,index,entry) { var container = $('
').appendTo(row); if (entry.empty) { container.addClass('red-ui-search-empty'); container.text("No SSH keys"); return; } $('').appendTo(container); var topRow = $('').appendTo(container); var content = $('').appendTo(content); $('').text(entry.name).appendTo(topRow); var tools = $('