[jslint] Enable js lint and fix the errors.
[platform/framework/web/tizen-extensions-crosswalk.git] / content / content_api.js
index ed0b323..0491f93 100644 (file)
@@ -7,24 +7,24 @@ var _nextReplyId = 0;
 
 function getNextReplyId() {
   return _nextReplyId++;
-};
+}
 
 function postMessage(msg, callback) {
   var replyId = getNextReplyId();
   _callbacks[replyId] = callback;
   msg.replyId = replyId;
   extension.postMessage(JSON.stringify(msg));
-};
+}
 
 function sendSyncMessage(msg) {
   return extension.internal.sendSyncMessage(JSON.stringify(msg));
-};
+}
 
 extension.setMessageListener(function(msg) {
   var m = JSON.parse(msg);
   var replyId = m.replyId;
   var callback = _callbacks[replyId];
-  
+
   if (typeof(callback) === 'function') {
     callback(m);
     delete m.replyId;
@@ -43,7 +43,8 @@ function Folder(uri, id, type, title) {
   });
 }
 
-function Content(id, name, type, mimeType, title, contentURI, thumnailURIs, releaseDate, modifiedDate, size, description, rating) {
+function Content(id, name, type, mimeType, title, contentURI, thumnailURIs, releaseDate,
+                 modifiedDate, size, description, rating) {
   Object.defineProperties(this, {
     'id': { writable: false, value: id, enumerable: true },
     'name': { writable: false, value: name, enumerable: true },
@@ -56,11 +57,12 @@ function Content(id, name, type, mimeType, title, contentURI, thumnailURIs, rele
     'modifiedDate': { writable: false, value: modifiedDate, enumerable: true },
     'size': { writable: false, value: size, enumerable: true },
     'description': { writable: false, value: description, enumerable: true },
-    'rating': { writable: false, value: rating, enumerable: true },
+    'rating': { writable: false, value: rating, enumerable: true }
   });
 }
 
-function ContentAudio(obj, album, genres, artists, composer, copyright, bitrate, trackNumber, duration) {
+function ContentAudio(obj, album, genres, artists, composer, copyright,
+                      bitrate, trackNumber, duration) {
   Object.defineProperties(obj, {
     'album': { writable: false, value: album, enumerable: true },
     'genres': { writable: false, value: genres, enumerable: true },
@@ -69,7 +71,7 @@ function ContentAudio(obj, album, genres, artists, composer, copyright, bitrate,
     'copyright': { writable: false, value: copyright, enumerable: true },
     'bitrate': { writable: false, value: bitrate, enumerable: true },
     'trackNumber': { writable: false, value: trackNumber, enumerable: true },
-    'duration': { writable: false, value: duration, enumerable: true },
+    'duration': { writable: false, value: duration, enumerable: true }
   });
 }
 
@@ -77,7 +79,7 @@ function ContentImage(obj, width, height, orientation) {
   Object.defineProperties(obj, {
     'width': { writable: false, value: width, enumerable: true },
     'height': { writable: false, value: height, enumerable: true },
-    'orientation': { writable: false, value: orientation, enumerable: true },
+    'orientation': { writable: false, value: orientation, enumerable: true }
   });
 }
 
@@ -87,7 +89,7 @@ function ContentVideo(obj, album, artists, duration, width, height) {
     'artists': { writable: false, value: artists, enumerable: true },
     'duration': { writable: false, value: duration, enumerable: true },
     'width': { writable: false, value: width, enumerable: true },
-    'height': { writable: false, value: height, enumerable: true },
+    'height': { writable: false, value: height, enumerable: true }
   });
 }
 
@@ -98,13 +100,13 @@ ContentManager.prototype.update = function(content) {
   if (!xwalk.utils.validateArguments('o', arguments)) {
     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
   }
-}
+};
 
 ContentManager.prototype.updateBatch = function(content, onsuccess, onerror) {
   if (!xwalk.utils.validateArguments('o?ff', arguments)) {
     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
   }
-}
+};
 
 ContentManager.prototype.getDirectories = function(onsuccess, onerror) {
   if (!xwalk.utils.validateArguments('f?f', arguments)) {
@@ -112,114 +114,115 @@ ContentManager.prototype.getDirectories = function(onsuccess, onerror) {
   }
 
   postMessage({
-      cmd: 'ContentManager.getDirectories',
-    }, function(result) {
-      if (result.isError) {
-        if (onerror)
-          onerror(new tizen.WebAPIError(result.errorCode));
-      } else if (onsuccess) {
-        var folders = [];
-
-        for (var i = 0; i < result.value.length; i++) {
-          var folder = result.value[i];
-          var jsonFolder = new Folder(folder.directoryURI,
-              folder.id,
-              folder.storageType,
-              folder.title);
-          folders.push(jsonFolder)
-        }
-        onsuccess(folders);
+    cmd: 'ContentManager.getDirectories'
+  }, function(result) {
+    if (result.isError) {
+      if (onerror)
+        onerror(new tizen.WebAPIError(result.errorCode));
+    } else if (onsuccess) {
+      var folders = [];
+
+      for (var i = 0; i < result.value.length; i++) {
+        var folder = result.value[i];
+        var jsonFolder = new Folder(folder.directoryURI,
+            folder.id,
+            folder.storageType,
+            folder.title);
+        folders.push(jsonFolder);
       }
+      onsuccess(folders);
+    }
   });
-}
+};
 
-ContentManager.prototype.find = function(onsuccess, onerror, directoryId, filter, sortMode, count, offset) {
+ContentManager.prototype.find = function(onsuccess, onerror, directoryId,
+    filter, sortMode, count, offset) {
   if (!xwalk.utils.validateArguments('f?fsoonn', arguments)) {
     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
   }
 
   postMessage({
-      cmd: 'ContentManager.find',
-      directoryId: directoryId,
-      filter: filter,
-      sortMode: sortMode,
-      count: count,
-      offset: offset,
-    }, function(result) {
-      if (result.isError) {
-        if (onerror)
-          onerror(new tizen.WebAPIError(result.errorCode));
-      } else if (onsuccess) {
-        var contents = [];
-        for (var i = 0; i < result.value.length; i++) {
-          var content = result.value[i];
-          var jsonContent = new Content(content.id, 
-              content.name,
-              content.type,
-              content.mimeType,
-              content.title,
-              content.contentURI,
-              content.thumnailURIs,
-              content.releaseDate,
-              content.modifiedDate,
-              content.size,
-              content.description,
-              content.rating);
-
-          if (content.type == "AUDIO") {
-            ContentAudio(jsonContent,
-                content.album,
-                content.genres,
-                content.artists,
-                content.composer,
-                content.copyright,
-                content.bitrate,
-                content.trackNumber,
-                content.duration);
-          } else if (content.type == "IMAGE") {
-            ContentImage(jsonContent,
-                content.width,
-                content.height,
-                content.orientation);
-          } else if (content.type == "VIDEO") {
-            ContentImage(jsonContent,
-                content.album,
-                content.artists,
-                content.duration,
-                content.width,
-                content.height);
-          }
-          contents.push(jsonContent);
-        }     
-        onsuccess(contents);
+    cmd: 'ContentManager.find',
+    directoryId: directoryId,
+    filter: filter,
+    sortMode: sortMode,
+    count: count,
+    offset: offset
+  }, function(result) {
+    if (result.isError) {
+      if (onerror)
+        onerror(new tizen.WebAPIError(result.errorCode));
+    } else if (onsuccess) {
+      var contents = [];
+      for (var i = 0; i < result.value.length; i++) {
+        var content = result.value[i];
+        var jsonContent = new Content(content.id,
+            content.name,
+            content.type,
+            content.mimeType,
+            content.title,
+            content.contentURI,
+            content.thumnailURIs,
+            content.releaseDate,
+            content.modifiedDate,
+            content.size,
+            content.description,
+            content.rating);
+
+        if (content.type == 'AUDIO') {
+          ContentAudio(jsonContent,
+              content.album,
+              content.genres,
+              content.artists,
+              content.composer,
+              content.copyright,
+              content.bitrate,
+              content.trackNumber,
+              content.duration);
+        } else if (content.type == 'IMAGE') {
+          ContentImage(jsonContent,
+              content.width,
+              content.height,
+              content.orientation);
+        } else if (content.type == 'VIDEO') {
+          ContentImage(jsonContent,
+              content.album,
+              content.artists,
+              content.duration,
+              content.width,
+              content.height);
+        }
+        contents.push(jsonContent);
       }
+      onsuccess(contents);
+    }
   });
-}
+};
 
 ContentManager.prototype.scanFile = function(contentURI, onsuccess, onerror) {
   if (!xwalk.utils.validateArguments('s?ff', arguments)) {
     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
   }
   postMessage({
-      cmd: 'ContentManager.scanFile',
-      contentURI: contentURI
-    }, function(result) {
-      if (result.isError) {
-        if (onerror)
-          onerror(new tizen.WebAPIError(result.errorCode));
-      } else if (onsuccess) {
-        onsuccess(contentURI);
-      }
+    cmd: 'ContentManager.scanFile',
+    contentURI: contentURI
+  }, function(result) {
+    if (result.isError) {
+      if (onerror)
+        onerror(new tizen.WebAPIError(result.errorCode));
+    } else if (onsuccess) {
+      onsuccess(contentURI);
+    }
   });
-}
+};
 
 ContentManager.prototype.setChangeListener = function(onchange) {
   if (!xwalk.utils.validateArguments('f', arguments)) {
     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
   }
-}
+};
 
 ContentManager.prototype.unsetChangeLIstener = function() {
-}
+};
 
 exports = new ContentManager();