91 lines
2.4 KiB
JavaScript
91 lines
2.4 KiB
JavaScript
|
|
function fileSelectorControl(fileData) {
|
||
|
|
var m_displayDom=document.createElement("div");
|
||
|
|
m_displayDom.setAttribute("class","fileSelector");
|
||
|
|
var m_selectedFile=null ;
|
||
|
|
var m_fileList=null;
|
||
|
|
|
||
|
|
return(construct());
|
||
|
|
|
||
|
|
function construct() {
|
||
|
|
update(fileData);
|
||
|
|
addActionButtons();
|
||
|
|
m_displayDom.isVisible;
|
||
|
|
m_displayDom.show=show;
|
||
|
|
m_displayDom.hide=hide;
|
||
|
|
m_displayDom.update=update;
|
||
|
|
|
||
|
|
return(m_displayDom);
|
||
|
|
}
|
||
|
|
function update(fileData){
|
||
|
|
var fileList=document.createElement("ul");
|
||
|
|
fileList.setAttribute("class","fileList");
|
||
|
|
var allFiles=fileData.childNodes;
|
||
|
|
for (var i=0;i<allFiles.length;i++) {
|
||
|
|
var theFile=allFiles[i];
|
||
|
|
var singleFileEle=document.createElement("li");
|
||
|
|
singleFileEle.setAttribute("class","unselected");
|
||
|
|
singleFileEle.setAttribute("filepkey",theFile.getAttribute("pkey"));
|
||
|
|
singleFileEle.appendChild(theFile.firstChild);
|
||
|
|
singleFileEle.onclick=onClickFile;
|
||
|
|
singleFileEle.select=select;
|
||
|
|
singleFileEle.unselect=unselect;
|
||
|
|
fileList.appendChild(singleFileEle);
|
||
|
|
}
|
||
|
|
if (!m_fileList) {
|
||
|
|
m_fileList=fileList;
|
||
|
|
m_displayDom.appendChild(m_fileList);
|
||
|
|
} else {
|
||
|
|
m_fileList.parentNode.replaceChild(fileList,m_fileList);
|
||
|
|
m_fileList=fileList;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function addActionButtons(){
|
||
|
|
var btnContainer=document.createElement("div");
|
||
|
|
btnContainer.setAttribute("class","btnContainer");
|
||
|
|
|
||
|
|
var menuItems=new Array();
|
||
|
|
menuItems[menuItems.length]=new textMenuItem("Load",onLoadClick);
|
||
|
|
menuItems[menuItems.length]=new textMenuItem("Delete",onDeleteClick,"contextMenuItemRed");
|
||
|
|
|
||
|
|
btnContainer.appendChild(new menuControl(menuItems,0));
|
||
|
|
|
||
|
|
m_displayDom.appendChild(btnContainer);
|
||
|
|
}
|
||
|
|
function onClickFile() {
|
||
|
|
if (m_selectedFile != null) {
|
||
|
|
m_selectedFile.unselect();
|
||
|
|
}
|
||
|
|
this.select();
|
||
|
|
}
|
||
|
|
function unselect() {
|
||
|
|
this.selected=false;
|
||
|
|
this.setAttribute("class","unselected");
|
||
|
|
m_selectedFile=null;
|
||
|
|
}
|
||
|
|
function select() {
|
||
|
|
this.selected=true;
|
||
|
|
this.setAttribute("class","selected");
|
||
|
|
m_selectedFile=this;
|
||
|
|
}
|
||
|
|
function onDeleteClick() {
|
||
|
|
if (m_selectedFile) {
|
||
|
|
deleteMap(m_selectedFile.getAttribute("filePKey"));
|
||
|
|
update(getFileList());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function onLoadClick() {
|
||
|
|
if (m_selectedFile) {
|
||
|
|
loadMap(m_selectedFile.getAttribute("filepkey"));
|
||
|
|
m_displayDom.parentNode.setFileDescription(m_selectedFile.firstChild.nodeValue);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function hide() {
|
||
|
|
m_displayDom.isVisible=false;
|
||
|
|
m_displayDom.style.display="none";
|
||
|
|
}
|
||
|
|
function show() {
|
||
|
|
m_displayDom.isVisible=true;
|
||
|
|
m_displayDom.style.display="block";
|
||
|
|
}
|
||
|
|
}
|