Main and secondary gadget code
<?xml version="1.0" encoding="UTF-8" ?> <Module> <ModulePrefs title="עכבר העיר: אירועי היום" title_url="http://www.mouse.co.il/" height="160" author="Gal&Yuval" author_email="galyuval@gmail.com" > <Require feature="dynamic-height" /> </ModulePrefs> <UserPref name="test000" display_name="בחר אזור" default_value="תל אביב" datatype="enum" publish="true" > <EnumValue value="1" display_value="תל אביב" /> <EnumValue value="2" display_value="אזור המרכז" /> <EnumValue value="3" display_value="חיפה והצפון" /> <EnumValue value="4" display_value="אזור הדרום" /> <EnumValue value="5" display_value="ירושלים והסביבה" /> </UserPref> <UserPref name="selectedTab" datatype="hidden"/> <Content type="html"> <![CDATA[ <div id="main_tab"> <div id="content_div1" style="font-size:10pt; padding:5px; direction:rtl; background-color: #FFFFBF" > <b>בחר אזור:</b> <table> <tr> <td> <select id="area" name="area" > <option value ="1">תל אביב</option> <option value ="2">אזור המרכז</option> <option value ="3">חיפה והצפון</option> <option value ="4">אזור הדרום</option> <option value ="5">ירושלים והסביבה</option> </select> </td> <td> <input type="button" name="butUpdate" name="butUpdate" value="עדכן" onclick="updateValue()"> </td> </tr> </table> <table> <tr> <td style="font-size:10pt; direction: rtl; width: 90px"> אירועים מיוחדים </td> <td> <div id="eventCount1" style="font-size:10pt; direction:rtl">0</div> </td> <td style="width: 40px"/> <td style="font-size:10pt; direction: rtl; width: 85px"> הצגות תיאטרון </td> <td> <div id="eventCount2" style="font-size:10pt; direction:rtl">0</div> </td> </tr> <tr> <td style="font-size:10pt; direction: rtl; width: 90px"> מופעי ילדים </td> <td> <div id="eventCount3" style="font-size:10pt; direction:rtl">0</div> </td> <td style="width: 40px"/> <td style="font-size:10pt; direction: rtl; width: 85px"> תערוכות </td> <td> <div id="eventCount4" style="font-size:10pt; direction:rtl">0</div> </td> </tr> <tr> <td style="font-size:10pt; direction: rtl; width: 90px"> מסיבות </td> <td> <div id="eventCount5" style="font-size:10pt; direction:rtl">0</div> </td> <td style="width: 40px"/> <td style="font-size:10pt; direction: rtl; width: 85px"> סרטים </td> <td> <div id="eventCount6" style="font-size:10pt; direction:rtl">0</div> </td> </tr> <tr> <td style="font-size:10pt; direction: rtl; width: 85px"> מופעי מוזיקה </td> <td> <div id="eventCount7" style="font-size:10pt; direction:rtl">0</div> </td> </tr> </table> </div> </div> <div id="search_tab" style="display: none"> <div id="content_div3" style="font-size:10pt; padding:5px; direction:rtl; background-color: #FFFFBF" > <b>לביצוע החיפוש בחר אזור, תחום אירוע וטווח שעות מבוקש:</b> <table> <tr> <td> <select id="area1" name="area1" > <option value ="0">בחר אזור</option> <option value ="1">תל אביב</option> <option value ="2">אזור המרכז</option> <option value ="3">חיפה והצפון</option> <option value ="4">אזור הדרום</option> <option value ="5">ירושלים והסביבה</option> </select> </td> <td> <select id="field" name="field" > <option value ="0">בחר תחום</option> <option value ="1">אירועים מיוחדים</option> <option value ="2">הצגות תיאטרון</option> <option value ="3">מופעי ילדים</option> <option value ="4">תערוכות</option> <option value ="5">מסיבות</option> <option value ="6">סרטים</option> </select> </td> <td> <select id="hour" name="hour" > <option value ="1">כל היום</option> <option value ="2">בוקר</option> <option value ="3">צהריים</option> <option value ="4">אחה"צ</option> <option value ="5">ערב</option> <option value ="6">לילה</option> </select> </td> <td> <input type="button" name="butSearch" name="butSearch" value="חיפוש" onclick="updateSearch()"> </td> </tr> </table> </div> <div id="content_div4" style="color: blue; font-size:11pt; padding:5px; direction:rtl" > </div> </div> <script type="text/javascript"> var tabs = new _IG_Tabs(__MODULE_ID__, "ראשי"); tabs.alignTabs("right", 10); var prefs = new _IG_Prefs(__MODULE_ID__); var myareaPref = prefs.getString("test000"); var areaEnName = ""; var searchEnArea; var searchEnField; var searchEnHour1; var searchEnHour2; var searchEnHour3; var searchEnHour4; var searchEnHour5; updateName(); // Gets and displays the publisher gadget's local test000 userpref. New userpref value is not published // unless user invokes updateMsg() by clicking button. var str = prefs.getString("test000"); _gel("area").value = str; _IG_RegisterOnloadHandler(init); //updates the name of the area chosen in english function updateName(){ if (myareaPref == "1") { areaEnName = "telAviv"; } else if (myareaPref == "2") { areaEnName = "merkaz"; } else if (myareaPref == "3") { areaEnName = "haifaNorth"; } else if (myareaPref == "4") { areaEnName = "south"; } else if (myareaPref == "5") { areaEnName = "jerusalem"; } } //fetches the number of events at the chosen field where area is the one chosen from the combobox function fetchData(field, id){ var dbName = "http://www.cs.tau.ac.il/~yuvalda/" + areaEnName + field + "Count.txt"; _IG_FetchContent(dbName, function (responseText) { if (responseText.length < 200) { _gel(id).innerHTML = responseText.substr(0,3); } else { _gel(id).innerHTML = "0"; } }); } //clears the data that was displayed on search tab function resetData() { _gel('content_div4').innerHTML = ""; _IG_AdjustIFrameHeight(160); } //a callback function for the search tab - adjust the height on initial selection of this tab function updateHeight() { _IG_AdjustIFrameHeight(160); } // This publisher gadget updates the value for the test000 // userpref when users click the "Update Message" button. function updateValue() { var newMsg = _gel("area").value; prefs.set("test000", newMsg); myareaPref = prefs.getString("test000"); updateName(); fetchData("SpecialEvents", "eventCount1"); fetchData("Stage", "eventCount2"); fetchData("Children", "eventCount3"); fetchData("Exhibition", "eventCount4"); fetchData("Parties", "eventCount5"); fetchData("Movies", "eventCount6"); fetchData("Music", "eventCount7"); _IG_AdjustIFrameHeight(); } //the initialization function called first when gadget uploads function init() { tabs.addTab("חיפוש", "search_tab", updateHeight); tabs.addTab("ראשי", "main_tab", updateValue); tabs.setSelectedTab(1); } //the search tab search function function searchData(){ if (searchEnArea == null | searchEnField == null) // if one of the comboboxes isn't chosen - reset the data shown { resetData(); } else { var dbName = "http://www.cs.tau.ac.il/~yuvalda/"+searchEnArea+searchEnField+"Table.txt"; if (searchEnField == "Movies") { _IG_FetchContent(dbName, function (responseText) { // Set CSS for div. var html = "<div style='padding: 5px; text-align:right;font-size:80%'>"; html += "<table><tr>"; html += "<td style='text-align:right; font-size:10pt; font-weight:bold; text-decoration: underline; width: 180px'>שם הסרט</td>"; html += "</tr><tr>"; var html2 = ""; // Use the split function to extract substrings separated by comma // delimiters. var contacts = responseText.split("$^$"); if (contacts[0].length > 200) { html2 += "<tr><td style='text-align:right; font-size:10pt; color: red; font-weight:bold; width: 180px'>אין סרטים</td ></tr>"; } else { // Process array of extracted substrings. for (var i = 0; i < contacts.length ; i++) { // Append substrings to html. if ((i%2) == 0) { html2 += "<td style='text-align:right; font-size:10pt; width: 180px'><a href=" + contacts[i+1] + " target='_blank' style='text-decoration: none;'>" + contacts[i]+"</a>"; html2 += "</td></tr><tr>"; } } } // Output html in div. if (html2 == "") { html2 = "ìà ðîöàå ñøèéí"; } html += html2; _gel('content_div4').innerHTML = html; _IG_AdjustIFrameHeight(); }); } else { _IG_FetchContent(dbName, function (responseText) { // Set CSS for div. var html = "<div style='padding: 5px; text-align:right;font-size:80%'>"; html += "<table><tr>"; html += "<td style='text-align:right; font-size:10pt; font-weight:bold; text-decoration: underline; width: 50px'>שעה</td>"; html += "<td style='text-align:right; font-size:10pt; font-weight:bold; text-decoration: underline; width: 180px'>שם המופע</td>"; html += "<td style='text-align:right; font-size:10pt; font-weight:bold; text-decoration: underline; width: 180px'>מקום המופע</td ></tr><tr>"; var html2 = ""; // Use the split function to extract substrings separated by comma // delimiters. var contacts = responseText.split("$^$"); if (contacts[0].length > 200) { html2 += "</table></div><div><table><tr><td style='text-align:right; font-size:10pt; color: red; font-weight:bold'>ìà ðîöàå àéøåòéí áúçåí åáàæåø äîáå÷ùéí</td></tr>"; } else if (searchEnHour1 != "all") { // Process array of extracted substrings. for (var i = 0; i < contacts.length ; i++) { // Append substrings to html. if ((i%6) == 0 & contacts[i].substr(0,2) != searchEnHour1 & contacts[i].substr(0,2) != searchEnHour2 & contacts[i].substr(0,2) != searchEnHour3 & contacts[i].substr(0,2) != searchEnHour4 & contacts[i].substr(0,2) != searchEnHour5) { i +=5; continue; } else if ((i%6) == 0) { html2 += "<td style='text-align:right; font-size:10pt; width: 50px'>" + contacts[i] + "</td>"; } else if ((i%2) == 0) { html2 += "<td style='text-align:right; font-size:10pt; width: 180px'><a href=" + contacts[i+1] + " target='_blank' style='text-decoration: none;'>" + contacts[i]+"</a>"; html2 += "</td>"; } else if((i+1)%6 ==0) { html2 += "</tr><tr>"; } } html2 += "</table></div>"; } else { // Process array of extracted substrings. for (var i = 0; i < contacts.length ; i++) { // Append substrings to html. if ((i%6) == 0) { html2 += "<td style='text-align:right; font-size:10pt; width: 50px'>" + contacts[i] + "</td>"; } else if ((i%2) == 0){ html2 += "<td style='text-align:right; font-size:10pt; width: 180px'><a href=" + contacts[i+1] + " target='_blank' style='text-decoration: none;'>" + contacts[i]+"</a>"; html2 += "</td>"; } else if((i+1)%6 ==0) { html2 += "</tr><tr>"; } } html2 += "</table></div>"; } if (html2 == "</table></div>") { html2 += "</table></div><table><tr><td style='text-align:right; font-size:10pt; color: red; font-weight:bold'>ìà ðîöàå àéøåòéí áùòåú äîáå÷ùåú</td></tr></table>" } html += html2; // Output html in div. _gel('content_div4').innerHTML = html; _IG_AdjustIFrameHeight(); }); } } } //sets the parameters for the search function updateSearch(){ var searchArea = document.getElementById('area1').value; var searchField = document.getElementById('field').value; var searchHour = document.getElementById('hour').value; if (searchArea == "0") { searchEnArea = null; } else if (searchArea == "1") { searchEnArea = "telAviv"; } else if (searchArea == "2") { searchEnArea = "merkaz"; } else if (searchArea == "3") { searchEnArea = "haifaNorth"; } else if (searchArea == "4") { searchEnArea = "south"; } else if (searchArea == "5") { searchEnArea = "jerusalem"; } if (searchField == "0") { searchEnField = null; } else if (searchField== "1") { searchEnField = "SpecialEvents"; } else if (searchField== "2") { searchEnField = "Stage"; } else if (searchField== "3") { searchEnField = "Children"; } else if (searchField== "4") { searchEnField = "Exhibition"; } else if (searchField== "5") { searchEnField = "Parties"; } else if (searchField== "6") { searchEnField = "Movies"; } if (searchHour== "1") { searchEnHour1 = "all"; searchEnHour2 = "all"; searchEnHour3 = "all"; searchEnHour4 = "all"; searchEnHour5 = "all"; } if (searchHour== "2") { searchEnHour1 = "07"; searchEnHour2 = "08"; searchEnHour3 = "09"; searchEnHour4 = "10"; searchEnHour5 = "11"; } else if (searchHour== "3") { searchEnHour1 = "11"; searchEnHour2 = "12"; searchEnHour3 = "13"; searchEnHour4 = "14"; searchEnHour5 = "15"; } else if (searchHour== "4") { searchEnHour1 = "15"; searchEnHour2 = "16"; searchEnHour3 = "17"; searchEnHour4 = "18"; searchEnHour5 = "19"; } else if (searchHour== "5") { searchEnHour1 = "19"; searchEnHour2 = "20"; searchEnHour3 = "21"; searchEnHour4 = "22"; searchEnHour5 = "23"; } else if (searchHour== "6") { searchEnHour1 = "22"; searchEnHour2 = "23"; searchEnHour3 = "00"; searchEnHour4 = "01"; searchEnHour5 = "02"; } searchData(); } </script> </div> ]]> </Content> </Module>