Immediacy : Useful JavaScript Functions For Creating Meta-Data Plugins

Creating The Support Object/How To Access The API
da = window.dialogArguments;                 // Scripting.Dictionary object - allows passing of parameters
// Support object - used to access Immediacy functionality
siteurl = support.GetImageFolder()+"../";
document.write("<script language=\"javascript\" src=\""+siteurl+"plugins/plugin.js\"><\/script>");

Creating A Tree Within The Form

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Case Study Options
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </title>
<style>
BODY                {background-color:buttonface; padding-left:4px; padding-top:4px; padding-right:4px; font-family:tahoma, arial; font-size:8pt;}
.pageEnd            {padding-top:3px; float:right;}
.pageEnd .button    {font-family:tahoma, arial; font-size:8pt; width:60px; height:23px;}
#treeView            {width:100%; height:180px; overflow:auto; background-color:white; border:2px groove; float:left;}
#radioRows            {width:160px; padding-left:5px; float:left;}
</style>
<SCRIPT LANGUAGE="jscript">
da = window.dialogArguments;                // Scripting.Dictionary object - allows passing of parameters
support = da.Item("Support");                // Support object - used to access Immediacy functionality
siteurl = support.GetImageFolder()+"../";
document.write("<script language=\"javascript\" src=\""+siteurl+"plugins/plugin.js\"><\/script>");
var tree;
var checkedPageCount = 0;
function init()
{
var temp;
window.dialogWidth = "350px";
window.dialogHeight = "400px";
PopulateBusinessType();
loadTree();
getSetCategories();
// Set a default return value - just in case the user click on the X
window.returnValue = false;
da = window.dialogArguments;
// If any pre-cusomter data exists populate control
temp = da.Item("customer")
if (temp != undefined)
customer.value = temp;
// If any pre-business type catergories set populate drop-down
temp = da.Item("biztype")
if (temp != undefined)
var rt = temp;
for (var i = 0; i < biztype.length ; i++)
{
if (biztype.options[i].value == rt)            
{ biztype.options[i].selected = true; }
}        
}
function loadTree()
{
rootpageid = GetRegionRoot();
tree = support.CreateTreeView(treeView, rootpageid, true);
tree.onClick = selectPage;
tree.onCheckChanged = checkPage;
tree.start(-1);
}
function GetRegionRoot()
{
var sql = "select * from [option] where Name ='ProductCategories'";
var MetaDataAsXML = support.OpenRecordsetAsXML(sql);
var scXML = new ActiveXObject("MSXML2.FreeThreadedDomDocument.3.0");
scXML.async = false;
scXML.loadXML(MetaDataAsXML);
var scNodes = scXML.selectNodes("Recordset/Row");
var pageID;
if(scNodes.length >0){
return scNodes.item(0).selectSingleNode("StringValue").text;
}
return "";
}
function selectPage(item)
{
tree.addCheck(item.pageID);
checkPage(item);
}
function checkPage(item)
{
var temp;
if (item.pageID == rootpageid)
{
return;
}
temp = da.item("p" + item.pageID);
if (temp != undefined)
{
if (temp == -1)
{
da.item("p" + item.pageID) = item.pageID;
}
else
{
da.item("p" + item.pageID) = -1;
}
}
else
{
da.item("p" + item.pageID) = item.pageID;
}
}
function checkTreeItem(pageID)
{
tree.addCheck(pageID);
}
// This function is fired when the Ok button is clicked
function doOK()
{
da.item("customer") = customer.value;
da.item("biztype") = biztype.options[biztype.selectedIndex].value
// The return value must be set to true otherwise all edits will be lost
window.returnValue=true;
window.close();
}
// Add Business Type Info into drop down
function AddBizTypeOption(formid, formname)
{
opt = new Option(formname, formid, false, false);
biztype.options[biztype.options.length] = opt;
}
</SCRIPT>
<script language="vbscript">
' Populate the Business Type drop down , using the catergory set-up in editor, uses option table value.
function PopulateBusinessType()
strXml = Support.OpenRecordsetAsXML("select * from page_data where p_parent_id = (select StringValue from [option] where Name ='BusinessType'  and UniqueID ='CaseStudies')")
set XMLDom = CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
XMLDom.async = false
XMLDom.loadxml strXML
set aNodes = XMLDom.selectNodes("Recordset/Row")
for i = 0 to aNodes.length -1
AddBizTypeOption aNodes.item(i).SelectSingleNode("p_page_id").text, aNodes.item(i).SelectSingleNode("p_title").text
next
set XMLDOm = nothing
end function
function getSetCategories()
pageID = ""
for each thing in da
if left(thing,1) = "p" then
pageID = mid(thing,2)
if (da.item(thing) <> "-1") then
checkTreeItem(pageID)
end if
end if
next
end function
</script>
</head>
<body scroll="no" onkeypress="document_onkeypress();">
<fieldset>
<label>
<strong>Customer :</strong></label>
<input type="text" id="customer" name="customer" style="width:100%" /><br />
<strong>Business Type :</strong></label>
<select id="biztype" name="biztype" style="width:100%" />
<option value="-1">Please select a business type</option>
</select>
<br />
</fieldset>
<fieldset>
<label>
<strong>Select Product Categories :</strong></label>
<div id="treeView" width="396px"></div>
<div id="radioRows" valign="top" align="left"></div>
</div>
<div>&nbsp;</div>
</fieldset>
<div class="pageEnd">
<input type="submit" class="button" value="OK" id="ok" name="ok" accesskey="o">&nbsp;&nbsp;<input class="button" type="button" value="Cancel" id="cancel" name="cancel"
accesskey="c">
</div>
</body>
</html>

How TO Do a Database Query Within A Plug-in

var row = getSQLResults("select * from META_Description where MetaDataType = 'ExcludePageExpiry'");         
function getSQLResults(SQL)
{
try
{
var PagesAsXML = support.OpenRecordsetAsXML(SQL);
}
catch(err)
{
alert(PagesAsXML);
}
var scXML = new ActiveXObject("MSXML2.FreeThreadedDomDocument.3.0");
scXML.async = false;
scXML.loadXML(PagesAsXML);
var scNodes = scXML.selectNodes("Recordset/Row");
return scNodes;
}

Reading and Writing Properties

Reading from Meta_extended_edited
var temp = da.Item("exclude")
Writing to Meta_extended_edited
da.Item("exclude") = "true";

Get Current Page ID

da.Item("CurrentPage")

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *