//========================================== //Syscom.GM.jQuery //------------------------------------------ // Requires: // * JQuery library // * //INITIALIZE THE API function registerNS(ns) { var nsParts = ns.split("."); var root = window; for (var i = 0; i < nsParts.length; i++) { if (typeof root[nsParts[i]] == "undefined") { root[nsParts[i]] = new Object(); } root = root[nsParts[i]]; } } ///// !!! Do this first so the namespace is available registerNS("Syscom.GM.Script.API"); var $GM = Syscom.GM.Script.API ///// GLOBAL VARIABLES var viewPortHeight; var viewPortWidth; ///// ENUMS Syscom.GM.Script.API.Enums = new function () { this.WindowPosition = { TopLeft: 1, TopMiddle: 2, TopRight: 3, MiddleLeft: 4, Middle: 5, MiddleRight: 6, BottomLeft: 7, BottomMiddle: 8, BottomRight: 9 }; } ///// BASE Syscom.GM.Script.API.Base = new function () { this.Property = function (value) { var _value = value; this.getValue = function () { return _value; } this.setValue = function (value) { _value = value; } } } ///// TELERIK ///// These methods were designed for the Q2 2009 release of the Telerik controls. Syscom.GM.Script.API.Telerik = new function () { ///// Attaches an resize event handler to the editor this.attachEditorResizeEvents = function (sender, e) { sender.InitialHeight = -1; sender.get_contentArea().style.overflow = "hidden"; sender.get_document().body.scroll = "no"; var resizeFnRef = function anon() { Syscom.GM.Script.API.Telerik.resizeEditorContentArea(sender) }; sender.attachEventHandler("RADEVENT_SEL_CHANGED", resizeFnRef) sender.attachEventHandler("keydown", resizeFnRef) } ///// Sets the height of the editor window to ??? this.resizeEditorContentArea = function (sender, e) { if (sender.InitialHeight == -1) { sender.InitialHeight = sender.get_document().body.clientHeight; } var ie = document.all ? true : false; var oDoc = sender.get_document(); var targetHeight = ie ? oDoc.body.scrollHeight : oDoc.documentElement.scrollHeight; if (targetHeight > sender.InitialHeight) { var theIFrame = document.getElementById("RadEContentIframe" + sender.Id); theIFrame.style.height = parseInt(targetHeight) + "px"; if (!ie) sender.SetSize(sender.GetWidth(), targetHeight); //FireFox bug, TD does not decrease height } } ///// Expands a RadComboBox Control this.expandComboBoxDropDown = function (sender, e) { sender.showDropDown(); } ///// Resizes a RadComboBox to the height of the elements this.autoResizeComboBoxDropDown = function (sender, e) { var dropDownDiv = $get(sender.DropDownID); var maxDropDownHeight = 240 var dropDownHeight = MaxDropDownHeight; if (comboBox.Items.length == 0) { dropDownDiv.style.height = intHeightMin; return; } try { if (comboBox.Items.length > 1) { var strItemClientID = $get(sender.Items[1].ClientID); if (strItemClientID) { dropDownHeight = strItemClientID.offsetHeight * sender.Items.length } } } catch (e) { dropDownHeight = maxDropDownHeight } if (dropDownHeight > maxDropDownHeight || dropDownHeight == 0) { dropDownDiv.style.height = maxDropDownHeight; } else { dropDownDiv.style.height = dropDownHeight; } } } ///// STRING Syscom.GM.Script.API.String = new function () { this.trim = function (str, chars) { return Syscom.GM.Script.API.String.trimLeft(Syscom.GM.Script.API.String.trimRight(str, chars), chars); } this.trimLeft = function (str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), ""); } this.trimRight = function (str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("[" + chars + "]+$", "g"), ""); } } ///// COMMON Syscom.GM.Script.API.Common = new function () { this.getViewPortDimensions = function () { if (document.all) { viewPortWidth = document.body.clientWidth; viewPortHeight = document.body.clientHeight; } else { viewPortWidth = window.innerWidth; viewPortHeight = window.innerHeight; } } this.addResizeListener = function (fn) { if (typeof window.addEventListener != 'undefined') { window.addEventListener('resize', fn, false); } else if (typeof document.addEventListener != 'undefined') { document.addEventListener('resize', fn, false); } else if (typeof window.attachEvent != 'undefined') { window.attachEvent('onresize', fn); } else { var oldfn = window.onload; if (typeof window.onresize != 'function') { window.onresize = fn; } else { window.onresize = function () { oldfn(); fn(); } } } } this.addLoadFunction = function (fn) { var oldfn = window.onload; if (typeof window.onload != 'function') { window.onload = fn; } else { window.onload = function () { oldfn(); fn(); } } } this.addUnLoadFunction = function (fn) { var oldfn = window.onunload; if (typeof window.onunload != 'function') { window.onunload = fn; } else { window.onunload = function () { oldfn(); fn(); } } } /* Telerik Utilities */ ///// Expands a RadComboBox Control this.expandDropDown = function (sender, e) { sender.showDropDown(); } this.open_win = function (url, the_x, the_y, toolbar, addressbar, directories, statusbar, menubar, scrollbar, resize, history, pos, winName) { //debugger; var the_win = winName; var the_url = url; var option; the_x -= 0; the_y -= 0; var how_wide = screen.availWidth; var how_high = screen.availHeight; var the_toolbar; var the_addressbar; var the_directories; var the_statusbar; var the_menubar; var the_do_resize; var the_copy_history; if (toolbar == "0" && toolbar != true) { the_toolbar = "no"; } else { the_toolbar = "yes"; } if (addressbar == "0" && addressbar != true) { the_addressbar = "no"; } else { the_addressbar = "yes"; } if (directories == "0" && directories != true) { the_directories = "no"; } else { the_directories = "yes"; } if (statusbar == "0" && statusbar != true) { the_statusbar = "no"; } else { the_statusbar = "yes"; } if (menubar == "0" && menubar != true) { the_menubar = "no"; } else { the_menubar = "yes"; } if (scrollbar == "0" && scrollbar != true) { the_scrollbars = "no"; } else { the_scrollbars = "yes"; } if (resize == "0" && resize != true) { the_do_resize = "no"; } else { the_do_resize = "yes"; } if (history == "0" && history != true) { the_copy_history = "no"; } else { the_copy_history = "yes"; } //---------------- // Window Position // Top Left if (pos == 1) { top_pos = 0; left_pos = 0; } //Middle // Top Middle if (pos == 2) { top_pos = 0; left_pos = (how_wide / 2) - (the_x / 2); } // Top Right if (pos == 3) { top_pos = 0; left_pos = how_wide - the_x; } // Middle Left if (pos == 4) { top_pos = (how_high / 2) - (the_y / 2); left_pos = 0; } // Middle if (pos == 5) { top_pos = (how_high / 2) - (the_y / 2); left_pos = (how_wide / 2) - (the_x / 2); } // Middle Right if (pos == 6) { top_pos = (how_high / 2) - (the_y / 2); left_pos = how_wide - the_x; } // Bottom Left if (pos == 7) { top_pos = how_high - the_y; left_pos = 0; } // Bottom Middle if (pos == 8) { top_pos = how_high - the_y; left_pos = (how_wide / 2) - (the_x / 2); } // Bottom right if (pos == 9) { top_pos = how_high - the_y; left_pos = how_wide - the_x; } //debugger; //------------- // Open Window if (window.outerWidth) { option = "toolbar=" + the_toolbar + ",location=" + the_addressbar + ",directories=" + the_directories + ",status=" + the_statusbar + ",menubar=" + the_menubar + ",scrollbars=" + the_scrollbars + ",resizable=" + the_do_resize + ",outerWidth=" + the_x + ",outerHeight=" + the_y + ",copyhistory=" + the_copy_history + ",left=" + left_pos + ",top=" + top_pos; the_win = window.open(the_url, winName, option); the_win.focus(); } else { option = "toolbar=" + the_toolbar + ",location=" + the_addressbar + ",directories=" + the_directories + ",status=" + the_statusbar + ",menubar=" + the_menubar + ",scrollbars=" + the_scrollbars + ",resizable=" + the_do_resize + ",Width=" + the_x + ",Height=" + the_y + ",copyhistory=" + the_copy_history + ",left=" + left_pos + ",top=" + top_pos; if (!the_win.closed && the_win.location) { //winName.location.href = the_url; } else { if (!isWindowOpen(winName)) { the_win = window_open(the_url, winName, option); try { the_win.resizeTo(the_x, the_y); } catch (err) { } the_win.focus(); } else { eval("window." + winName + ".focus()"); } } } } function window_open(theUrl, winName, options) { return eval(winName.replace('-', 'neg') + " = window.open('" + theUrl + "', '" + winName.replace('-', 'neg') + "','" + options + "')"); } function isWindowOpen(winName) { try { if (eval("window." + winName + ".document")) { return true; } } catch (err) { return false; } } this.open_win_preview = function (page) { Syscom.GM.Script.API.Common.open_win(page, 720, 480, 0, 0, 0, 0, 0, 1, 1, 0, 5, 'gmPreview'); } this.open_item = function (Type, ContentItemType, ParentNodeID, ItemID, WinType, Tab, Token, URLRoot, NodeID, AttributeGroupID) { var item_type; if (!ContentItemType) { item_type = Type * -1 } else { item_type = ContentItemType } var win_name = app_id + '_' + WinType.replace('-', 'neg') + '_' + String(ItemID).replace('-', 'neg'); if (!Type) { Type = ''; } else { Type = '&Type=' + Type; } if (!ContentItemType) { ContentItemType = ''; } else { ContentItemType = '&ContentItemType=' + ContentItemType; } if (!ParentNodeID) { ParentNodeID = ''; } else { ParentNodeID = '&ParentNodeID=' + ParentNodeID; } if (!NodeID) { NodeID = ''; } else { NodeID = '&NodeID=' + NodeID; } if (!ItemID) { ItemID = ''; } else { ItemID = 'ItemID=' + ItemID; } if (!Tab) { Tab = ''; } else { Tab = '&Tab=' + Tab; } if (!Token) { Token = ''; } else { Token = '&Token=' + Token; } if (!AttributeGroupID) { AttributeGroupID = ''; } else { AttributeGroupID = '&AttributeGroupID=' + AttributeGroupID; } if (!URLRoot) { URLRoot = ''; } else { Root = '&Root=' + URLRoot; } var LaunchURL = URLRoot + 'Manage/Default.aspx?' + ItemID + Type + ContentItemType + ParentNodeID + Tab + Token + NodeID + AttributeGroupID Syscom.GM.Script.API.Common.open_win(LaunchURL, 780, 860, 0, 0, 0, 0, 0, 1, 1, 0, 5, win_name); } this.generateGuid = function () { var result, i, j; result = ''; for (j = 0; j < 32; j++) { if (j == 8 || j == 12 || j == 16 || j == 20) result = result + '-'; i = Math.floor(Math.random() * 16).toString(16).toUpperCase(); result = result + i; } return result } //Sample usages //disableSelection(document.body) //Disable text selection on entire body //disableSelection($get("mydiv")) //Disable text selection on element with id="mydiv" this.disableSelection = function (target) { if (typeof target.onselectstart != "undefined") //IE route target.onselectstart = function () { return false } else if (typeof target.style.MozUserSelect != "undefined") //Firefox route target.style.MozUserSelect = "none" else //All other route (ie: Opera) target.onmousedown = function () { return false } target.style.cursor = "default" } } ///// SCRIPT OBJECTS Syscom.GM.Script.API.TemplateStudio = function (templateId) { //PROPERTIES -- Keep these in alpha order by private var. name //appId this.appId = new Syscom.GM.Script.API.Base.Property('SyscomGM_Web_Admin'); //itemId this.itemId = new Syscom.GM.Script.API.Base.Property(0); //itemType this.itemType = new Syscom.GM.Script.API.Base.Property(5); //loginToken this.loginToken = new Syscom.GM.Script.API.Base.Property(''); //urlRoot this.urlRoot = new Syscom.GM.Script.API.Base.Property('../'); //windowHeight this.windowHeight = new Syscom.GM.Script.API.Base.Property(680); //windowPosition this.windowPosition = new Syscom.GM.Script.API.Base.Property(Syscom.GM.Script.API.Enums.WindowPosition.Middle); //windowType this.windowType = new Syscom.GM.Script.API.Base.Property('TemplateStudio'); //windowWidth this.windowWidth = new Syscom.GM.Script.API.Base.Property(1080); //windowName this.windowName = new Syscom.GM.Script.API.Base.Property(''); //navigateUrl this.get_navigateUrl = function () { var itemIdParam = ''; var loginTokenParam = ''; var urlRootParam = ''; if (this.itemId.getValue() != 0) { itemIdParam = 'ItemID=' + this.itemId.getValue() } if (this.loginToken.getValue() != '') { loginTokenParam = '&Token=' + this.loginToken.getValue() } if (this.urlRoot.getValue() != '') { urlRootParam = '&Root=' + this.urlRoot.getValue() } return this.urlRoot.getValue() + 'TemplateStudio/Designer.aspx?' + itemIdParam + loginTokenParam } this.open = function () { var showToolBar = false; var showAddressBar = false; var showDirectories = false; var showStatusBar = false; var showMenuBar = false; var allowScrolling = true; var allowResize = true; var showHistory = false; if (this.windowName.getValue() == '') { var winName = this.appId.getValue() + '_' + this.windowType.getValue() + '_' + this.itemId.getValue(); this.windowName.setValue(winName) } Syscom.GM.Script.API.Common.open_win( this.get_navigateUrl(), this.windowWidth.getValue(), this.windowHeight.getValue(), showToolBar, showAddressBar, showDirectories, showStatusBar, showMenuBar, allowScrolling, allowResize, showHistory, this.windowPosition.getValue(), this.windowName.getValue() ); } if (templateId) { try { this.itemId.setValue(templateId); } catch (err) { } } } ///// Manage Item Window Opener Syscom.GM.Script.API.ManageItemWindow = function (windowProperties) { //PROPERTIES -- Keep these in alpha order by private var. name //appId this.appId = new Syscom.GM.Script.API.Base.Property('SyscomGM_Web_Admin'); //contentItemType this.contentItemType = new Syscom.GM.Script.API.Base.Property(0); //itemId this.itemId = new Syscom.GM.Script.API.Base.Property(0); //itemType this.itemType = new Syscom.GM.Script.API.Base.Property(5); //loginToken this.loginToken = new Syscom.GM.Script.API.Base.Property(''); //nodeId this.nodeId = new Syscom.GM.Script.API.Base.Property(0); //parentNodeId this.parentNodeId = new Syscom.GM.Script.API.Base.Property(0); //attributeGroupId this.attributeGroupId = new Syscom.GM.Script.API.Base.Property(0); //tab this.tab = new Syscom.GM.Script.API.Base.Property(null); //urlRoot this.urlRoot = new Syscom.GM.Script.API.Base.Property('.'); //windowHeight this.windowHeight = new Syscom.GM.Script.API.Base.Property(780); //windowPosition this.windowPosition = new Syscom.GM.Script.API.Base.Property(Syscom.GM.Script.API.Enums.WindowPosition.Middle); //windowType this.windowType = new Syscom.GM.Script.API.Base.Property('ContentItem'); //windowWidth this.windowWidth = new Syscom.GM.Script.API.Base.Property(740); //windowName this.windowName = new Syscom.GM.Script.API.Base.Property(''); //READ ONLY PROPERTIES -- Keep these in alpha order //navigateUrl this.get_navigateUrl = function () { var params = ''; if (this.contentItemType.getValue() != 0) { if (this.itemType.getValue() > 0) { this.itemType.setValue(this.itemType.getValue() * -1) } } else if (this.contentItemType.getValue() != '' && this.contentItemType.getValue() != "''") { this.itemType.setValue(this.contentItemType.getValue()) } if (this.itemType.getValue() != null) { params = params + '&Type=' + this.itemType.getValue() } if (this.contentItemType.getValue() != 0) { params = params + '&ContentItemType=' + this.contentItemType.getValue() } if (this.parentNodeId.getValue() > 0) { params = params + '&ParentNodeID=' + this.parentNodeId.getValue() } if (this.nodeId.getValue() > 0) { params = params + '&NodeID=' + this.nodeId.getValue() } if (this.itemId.getValue() != 0) { params = params + '&ItemID=' + this.itemId.getValue() } if (this.attributeGroupId.getValue() > 0) { params = params + '&AttributeGroupID=' + this.attributeGroupId.getValue() } if (this.tab.getValue() != null) { params = params + '&Tab=' + this.tab.getValue() } if (this.loginToken.getValue() != '') { params = params + '&Token=' + this.loginToken.getValue() } //if (this.urlRoot.getValue() != '') { params = params + '&Root=' + this.urlRoot.getValue() } //if (params.length > 0) { params = params.substring(1, params.length - 1) } return this.urlRoot.getValue() + '/Manage/Default.aspx?' + params } ///// METHODS this.open = function () { var showToolBar = false; var showAddressBar = false; var showDirectories = false; var showStatusBar = false; var showMenuBar = false; var allowScrolling = false; var allowResize = true; var showHistory = false; if (this.windowName.getValue() == '') { var winName = this.appId.getValue() + '_' + this.windowType.getValue() + '_' + this.itemId.getValue(); this.windowName.setValue(winName) } Syscom.GM.Script.API.Common.open_win( this.get_navigateUrl(), this.windowWidth.getValue(), this.windowHeight.getValue(), showToolBar, showAddressBar, showDirectories, showStatusBar, showMenuBar, allowScrolling, allowResize, showHistory, this.windowPosition.getValue(), this.windowName.getValue() ); } if (windowProperties) { try { this.itemId.setValue(windowProperties.ItemId); } catch (err) { } try { this.contentItemType.setValue(windowProperties.ContentItemType); } catch (err) { } try { this.itemType.setValue(windowProperties.ItemType); } catch (err) { } try { this.nodeId.setValue(windowProperties.NodeId); } catch (err) { } try { this.operationType.setValue(windowProperties.OperationType); } catch (err) { } try { this.windowType.setValue(windowProperties.WindowType); } catch (err) { } try { this.attributeGroupId.setValue(windowProperties.AttributeGroupId); } catch (err) { } } } ///// Common ManageItemWindow properties. Syscom.GM.Script.API.ManageItemWindowProperties = function (windowProperties) { var _itemId; var _windowType; var _contentItemType; var _itemType; var _nodeId; var _operationType; var _attributeGroupId var winPropsArray = windowProperties.split("|"); try { _itemId = parseInt(winPropsArray[0]); _windowType = winPropsArray[1]; _contentItemType = parseInt(winPropsArray[2]); _itemType = parseInt(winPropsArray[3]); _nodeId = parseInt(winPropsArray[4]); _operationType = winPropsArray[5]; _attributeGroupId = parseInt(winPropsArray[6]); } catch (err) { } this.ItemId = _itemId; this.WindowType = _windowType; this.ContentItemType = _contentItemType; this.ItemType = _itemType; this.NodeId = _nodeId; this.OperationType = _operationType; this.AttributeGroupId = _attributeGroupId; } Syscom.GM.Script.API.Clipboard = function () { //action this.action = new Syscom.GM.Script.API.Base.Property(null); //items this.contents = new Syscom.GM.Script.API.Base.Property(new Array()); // Clear the items this.clear = function () { this.contents = new Syscom.GM.Script.API.Base.Property(new Array()); this.action = new Syscom.GM.Script.API.Base.Property(null); } this.count = function () { //return } // The contents must be an array of ClipboardItem this.getDelimitedContents = function (delimiter) { var str = ''; if (delimiter == null || delimiter == '') { delimiter = ","; } for (i = 0; i < this.contents.getValue().length; i++) { try { var itm = this.contents.getValue()[i].getDelimitedValues(); if (itm != null) { str += itm + delimiter; } } catch (err) { } } if (str.length > 0) { str = Syscom.GM.Script.API.String.trim(str, delimiter) }; return str; } this.size = function () { var size = 0; for (var i in this.contents) { if (this.contents[i] != null) { size++; } } return size; } }; Syscom.GM.Script.API.ClipboardItem = function() { //id this.id = new Syscom.GM.Script.API.Base.Property(0); //contentItemType - for content items only this.contentItemType = new Syscom.GM.Script.API.Base.Property(5); //nodeId this.nodeId = new Syscom.GM.Script.API.Base.Property(0); //itemType this.itemType = new Syscom.GM.Script.API.Base.Property(0); //source this.source = new Syscom.GM.Script.API.Base.Property(null); this.getDelimitedValues = function (delimiter) { if (this.id != null && this.id > 0) { if (delimiter == null || delimiter == '') { delimiter = ","; } return "{" + this.id + delimiter + this.nodeId + delimiter + this.itemType + delimiter + this.contentItemType + delimiter + this.source + '}'; } else { return null } } }; Syscom.GM.Script.API.AjaxEventArgument = function (eventTarget, event, arguments, argumentsType) { this.eventTarget = new Syscom.GM.Script.API.Base.Property(eventTarget); this.event = new Syscom.GM.Script.API.Base.Property(event); this.arguments = new Syscom.GM.Script.API.Base.Property(arguments); this.argumentsType = new Syscom.GM.Script.API.Base.Property(argumentsType); this.join = function () { var rtn = '[' + this.eventTarget.getValue() + '],[' + this.event.getValue() + '],['; if (this.argumentsType.getValue() != '' && this.argumentsType.getValue() != null && this.argumentsType.getValue() != null) { rtn += this.argumentsType.getValue() + '::'; }; rtn += this.arguments.getValue() + ']'; return rtn; } this.toString = function () { return this.join(); } }; Syscom.GM.Script.API.HashTable = function () { this.items = new Object(); this.putItem = function (key, value) { this.addItem(key, value); } this.addItem = function (key, value) { if (key == null || value == null) { throw "NullPointerException {" + key + "},{" + value + "}"; } else if (!this.containsKey(key)) { this.items[key] = value; } else { throw "KeyExistsException {" + key + "}"; } } this.containsKey = function (key) { return typeof (this.items[key]) != "undefined"; } this.containsValue = function containsValue(value) { for (var item in this.items) { if (this.items[item] == value) return true; } return false; } this.contains = function (keyOrValue) { return this.containsKey(keyOrValue) || this.containsValue(keyOrValue); } this.clear = function () { this.items = new Object(); } this.getItem = function (key) { if (this.containsKey(key)) return this.items[key]; else { return null; } } this.isEmpty = function () { return this.size() == 0; } this.keys = function () { var keys = new Array(); for (var i in this.items) { if (this.items[i] != null) { keys.push(i); } } return keys; } this.remove = function (key) { if (this.containsKey(key)) { delete this.items[key]; } else { alert(key); throw "key '" + key + "' does not exists." } } this.size = function () { var size = 0; for (var i in this.items) { if (this.items[i] != null) { size++; } } return size; } this.toString = function () { var result = ""; for (var i in this.items) { if (this.items[i] != null) { result += "{" + i + "},{" + this.items[i] + "}"; } } return result; } this.values = function () { var values = new Array(); for (var i in this.items) { if (this.items[i] != null) { values.push(this.items[i]); } } return values; } }; ///// Initializer functions Syscom.GM.Script.API.Common.addLoadFunction(Syscom.GM.Script.API.Common.getViewPortDimensions); Syscom.GM.Script.API.Common.addResizeListener(Syscom.GM.Script.API.Common.getViewPortDimensions);