Debian Codegraph @

dojox/mobile/tests/imageControlsApp/app/assistants/flickr-search-group-assistant.js

raw symbols SCIP
1 dojo.require("dojox.mobile.app.SceneAssistant");
2
3 dojo.declare("FlickrSearchGroupAssistant", dojox.mobile.app.SceneAssistant, {
4
5 setup: function(){
6
7 // Instantiate widgets in the template HTML.
8 this.controller.parse();
9
10 // This api key should not be reused. You should get your own
11 // free api key from Flickr.
12 this.apiKey = "8c6803164dbc395fb7131c9d54843627";
13
14 this.listWidget = dijit.byId("searchList");
15 this.textWidget = dijit.byId("searchTextInput");
16
17 this.listWidget.set("items", []);
18
19 var _this = this;
20
21 this.search = dojo.hitch(this, this.search);
22 this.handleGroupResults = dojo.hitch(this, this.handleGroupResults);
23
24 // Listen for changes to the text widget.
25 // To ensure that onChange is called on every letter change,
26 // intermediateChanges is set to true on the widget
27 this.connect(this.textWidget, "onChange", function(value){
28 // console.log("search value = ", value);
29
30 if(!value || value.length == 0){
31 _this.listWidget.set("items", []);
32 return;
33 }
34
35 if(!_this.timer){
36 _this.timer = setTimeout(_this.search, 300);
37 }
38 });
39
40 this.connect(this.listWidget, "onSelect", function(item, index, node){
41 console.log("select", arguments);
42
43 _this.controller.stageController.pushScene("flickr-image-view",
44 dojo.mixin({type: "group"}, item));
45 });
46 },
47
48 activate: function(searchType){
49
50 this.searchType = searchType;
51
52 // Set the title of the screen based on the type of the search
53 if(searchType){
54 var sceneHeader = dijit.byId("searchHeader");
55 switch(searchType){
56 case "group":
57 sceneHeader.setLabel("Search Flickr Groups");
58 break;
59 case "user":
60 sceneHeader.setLabel("Search Flickr People");
61 break;
62 case "tag":
63 sceneHeader.setLabel("Search Flickr Tags");
64 break;
65 }
66 }
67 // Focus in the search text input
68 this.textWidget.focus();
69
70 if(this.textWidget.set("value")){
71 this.search();
72 }
73 },
74
75 search: function(){
76 // summary:
77 // Perform a search. Switch between group, user and tag search
78
79 if(this.timer){
80 clearTimeout(this.timer);
81 this.timer = null;
82 }
83
84 var searchText = this.textWidget.set("value");
85
86 if(!searchText || dojo.trim(searchText).length < 1){
87 this.listWidget.set("items", []);
88
89 console.log("NOT SEARCHING");
90 return;
91 }
92
93 var url = "http://api.flickr.com/services/rest/?method=flickr.groups.search";
94
95 var deferred = dojo.io.script.get({
96 url: url,
97 content: {
98 api_key: this.apiKey,
99 format: "json",
100 text: searchText,
101 perPage: 10
102 },
103 jsonp: "jsoncallback"
104 });
105 deferred.addBoth(this.handleGroupResults);
106 },
107
108 handleGroupResults: function(res){
109 var groups;
110 if(res && res.groups && res.groups.group){
111 groups = res.groups.group;
112
113 for(var i = 0; i < groups.length; i++){
114 groups[i].label = groups[i].name;
115 }
116 }else{
117 groups = [];
118 }
119 this.listWidget.set("items", groups);
120 }
121
122 });