/**
* 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.settings = (function() {
var trayWidth = 700;
var settingsVisible = false;
var panes = [];
function addPane(options) {
panes.push(options);
}
// TODO: DRY - tab-info.js
function addTargetToExternalLinks(el) {
$(el).find("a").each(function(el) {
var href = $(this).attr('href');
if (/^https?:/.test(href)) {
$(this).attr('target','_blank');
}
});
return el;
}
function show(initialTab) {
if (settingsVisible) {
return;
}
settingsVisible = true;
var tabContainer;
var trayOptions = {
title: "Project Information",// RED._("menu.label.userSettings"),, // TODO: nls
buttons: [
{
id: "node-dialog-ok",
text: RED._("common.label.close"),
class: "primary",
click: function() {
RED.tray.close();
}
}
],
resize: function(dimensions) {
trayWidth = dimensions.width;
},
open: function(tray) {
var project = RED.projects.getActiveProject();
var trayBody = tray.find('.editor-tray-body');
var settingsContent = $('
').appendTo(trayBody);
var tabContainer = $('',{id:"user-settings-tabs-container"}).appendTo(settingsContent);
$('
').appendTo(row);
if (entry.empty) {
container.addClass('red-ui-search-empty');
container.text("No branches");
return;
}
if (entry.current) {
container.addClass("current");
}
$('').appendTo(container);
var content = $('').appendTo(container);
var topRow = $('
').appendTo(content);
$('').text(entry.name).appendTo(topRow);
if (entry.commit) {
$('').text(entry.commit.sha).appendTo(topRow);
}
if (entry.remote) {
var bottomRow = $('
').appendTo(content);
$('').text(entry.remote||"").appendTo(bottomRow);
if (entry.status.ahead+entry.status.behind > 0) {
$(''+
' '+entry.status.ahead+' '+
' '+entry.status.behind+''+
'').appendTo(bottomRow);
}
}
if (!entry.current) {
var tools = $('').appendTo(container);
$('')
.appendTo(tools)
.click(function(e) {
e.preventDefault();
var spinner = utils.addSpinnerOverlay(row).addClass('projects-dialog-spinner-contain');
var notification = RED.notify("Are you sure you want to delete the local branch '"+entry.name+"'? This cannot be undone.", {
type: "warning",
modal: true,
fixed: true,
buttons: [
{
text: RED._("common.label.cancel"),
click: function() {
spinner.remove();
notification.close();
}
},{
text: 'Delete branch',
click: function() {
notification.close();
var url = "projects/"+activeProject.name+"/branches/"+entry.name;
var options = {
url: url,
type: "DELETE",
responses: {
200: function(data) {
row.fadeOut(200,function() {
branchList.editableList('removeItem',entry);
spinner.remove();
});
},
400: {
'git_delete_branch_unmerged': function(error) {
notification = RED.notify("The local branch '"+entry.name+"' has unmerged changes that will be lost. Are you sure you want to delete it?", {
type: "warning",
modal: true,
fixed: true,
buttons: [
{
text: RED._("common.label.cancel"),
click: function() {
spinner.remove();
notification.close();
}
},{
text: 'Delete unmerged branch',
click: function() {
options.url += "?force=true";
notification.close();
utils.sendRequest(options);
}
}
]
});
},
'unexpected_error': function(error) {
console.log(error);
spinner.remove();
}
},
}
}
utils.sendRequest(options);
}
}
]
})
})
}
}
});
$.getJSON("projects/"+activeProject.name+"/branches",function(result) {
if (result.branches) {
if (result.branches.length > 0) {
result.branches.sort(function(A,B) {
if (A.current) { return -1 }
if (B.current) { return 1 }
return A.name.localeCompare(B.name);
});
result.branches.forEach(function(branch) {
branchList.editableList('addItem',branch);
})
} else {
branchList.editableList('addItem',{empty:true});
}
}
})
}
function createRemoteRepositorySection(activeProject,pane) {
$('').text("Version Control").appendTo(pane);
createLocalBranchListSection(activeProject,pane);
var repoContainer = $('').appendTo(pane);
var title = $('').text("Git remotes").appendTo(repoContainer);
var editRepoButton = $('')
.appendTo(title)
.click(function(evt) {
editRepoButton.attr('disabled',true);
addRemoteDialog.slideDown(200, function() {
addRemoteDialog[0].scrollIntoView();
});
});
var emptyItem = { empty: true };
var row = $('').appendTo(repoContainer);
var addRemoteDialog = $('').hide().appendTo(row);
row = $('').appendTo(repoContainer);
var remotesList = $('').appendTo(row);
remotesList.editableList({
addButton: false,
height: 'auto',
addItem: function(row,index,entry) {
var container = $('
').appendTo(row);
if (entry.empty) {
container.addClass('red-ui-search-empty');
container.text("No remotes");
return;
} else {
$('').appendTo(container);
var content = $('').appendTo(container);
$('
').text(entry.name).appendTo(content);
if (entry.urls.fetch === entry.urls.push) {
$('