[Content] Add listeners and events support
[platform/framework/web/tizen-extensions-crosswalk.git] / examples / content.html
1 <html>
2 <head>
3   <meta name="viewport" content="width=device-width">
4 </head>
5
6 <h1>Tizen Content API</h1>
7 <body>
8 <button onClick="handleCleanConsole()">Clean</button>
9 <button onClick="handleGetDirectories()">Get Directories</button>
10 <button onClick="handleFind()">Find</button>
11 <button onClick="handleScanFile()">Scan File</button>
12 <button onClick="enableEvents()">Listener (ON)</button>
13 <button onClick="disableEvents()">Listener (OFF)</button>
14
15 <div>
16   <h2>Attribute Filter</h2>
17   <select id="attribute-name">
18     <option value="type">type</option>
19     <option value="mimeType">mime</option>
20     <option value="title">title</option>
21     <option value="contentURI">uri</option>
22     <option value="thumbnailURIs">thumbnails</option>
23     <option value="size">size</option>
24     <option value="rating">rating</option>
25     <option value="artists">artist</option>
26     <option value="duration">duration</option>
27     <option value="width">width</option>
28     <option value="height">height</option>
29   </select>
30   <select id="match-flag">
31     <option value="EXACTLY">EXACTLY</option>
32     <option value="FULLSTRING">FULLSTRING</option>
33     <option value="CONTAINS">CONTAINS</option>
34     <option value="STARTSWITH">STARTSWITH</option>
35     <option value="ENDSWITH">ENDSWITH</option>
36     <option value="EXISTS">EXISTS</option>
37   </select>
38   <input id="match-value" type="text">
39
40 </div>
41
42 <pre id="console"></pre>
43 <script src="js/js-test-pre.js"></script>
44 <script>
45
46 function handleCleanConsole()
47 {
48   var el = document.getElementById("console");
49   while (el.firstChild)
50     el.removeChild(el.firstChild);
51 }
52
53 function handleGetDirectories()
54 {
55   try {
56     debug('tizen.content.getDirectories:');
57     tizen.content.getDirectories(function(folders) {
58     for (var i = 0; i < folders.length; i++) {
59         debug(folders[i].title + ', ' + folders[i].directoryURI);
60       }    
61     }, 
62     function(err) {
63       debug(err.name);
64     });
65   } catch (err) {
66     debug(err.name);
67   }
68 }
69 function handleFind()
70 {
71   var filter = null;
72
73   var e = document.getElementById("attribute-name");
74   var attributeName = e.options[e.selectedIndex].value;
75   e = document.getElementById("match-flag");
76   var matchFlag = e.options[e.selectedIndex].value;
77   var matchValue = document.getElementById('match-value').value;
78
79   debug("Filter: " + attributeName + ' ' + matchFlag + ' ' + matchValue);
80   if (matchValue != "" || matchFlag == "EXISTS")
81     filter = new tizen.AttributeFilter(attributeName, matchFlag, matchValue);
82
83   try {
84     debug('tizen.content.find:');
85     tizen.content.find(function(items) {
86       for (var i = 0; i < items.length; i++) {
87         debug(items[i].title + ', ' + items[i].mimeType);
88       }    
89     }, 
90     function(err) {
91       debug('find: error');
92     }, null, filter);
93   } catch (err) {
94     debug(err.name);
95   }
96 }
97 function handleScanFile()
98 {
99   try {
100     debug('tizen.content.scanFile:');
101     tizen.content.scanFile("file:///opt/usr/media/Images/Default.jpg",
102       function(uri) {
103         debug("scan OK: " + uri);
104       },
105       function(err) {
106         debug("scan ERR: ")
107       });
108   } catch (err) {
109     debug(err.name);
110   }
111 }
112 var listener = {
113     oncontentadded: function(content) {
114       debug("Event ADD: " + content.contentURI);
115     },
116     oncontentupdated: function(content) {
117       debug("Event UPDATE: " + content.contentURI);
118     },
119     oncontentremoved: function(id) {
120       debug("Event REMOVE: " + id);
121     }
122  };
123
124 function enableEvents() {
125   try {
126     debug('tizen.content.setChangeListener:');
127     tizen.content.setChangeListener(listener);
128   } catch (err) {
129     debug(err.name);
130   }
131 }
132
133 function disableEvents() {
134   try {
135     debug('tizen.content.unsetChangeListener:');
136     tizen.content.unsetChangeListener();
137   } catch (err) {
138     debug(err.name);
139   }
140 }
141
142 </script>
143 </body>
144 </html>