93bc419e0617d189b6d3f17b89bc4e7572deb6ec
[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
13 <div>
14   <h2>Attribute Filter</h2>
15   <select id="attribute-name">
16     <option value="type">type</option>
17     <option value="mimeType">mime</option>
18     <option value="title">title</option>
19     <option value="contentURI">uri</option>
20     <option value="thumbnailURIs">thumbnails</option>
21     <option value="size">size</option>
22     <option value="rating">rating</option>
23     <option value="artists">artist</option>
24     <option value="duration">duration</option>
25     <option value="width">width</option>
26     <option value="height">height</option>
27   </select>
28   <select id="match-flag">
29     <option value="EXACTLY">EXACTLY</option>
30     <option value="FULLSTRING">FULLSTRING</option>
31     <option value="CONTAINS">CONTAINS</option>
32     <option value="STARTSWITH">STARTSWITH</option>
33     <option value="ENDSWITH">ENDSWITH</option>
34     <option value="EXISTS">EXISTS</option>
35   </select>
36   <input id="match-value" type="text">
37
38 </div>
39
40 <pre id="console"></pre>
41 <script src="js/js-test-pre.js"></script>
42 <script>
43
44 function handleCleanConsole()
45 {
46   var el = document.getElementById("console");
47   while (el.firstChild)
48     el.removeChild(el.firstChild);
49 }
50
51 function handleGetDirectories()
52 {
53   try {
54     debug('tizen.content.getDirectories:');
55     tizen.content.getDirectories(function(folders) {
56     for (var i = 0; i < folders.length; i++) {
57         debug(folders[i].title + ', ' + folders[i].directoryURI);
58       }    
59     }, 
60     function(err) {
61       debug(err.name);
62     });
63   }
64   catch (err) {
65     debug(err.name);
66   }
67 }
68 function handleFind()
69 {
70   var filter = null;
71
72   var e = document.getElementById("attribute-name");
73   var attributeName = e.options[e.selectedIndex].value;
74   e = document.getElementById("match-flag");
75   var matchFlag = e.options[e.selectedIndex].value;
76   var matchValue = document.getElementById('match-value').value;
77
78   debug("Filter: " + attributeName + ' ' + matchFlag + ' ' + matchValue);
79   if (matchValue != "" || matchFlag == "EXISTS")
80     filter = new tizen.AttributeFilter(attributeName, matchFlag, matchValue);
81
82   try {
83     debug('tizen.content.find:');
84     tizen.content.find(function(items) {
85       for (var i = 0; i < items.length; i++) {
86         debug(items[i].title + ', ' + items[i].mimeType);
87       }    
88     }, 
89     function(err) {
90       debug('find: error');
91     }, null, filter);
92   }
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   }
109   catch (err) {
110     debug(err.name);
111   }
112 }
113
114 </script>
115 </body>
116 </html>