debug("----- Initializing the data store -----");
/* Set the channel's minimum size */
DataStore.Set("Internet.minViewSize", "{width=310; height=260}");
/* Update the data store representation of the search field as the
user types into it. This way, if they click the search button
before hitting return, the data store will reflect the latest
changes made by the user.
*/
DataStore.Set("Internet.MainQueryField.updateValueOnTextChanged", true);
/* Customize the NSTableView a bit */
DataStore.Set("Internet.SearchResultsTable.pasteboardTypes.NSStringPboardType", "description.URL.objectValue");
DataStore.Set("Internet.SearchResultsTable.pasteboardTypes.NSURLPboardType", "doubleClickURL");
DataStore.Set("Internet.SearchResultsTable.visibleDragColumns", "description");
DataStore.Set("Internet.NoItemsFound.objectValue", "");
/* Initialize this with an empty document, so it fills in with white */
DataStore.Set("Internet.DetailHTMLView.htmlData", "");
debug("----- Channel did install -----");
/* Set a default value in the search field */
// DataStore.Set("Internet.MainQueryField.objectValue", "");
debug("----- User clicked the search button -----");
/* Clear out the previous results */
DataStore.Set("Internet.SearchResultsTable.dataValue", null);
/* Indicate that a search is about to take place */
DataStore.Set("Internet.NetworkArrows.animating", true);
/* Kick off the search. Searches are usually done in XQuery, since
it has better data parsing/manipulating characteristics than
JavaScript.
*/
DataStore.Notify("DATA.action.performSearch");
let $log := msg("----- Performing the search -----")
let $log := msg("----- Query: ", $query)
let $httpRequest := http-request($query)
let $rss:= http-request-value($httpRequest, "DATA")
let $results := for $item in $rss/rss/channel/item
return dictionary(
("description", $item/title/text()/convert-html(.)),
("doubleClickURL", $item/link/text()/convert-html(.))
)
{-- From the trigger, return a dictionary with key/value pairs representing
data store locations and their values.
--}
return dictionary(
("Internet.SearchResultsTable.dataValue", $results),
("Internet.SearchResultsTable.selectedRows", null()),
("Internet.NetworkArrows.animating", false()),
("Internet.NoItemsFound.objectValue", if ($results) then "" else "No items found.")
)
query = DataStore.Get("URL.query");
if (query)
{
DataStore.Set("Internet.MainQueryField.objectValue", query);
DataStore.Set("Internet.NetworkArrows.animating", true);
DataStore.Notify("DATA.action.performSearch");
}
{-- If any aspect of the results table changes (.dataValue, or .selectedRows) --}
{-- we want to trigger an update of the detail view. --}
let $selectedItem := if (exists($selectedRows)) then
$tableRows[1+$selectedRows]
else
null()
return $selectedItem/doubleClickURL