home *** CD-ROM | disk | FTP | other *** search
Wrap
// Get Surveys-Button could have a popup saying "get surveys for user-key xx" which also would have to be updated each time the api changes - not implemented upto now... // ***************** // Config Settings // ***************** var POSTURL = "https://api.surveygizmo.com/plugin.php?"; var devKey = "hy6ba0hw52b8kdb18gl4ggs8"; var myUserKey = "Please enter User-key"; var GETURL = "https://www.surveygizmo.com/http_api/plugin.php?"; var XMLCMD = "GETSURVEYLIST"; var ERR_ARR = new Array(); // First 4 errorstrings are the strings returned by the surveygizmo-server so they should not be changed!!! ERR_ARR[0] = new Object(); ERR_ARR[0]["ErrString"] = "Invalid user ident".toUpperCase(); ERR_ARR[0]["ErrMsg"] = "Please check or add your User API Key"; ERR_ARR[0]["Spin"] = ""; ERR_ARR[1] = new Object(); ERR_ARR[1]["ErrString"] = "Invalid developer key".toUpperCase(); ERR_ARR[1]["ErrMsg"] = "An invalid developer key was given"; ERR_ARR[1]["Spin"] = ""; ERR_ARR[2] = new Object(); ERR_ARR[2]["ErrString"] = "Unrecognized Command".toUpperCase(); ERR_ARR[2]["ErrMsg"] = "An invalid command was given"; ERR_ARR[2]["Spin"] = ""; ERR_ARR[3] = new Object(); ERR_ARR[3]["ErrString"] = "A command is required".toUpperCase(); ERR_ARR[3]["ErrMsg"] = "A command is required"; ERR_ARR[3]["Spin"] = ""; ERR_ARR[4] = new Object(); ERR_ARR[4]["ErrString"] = "Updating".toUpperCase(); ERR_ARR[4]["ErrMsg"] = "Updating Survey List..."; ERR_ARR[4]["Spin"] = '<img src="gfx/spinner.gif"/>'; ERR_ARR[5] = new Object(); ERR_ARR[5]["ErrString"] = "InProgress".toUpperCase(); ERR_ARR[5]["ErrMsg"] = "Another request is in progress"; ERR_ARR[5]["Spin"] = ""; ERR_ARR[6] = new Object(); ERR_ARR[6]["ErrString"] = "NoResponse".toUpperCase(); ERR_ARR[6]["ErrMsg"] = "No server response - contact SurveyGizmo"; ERR_ARR[6]["Spin"] = ""; ERR_ARR[7] = new Object(); ERR_ARR[7]["ErrString"] = "WrongResponse".toUpperCase(); ERR_ARR[7]["ErrMsg"] = "Wrong server response"; ERR_ARR[7]["Spin"] = ""; ERR_ARR[8] = new Object(); ERR_ARR[8]["ErrString"] = "ok".toUpperCase(); ERR_ARR[8]["ErrMsg"] = ""; ERR_ARR[8]["Spin"] = ""; var BASE_URL = "http://www.surveygizmo.com/"; var AP_URL = "?ap=wdgty"; var ROOT_URL = BASE_URL + AP_URL; var NEWSURVEY_URL = BASE_URL + "surveybuilder/create/" + AP_URL; var GETACCOUNT_URL = BASE_URL + "widget-new-account/" + AP_URL; var FINDKEY_URL = BASE_URL + "surveybuilder/account/#api"; var UPDATE_URL = BASE_URL + "add-ons/survey-widget/"+ AP_URL; var myVersion var WIDGETVERSION = "1.0"; // initial value only, will be read from the file above... var VERSIONFILE = "Info.plist"; // The file from which version will be extracted var VERSIONKEY = "CFBundleVersion"; // xml-key to look for var MAXREQUESTTIME = 20; // No. of seconds to wait until the request is aborted var MYSTRINGLENGTH = 40; // length of string to be shown in the popup-menu var btEditSurvey; var btReporting; var btPreview; var btDone; var btInfo; var btGetSurveys; var myTagValues = new Array(); var requestOk = false; var conn = 0; var mySurveyNameBackup = ""; function readVersion(){ var myXmlDoc = new XMLHttpRequest(); var myInfoPList = ""; myXmlDoc.open("GET", VERSIONFILE, false); myXmlDoc.send(null); if (myXmlDoc.readyState == 4) { var myInfoPList = myXmlDoc.responseText; var myCFBundleVersionPos = myInfoPList.indexOf("CFBundleVersion"); var myVersionStart = myInfoPList.indexOf("</",myCFBundleVersionPos); myVersionStart = myInfoPList.indexOf(">", myVersionStart); myVersionStart++; myVersionStart = myInfoPList.indexOf(">", myVersionStart); myVersionStart++; myVersionEnd = myInfoPList.indexOf("<", myVersionStart); WIDGETVERSION = myInfoPList.substring(myVersionStart,myVersionEnd); } } function setup() { setupButtons(); setPopups(); readPrefs(); readVersion(); document.getElementById("divWidgetVersion").innerText = WIDGETVERSION; // Entry to "Create a new survey to get you started" -> shouldn't that be an entry to "create an account"? document.getElementById("popupMenu").options[0] = new Option("Please select survey...",-2) //document.getElementById("popupMenu").options[1] = new Option("Create a new survey",-1) if (window.widget) { widget.onshow = onshow; //widget.onhide = onhide; } } function onshow(){ importxml(); } // function onhide(){ widget.onshow = ""; } function setPopups(){ setPopupText(document.getElementById("btGetSurveys") , new Array("Get Your Surveys")); setPopupText(document.getElementById("btEditSurvey") , new Array("Edit survey")); setPopupText(document.getElementById("btReporting") , new Array("Reporting")); setPopupText(document.getElementById("btPreview") , new Array("Preview surveys")); setJSLink(document.getElementById("blank"), ROOT_URL); setPopupText(document.getElementById("blank") , new Array("Visit the SurveyGizmo website")); setJSLink(document.getElementById("lnkBtSurveyGizmoOnFront"), ROOT_URL); setPopupText(document.getElementById("lnkBtSurveyGizmoOnFront") , new Array("Visit the SurveyGizmo website")); setJSLink(document.getElementById("lnkBtUpdateWidget"), UPDATE_URL); setPopupText(document.getElementById("lnkBtUpdateWidget") , new Array("A new widget version is available at:" , UPDATE_URL)); setJSLink(document.getElementById("lnkBtNewSurvey"), NEWSURVEY_URL); setPopupText(document.getElementById("lnkBtNewSurvey") , new Array("Create a new survey to get started")); setJSLink(document.getElementById("lnkFindYourKey"), FINDKEY_URL); setPopupText(document.getElementById("lnkFindYourKey") , new Array("Click to get your specific API key")); setJSLink(document.getElementById("lnkGetAccount"), GETACCOUNT_URL); setPopupText(document.getElementById("lnkGetAccount") , new Array("Get your own SurveyGizmo account")); setJSLink(document.getElementById("lnkWdgty"), "http://www.wdgty.com/"); setPopupText(document.getElementById("lnkWdgty") , new Array("Visit the wdgty website")); setJSLink(document.getElementById("lnkSurveyGizmoOnBack"), ROOT_URL); setPopupText(document.getElementById("lnkSurveyGizmoOnBack") , new Array("Visit the SurveyGizmo website")); } function setJSLink(myObject, myLink){ myObject.href = "javascript:openURL('" + myLink + "');"; } function openURL(url) { (window.widget) ? widget.openURL(url) : window.location.href = url; } /****************************** * React on popup-menu changes * ******************************/ function popupMenuChanged(elem) { var chosenOption = elem.selectedIndex; var myOption = elem.options[chosenOption].text; var myValue = elem.options[chosenOption].value; if (myValue > -1){ mySurveyNameBackup = document.getElementById("popupMenuText").innerText = myOption; // change text of popupmenu (technically, the text that lies above the invisible popup-menu) and save Name document.getElementById("outCompleted").innerText = myTagValues[myValue]["ctComplete"]; document.getElementById("outAbandoned").innerText = myTagValues[myValue]["ctAbandoned"]; document.getElementById("outInProgress").innerText = myTagValues[myValue]["ctInProgress"]; document.getElementById("outPartial").innerText = myTagValues[myValue]["ctPartial"]; setJSLink(document.getElementById("lnkBtEditSurvey"), myTagValues[myValue]["link_edit"]); setJSLink(document.getElementById("lnkBtReporting"), myTagValues[myValue]["link_reporting"]); setJSLink(document.getElementById("lnkBtPreview"), myTagValues[myValue]["link_preview"]); document.getElementById("dvResults").style.display = "block"; } else if (myValue == -1){ document.getElementById("popupMenuText").innerText = myOption; } } function setPopupText(myObject, myLines){ myObject.title = ""; for (var i=0 ; i<myLines.length ; i++){ myObject.title = myObject.title + myLines[i] + "\n"; } myObject.title = myObject.title.substring(0,myObject.title.length-1); } function readPrefs(){ if (window.widget) { var uKey = widget.preferenceForKey("userKey"); if (uKey != undefined){ // maybe we should test on length too? document.getElementById("inpUserKey").value = myUserKey = uKey; } } } function undoPrefs(){ document.getElementById("inpUserKey").value = myUserKey; hidePrefs(); } function setPrefs(){ if (window.widget){ if (myUserKey != document.getElementById("inpUserKey").value){ alert("saved changed userkey"); myUserKey = document.getElementById("inpUserKey").value; widget.setPreferenceForKey(myUserKey,"userKey"); } hidePrefs(); importxml(); } } // This function isn't needed as this is handled by hyperlinks function doNothing(){ } function setupButtons(){ var myBtArray = new Object(); myBtArray["editsurvey"] = new Array("btEditSurvey","EDIT SURVEY"); myBtArray["reporting"] = new Array("btReporting","REPORTING"); myBtArray["preview"] = new Array("btPreview","PREVIEW"); myBtArray["done"] = new Array("btDone","Done"); myBtArray["cancel"] = new Array("btCancel","Cancel"); myBtArray["getsurveys"] = new Array("btGetSurveys","GET SURVEYS"); btDone = new AppleButton( document.getElementById(myBtArray["done"][0]), myBtArray["done"][1], 23, "buttongfx/buttonLeft.png", "buttongfx/buttonleftclicked.png", 10, "buttongfx/buttonMiddle.png", "buttongfx/buttonmiddleclicked.png", "buttongfx/buttonRight.png", "buttongfx/buttonrightclicked.png", 10, setPrefs); btCancel = new AppleButton( document.getElementById(myBtArray["cancel"][0]), myBtArray["cancel"][1], 23, "buttongfx/buttonLeft.png", "buttongfx/buttonleftclicked.png", 10, "buttongfx/buttonMiddle.png", "buttongfx/buttonmiddleclicked.png", "buttongfx/buttonRight.png", "buttongfx/buttonrightclicked.png", 10, undoPrefs); btInfo = new AppleInfoButton(document.getElementById("btInfo"), document.getElementById("front"), "white", "white", showPrefs); }