in src/main/resources/SLING-INF/libs/sling/resource-editor/static/js/tree/AddNodeController.js [184:294]
AddNodeController.prototype.openAddNodeDialog = function(resourcePath, nodeTypeName) {
var thatAddNodeController = this;
var resTypeHelpElement = $('#addNodeDialog .resource-type-not-allowed');
resTypeHelpElement.hide();
this.nodeTypeName = nodeTypeName;
var nodeType = mainController.ntManager.getNodeType(this.nodeTypeName);
var appliCnTypesByNodeName = nodeType.getApplicableCnTypesPerCnDef(false /*include mixins*/);
var nodeNameListStar = Object.keys(appliCnTypesByNodeName);
var nodeHelpElement = $('#addNodeDialog .only-listed-node-names-allowed');
var indexOfResidualDef = nodeNameListStar.indexOf("*");
var residualsDefined = indexOfResidualDef >= 0;
if (residualsDefined){
nodeNameListStar.splice(indexOfResidualDef, 1);
nodeHelpElement.parents(".form-group").addClass("has-warning");
nodeHelpElement.hide();
} else {
nodeHelpElement.parents(".form-group").addClass("has-warning");
nodeHelpElement.show();
}
nodeNameListStar.sort();
nodeNameListStar.unshift("");
var nodeNameObjects = jQuery.map(nodeNameListStar, function( nt, i ) {
return {id: nt, text: nt};
});
$('#nodeName').select2('data', null);
$("#nodeName").select2({
placeholder: "Enter or select a node name",
allowClear: true,
selectOnBlur: true,
dropdownCssClass: "node_name_dd_container",
data: nodeNameObjects,
createSearchChoice: function(searchTerm){
thatAddNodeController.latestEnteredNodeName = searchTerm;
return {id:searchTerm, text:searchTerm};
}
});
$("#nodeName").on("select2-open", function(e) {
thatAddNodeController.nodeNameSubmitable=false;
});
$("#nodeName").on("select2-close", function(e) {
thatAddNodeController.nodeNameSubmitable=true;
});
var nodeNameList = Object.keys(appliCnTypesByNodeName);
nodeNameList.sort();
thatAddNodeController.nodeTypeObjects = getNodeTypesByDependenyState.call(thatAddNodeController, nodeNameList, appliCnTypesByNodeName, thatAddNodeController.nodeTypeObjects);
$("#nodeName").on("change", function(e) {
thatAddNodeController.nodeTypeObjects = getNodeTypesByDependenyState.call(thatAddNodeController, nodeNameList, appliCnTypesByNodeName, thatAddNodeController.nodeTypeObjects);
});
$("#nodeType").on("change", function(e) {
var nodeTypeName = $("#nodeType").val();
var nodeType = mainController.ntManager.getNodeType(nodeTypeName);
var canAddResourceType = nodeType.canAddProperty("sling:resourceType", "String");
if (canAddResourceType){
resTypeHelpElement.hide();
} else {
resTypeHelpElement.parents(".form-group").addClass("has-warning");
resTypeHelpElement.show();
}
});
$('#nodeType').select2('data', null);
$("#nodeType").select2({
placeholder: "Select a node type",
allowClear: true,
dropdownCssClass: "node_type_dd_container",
selectOnBlur: true,
data: function() {
return { results: thatAddNodeController.nodeTypeObjects } ; // Use the global variable to populate the list
}
});
var contextPath = this.mainController.getContextPath() == "/" && resourcePath.length>0 && resourcePath.charAt(0)=="/" ? "" : this.mainController.getContextPath();
this.lastAddNodeURL = contextPath+resourcePath;
$('#newResourceType').select2('data', null);
var contextPath = this.mainController.getContextPath();
contextPath = "/" === contextPath ? "" : contextPath;
var url = contextPath+"/libs/sling/resource-editor/content/content-nodes/resource-types.json";
$.getJSON(url, function( origData ) {
var data = jQuery.map( origData, function( n, i ) {
return ( {id:n, text:n} );
});
data.unshift({id:"",text:""});
var select2 = $("#newResourceType").select2({
placeholder: "Enter or select a resource type",
allowClear: true,
dropdownCssClass: "resource_type_dd_container",
selectOnBlur: true,
data: data,
createSearchChoice: function(searchTerm){
thatAddNodeController.latestEnteredResType = searchTerm;
return {id:searchTerm, text:searchTerm};
}
}).data("select2");
$("#newResourceType").on("select2-open", function(e) {
thatAddNodeController.resourceTypeSubmitable=false;
});
$("#newResourceType").on("select2-close", function(e) {
thatAddNodeController.resourceTypeSubmitable=true;
});
$('#addNodeDialog').modal('show');
$('#addNodeDialog').addClass('add-node-finished');
});
}