// +--------------------------------------------------------------------+
// | DO NOT REMOVE THIS |
// +--------------------------------------------------------------------+
// | management.js |
// | Some functions, stuff for documents & folders management. |
// +--------------------------------------------------------------------+
// | Author: Cezary Tomczak [www.gosu.pl] |
// | Project: SimpleDoc |
// | URL: http://gosu.pl/php/simpledoc.html |
// | License: GPL |
// +--------------------------------------------------------------------+
function Fader(id) {
this.start = function() {
this.timerId = setInterval(change, 80);
};
this.stop = function() {
clearInterval(this.timerId);
this.opacity = 80;
this.direction = 0;
document.getElementById(this.id).style.opacity = 1;
document.getElementById(this.id).style.MozOpacity = 1;
document.getElementById(this.id).style.filter = 80;
};
function change() {
self.opacity += (self.direction ? 10 : -10);
document.getElementById(self.id).style.opacity = self.opacity/100;
document.getElementById(self.id).style.MozOpacity = self.opacity/100;
document.getElementById(self.id).style.filter = "alpha(opacity="+self.opacity+")";
if (self.opacity == 20) { self.direction = 1; }
if (self.opacity == 80) { self.direction = 0; }
}
var self = this;
this.id = id;
this.timerId = null;
this.opacity = 80;
this.direction = 0;
}
//var tabsLoading = new Fader("tabs-loading");
//var tabsSaving = new Fader("tabs-saving");
//var AjaxRequest = new AjaxRequest();
//function tabsLoadingOn() { document.getElementById("tabs-loading").style.display = "block"; tabsLoading.start(); }
function tabsLoadingOn() { }
//function tabsLoadingOff() { document.getElementById("tabs-loading").style.display = "none"; tabsLoading.stop(); }
function tabsLoadingOff() { }
//function tabsSavingOn() { document.getElementById("tabs-saving").style.display = "block"; tabsSaving.start(); }
function tabsSavingOn() { }
//function tabsSavingOff() { document.getElementById("tabs-saving").style.display = "none"; tabsSaving.stop(); }
function tabsSavingOff() { }
function documentInfo() {
if (!tree.active || !tree.getActiveNode().isDocument()) {
alert("You have to select a document in the Tree View to perform this action.");
return;
}
checkContentSaved();
AjaxRequest.get(
{
'url':'modules/mx_simpledoc/simpledoc/modules/simpledoc__tab-document-info.php'
,'parameters':{ 'id':escape(treeGetId()), 'block_id':mxBlock.block_id, 'page_id':mxBlock.page_id }
,'onLoading':function() { clearTabs(); tabsLoadingOn(); }
,'onComplete':function() { tabsLoadingOff(); }
,'onSuccess':function(req){ el('tabs-data').innerHTML = req.responseText; updateTabs('tab1'); dhtmlHistory.add( treeGetId(), el(tree.active+"-text").innerHTML );}
,'onError':function(req){ el('tabs-data').innerHTML = 'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText;}
,'timeout':5000
,'onTimeout':function(){ clearTabs(); tabsLoadingOff(); el('tabs-data').innerHTML = 'Timed out. Try again!'; }
}
);
}
function editContent() {
if (!tree.active || !tree.getActiveNode().isDocument()) {
alert("You have to select a document in the Tree View to perform this action.");
return;
}
checkContentSaved();
AjaxRequest.get(
{
'url':'modules/mx_simpledoc/simpledoc/modules/simpledoc__tab-edit-content.php'
,'parameters':{ 'id':escape(treeGetId()), 'block_id':mxBlock.block_id, 'page_id':mxBlock.page_id }
,'onLoading':function() { clearTabs(); tabsLoadingOn(); }
,'onComplete':function() { tabsLoadingOff(); }
,'onSuccess':function(req){ el('tabs-data').innerHTML = req.responseText; initSimpleEditor(); el('body-tmp').value = el('body').value; updateTabs('tab2'); dhtmlHistory.add( treeGetId(), el(tree.active+"-text").innerHTML );}
,'onError':function(req){ el('tabs-data').innerHTML = 'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText;}
,'timeout':5000
,'onTimeout':function(){ clearTabs(); tabsLoadingOff(); el('tabs-data').innerHTML = 'Timed out. Try again!'; }
}
);
}
var ste = null;
function initSimpleEditor(){
ste = new SimpleTextEditor("body", "ste");
ste.path = "modules/mx_simpledoc/simpledoc/shared/SimpleTextEditor/";
ste.charset = "iso-8859-1";
ste.init();
ste.frame.document.onkeydown = keyPress;
// aaa!! next IE bug, editor images not loading :\
if (document.all) {
setTimeout(loadEditorImages, 50);
}
}
function documentPreview() {
if (!tree.active || !tree.getActiveNode().isDocument()) {
alert("You have to select a document in the Tree View to perform this action.");
return;
}
AjaxRequest.get(
{
'url':'modules/mx_simpledoc/simpledoc/modules/simpledoc__tab-view-content.php'
,'parameters':{ 'id':escape(treeGetId()), 'block_id':mxBlock.block_id, 'page_id':mxBlock.page_id }
,'onLoading':function() { clearTabs(); tabsLoadingOn(); }
,'onComplete':function() { tabsLoadingOff(); }
,'onSuccess':function(req){ el('tabs-data').innerHTML = addTocDiv(stripBodyHtml(req.responseText)); generateTOC('index'); updateTabs('tab3'); }
,'onError':function(req){ el('tabs-data').innerHTML = 'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText;}
,'timeout':5000
,'onTimeout':function(){ clearTabs(); tabsLoadingOff(); el('tabs-data').innerHTML = 'Timed out. Try again!'; }
}
);
}
function documentView() {
if (!tree.active || !tree.getActiveNode().isDocument()) {
alert("You have to select a document in the Tree View to perform this action.");
return;
}
AjaxRequest.get(
{
'url':'modules/mx_kb/kb/modules/tabs/kb__tab-view.php'
,'parameters':{ 'mode':'article', 'k': escape(treeGetId().substr(treeGetId().lastIndexOf("/")+1)), 'id': escape(treeGetId()), 'block_id':mxBlock.block_id, 'page_id':mxBlock.page_id }
,'onLoading':function() { clearTabs(); tabsLoadingOn(); }
,'onComplete':function() { tabsLoadingOff(); }
,'onSuccess':function(req){ el('tabs-data').innerHTML = stripBodyHtml(req.responseText); generateParentTOC('view'); generateTOC('view');}
,'onError':function(req){ el('tabs-data').innerHTML = 'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText; }
,'timeout':5000
,'onTimeout':function(){ clearTabs(); tabsLoadingOff(); el('tabs-data').innerHTML = 'Timed out. Try again!'; }
}
);
}
function saveContent(theform) {
tabsSavingOn();
el('save-document').disabled = true;
//el('tabs-data').style.visibility = "hidden";
var status = AjaxRequest.submit(
theform
,{
'onSuccess':function(req){ }
}
);
el('save-document').disabled = false;
el('body-tmp').value = el('body').value;
tabsSavingOff();
//var data = {"body": el('body').value}
//var save = httpSave("modules/mx_simpledoc/simpledoc/modules/simpledoc__tab-save-content.php?id="+escape(treeGetId())+'&block_id='+mxBlock.block_id+'&page_id='+mxBlock.page_id, data);
if ((typeof status == "boolean" && !status) || typeof status == "string") {
alert("Unknown error, cannot save document.");
} else {
el("saved").innerHTML = "Saved successfuly on "+(new Date()+"
(this message will disappear in 3 seconds)");
if (savedTimerID) clearTimeout(savedTimerID);
savedTimerID = setTimeout(function(){ el("saved").innerHTML = ""; }, 3000);
}
return status;
}
// The top right toc
// this snippet doesn't work if there is a folder named "html"
// Only used when the doc is generated as part of the app - inline (scripts are stripped in plain code)
function generateTOC(mode) {
var contents = "";
var link = escape(treeGetId());
contents = '