/**
* Copyright 2013 IBM Corp.
*
* 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.library = function() {
function loadFlowLibrary() {
d3.json("library/flows",function(data) {
//console.log(data);
var buildMenu = function(data,root) {
var ul = document.createElement("ul");
ul.className = "dropdown-menu";
if (data.d) {
for (var i in data.d) {
var li = document.createElement("li");
li.className = "dropdown-submenu pull-left";
var a = document.createElement("a");
a.href="#";
a.innerHTML = i;
li.appendChild(a);
li.appendChild(buildMenu(data.d[i],root+(root!=""?"/":"")+i));
ul.appendChild(li);
}
}
if (data.f) {
for (var i in data.f) {
var li = document.createElement("li");
var a = document.createElement("a");
a.href="#";
a.innerHTML = data.f[i];
a.flowName = root+(root!=""?"/":"")+data.f[i];
a.onclick = function() {
$.get('library/flows/'+this.flowName, function(data) {
RED.view.importNodes(data);
});
};
li.appendChild(a);
ul.appendChild(li);
}
}
return ul;
};
var menu = buildMenu(data,"");
$("#flow-menu-parent>ul").replaceWith(menu);
});
}
loadFlowLibrary();
function createUI(options) {
var libraryData = {};
var selectedLibraryItem = null;
var libraryEditor = null;
function buildFileListItem(item) {
var li = document.createElement("li");
li.onmouseover = function(e) { $(this).addClass("list-hover"); };
li.onmouseout = function(e) { $(this).removeClass("list-hover"); };
return li;
}
function buildFileList(root,data) {
var ul = document.createElement("ul");
for (var i in data) {
var v = data[i];
if (typeof v === "string") {
// directory
var li = buildFileListItem(v);
li.onclick = function () {
var dirName = v;
return function(e) {
var bcli = $('