chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1309292 [8/8] - in /chemistry/playground/chemistry-opencmis-javascript-relax: ./ src/ src/main/ src/main/webapp/ src/main/webapp/WEB-INF/ src/main/webapp/css/ src/main/webapp/css/eggplant/ src/main/webapp/css/eggplant/images/ src/main/weba...
Date Wed, 04 Apr 2012 08:55:13 GMT
Added: chemistry/playground/chemistry-opencmis-javascript-relax/src/main/webapp/playerpage.js
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-javascript-relax/src/main/webapp/playerpage.js?rev=1309292&view=auto
==============================================================================
--- chemistry/playground/chemistry-opencmis-javascript-relax/src/main/webapp/playerpage.js
(added)
+++ chemistry/playground/chemistry-opencmis-javascript-relax/src/main/webapp/playerpage.js
Wed Apr  4 08:55:11 2012
@@ -0,0 +1,409 @@
+    
+    var session = null;
+    var filter = null;
+    var myPlaylist =null;
+    
+    function connect() {
+        var firstRepoId;        
+        connectToRepo($("#reposfield").val(), $("#jsonpfield").attr("checked")=="checked",
$("#userfield").val(),
+                $("#pwdfield").val(), function(repoInfos) {
+            trace("getRepositories()");
+            var row;
+            var tbl = $('<table>').append($('<tr>').append($('<td>').text("Found
repositories:")))
+                    .append(row = $('<tr>'));
+            for (var repoInfo in repoInfos) {
+                row.append($('<td>').text(repoInfos[repoInfo].repositoryId));
+                if (null == firstRepoId)
+                    firstRepoId = repoInfos[repoInfo].repositoryId;
+            }
+            $("#repositoriessection *").remove();
+            $("#repositoriessection").append(tbl);
+            $("#repoidfield").attr('value', firstRepoId);
+            $("#folderidfield").attr('value', repoInfos[firstRepoId].rootFolderId);
+            
+            createSession($("#reposfield").val(), firstRepoId, $("#jsonpfield").attr("checked")=="checked",
$("#userfield").val(),
+                    $("#pwdfield").val());
+        });    
+    }
+    
+    function connectToRepo(connectionUrl, jsonp, user, password, cbFct) {
+         var factory = new CmisSessionFactory({
+              url : connectionUrl,
+              jsonp : jsonp,
+              user : user,
+              password: password
+            });
+         factory.getRepositories(cbFct, function(errorMessage) {
+             displayError(errorMessage, "#alertpane")
+         });
+    }
+                
+    function createSession(connectionUrl, repoId, jsonp, user, password) {
+                trace("Initializing session to " + connectionUrl);
+                session = null;
+                var factory = new CmisSessionFactory({
+                    url : connectionUrl,
+                    repositoryId : repoId,
+                    jsonp : jsonp,
+                    user : user,
+                    password: password
+                });
+                  
+                session = factory.createSession();
+                session.getRepositoryInfo(function(repoInfos) {
+                    trace("init(): getRepositoryInfo()");
+                    for (var repoInfo in repoInfos) {
+                        session.rootFolderId = repoInfos[repoInfo].rootFolderId;
+                        session.rootUrl = repoInfos[repoInfo].rootFolderUrl;
+                        break;
+                    }
+                    checkSession("#alertpane");
+                });
+    }
+    
+    
+    function checkSession(domId) {
+        if (null == session) {
+            var error = "No session! Please connect first...";
+            displayError(error, domId);
+            throw error;
+        } else {
+            $('#alertpane').text("Connected to server as user: " + session.user);
+        }
+    }
+
+    function displayError(cmisError, domId) {
+        if (null == domId)
+            domId = "#alertpane";
+        $(domId + " *").remove();
+        if (null != cmisError)
+            $(domId).html(cmisError.toString());         
+    }
+    
+    function checkError(jsonObj, domId) {
+        if (jsonObj != null && jsonObj.exception) {
+            var cmisError = session.createErrorFromErrorResponse(jsonObj);
+            displayError(cmisError, domId);
+            return cmisError;
+        } else
+            return null;
+    }
+    
+    function createRandomString() {
+        return Math.round(Math.random()*1000).toString();
+    }
+
+    function onClickQueryForPlaylistFirst() {
+        var pageCtx = session.getPagingContext("doQueryForPlaylist");
+        pageCtx.setFirstPage();
+        doQueryForPlaylist(pageCtx.query);
+    }
+    
+    function onClickQueryForPlaylistPrev() {
+        var pageCtx = session.getPagingContext("doQueryForPlaylist");
+        pageCtx.setPreviousPage();
+        doQueryForPlaylist(pageCtx.query);
+    }
+    
+    function onClickQueryForPlaylistNext() {
+        var pageCtx = session.getPagingContext("doQueryForPlaylist");
+        pageCtx.setNextPage();
+        doQueryForPlaylist(pageCtx.query);
+    }
+    
+    function onClickQueryForPlaylistLast() {
+        var pageCtx = session.getPagingContext("doQueryForPlaylist");        
+        pageCtx.setLastPage();        
+        doQueryForPlaylist(pageCtx.query);
+    }
+    
+    function onClickQueryForAlbumNext() {
+        var pageCtx = session.getPagingContext("doQueryByAlbum");
+        pageCtx.setNextPage();
+        doQueryByAlbum(pageCtx.query);
+    }
+    
+    function onClickQueryForArtistNext() {
+        var pageCtx = session.getPagingContext("doQueryByArtist");
+        pageCtx.setNextPage();
+        doQueryByArtist(pageCtx.query);
+    }
+
+    function getContentUrl(id) {
+        return session.getRootUrl() + "?cmisselector=content&objectId=" + id;
+    }
+    
+    
+    function convertValue(value, type) {
+        if (type == 'string') {
+            if (value == '*')
+                return "'*'"; // confuses text() method 
+            else 
+                return value;
+        } else if (type == 'datetime') {
+            return new Date(value).toLocaleString();
+        } else
+            return value.toString();
+    }
+    
+    function getPropertyValue(props, queryName) {
+        var prop = props[queryName];
+        if (null != prop && null != prop.value) {
+            return convertValue(prop.value, prop.type);
+        } else
+            return "";
+    }
+        
+    function filterByAlbum(filter) {
+        session.deletePagingContext("doQueryByAlbum");
+        if (filter)
+            doQueryByAlbum("SELECT * FROM AUDIO_FILE where ALBUM LIKE '" + filter + "%'");
+        else
+            doQueryByAlbum("SELECT * FROM AUDIO_FILE");
+    }
+    
+    function createAlbumList(queryResp) {
+        var albums = {};
+        
+        for (var child in queryResp.results) {
+            var props = queryResp.results[child].properties;
+            var typeId = getPropertyValue(props, "cmis:objectTypeId");
+            if (typeId != null && typeId === "audioFile") {
+                var playItem = {};
+                var album = getPropertyValue(props, "ALBUM");
+                var artist  = getPropertyValue(props, "ARTIST");
+                if (album && artist)
+                    albums[album] = artist;
+            }
+        }
+        
+        $("#filterresultlist").html(null);
+        for (var album in albums) {
+            $("#filterresultlist").append($("<li>").append($("<a>").attr("href","javascript:getPlaylistForAlbum(\""
+ album + "\");").text(album))
+                    .append($("<span class=\"artist\">").text(" by " + albums[album])));
+        }
+    }
+        
+    function doQueryByAlbum(cmisQuery) {
+        checkSession("#alertpane");
+        $("#queryresponsesection *").remove();
+        trace("doing query: " + cmisQuery);
+        session.doQueryPaged(cmisQuery, "doQueryByAlbum", function(data) {
+            if (!checkError(data, "#alertpane")) {
+                createAlbumList(data);
+                var pageCtx = session.getPagingContext("doQueryByAlbum");
+                pageCtx.query = cmisQuery; // store query for later reuse when paging
+                $("#pagingbuttons").html(null);
+                if (pageCtx.getCurrentPage() < pageCtx.getTotalPages()) {
+                    $("#pagingbuttons")
+                        .append($("<p>").append($("<a>").attr("href", "javascript:onClickQueryForAlbumNext();").text("More...")));
+                }
+            }
+        });       
+    }
+    
+    function loadPlayer(domObj, cbFct) {
+        domObj.load('jplayer.html', function() {
+
+            myPlaylist = new jPlayerPlaylist({
+                jPlayer: "#jquery_jplayer_N",
+                cssSelectorAncestor: "#jplayer"
+            }, [
+                {
+                    title:"<Empty>",
+                    artist:"",
+                    mp3:"",
+                    oga:"",
+                    poster: "poster.jpg"
+                }
+            ], {
+                playlistOptions: {
+                    enableRemoveControls: false
+                },
+                swfPath: "jplayer",
+                supplied: "webmv, mp3"
+                // supplied: "webmv, ogv, m4v, oga, mp3"
+            });
+
+            return cbFct.call(this);
+        });        
+    }
+    
+    function getPlaylistForAlbum(albumName) {
+        var queryString; 
+        
+        if (albumName.lastIndexOf("no/unknown") >= 0)
+            queryString = "SELECT * FROM AUDIO_FILE WHERE ALBUM IS NULL";
+        else
+            queryString = "SELECT * FROM AUDIO_FILE WHERE ALBUM LIKE '" + albumName + "%'
 ORDER BY TRACK";
+        
+        checkSession("#alertpane");
+        // load player view
+        loadPlayer($('#mainpane'), function() {
+            session.opCtx.maxItems = 25; // set paging size
+            session.deletePagingContext("doQueryForPlaylist");
+            $("#playerheader").html($("<h3 class=\"ui-widget ui-widget-header\">").text("Album:
" + albumName));
+            doQueryForPlaylist(queryString);
+            });
+    }
+    
+    function filterByArtist(filter) {
+        session.deletePagingContext("doQueryByArtist");
+        if (filter)
+            doQueryByArtist("SELECT * FROM AUDIO_FILE where ARTIST LIKE '" + filter + "%'");
+        else
+            doQueryByArtist("SELECT * FROM AUDIO_FILE");
+    }
+
+    function doQueryByArtist(cmisQuery) {
+        checkSession("#alertpane");
+        $("#queryresponsesection *").remove();
+        trace("doing query: " + cmisQuery);
+        session.doQueryPaged(cmisQuery, "doQueryByArtist", function(data) {
+            if (!checkError(data, "#alertpane")) {
+                createArtistList(data);
+                var pageCtx = session.getPagingContext("doQueryByArtist");
+                pageCtx.query = cmisQuery; // store query for later reuse when paging
+                $("#pagingbuttons").html(null);
+                if (pageCtx.getCurrentPage() < pageCtx.getTotalPages()) {
+                    $("#pagingbuttons")
+                        .append($("<p>").append($("<a>").attr("href", "javascript:onClickQueryForArtistNext();").text("More...")));
+                }
+            }
+        });       
+    }
+    
+    function createArtistList(queryResp) {
+        var albums = {};
+        for (var child in queryResp.results) {
+            var props = queryResp.results[child].properties;
+            var typeId = getPropertyValue(props, "cmis:objectTypeId");
+            if (typeId != null && typeId === "audioFile") {
+                var playItem = {};
+                var album = getPropertyValue(props, "ALBUM");
+                var artist  = getPropertyValue(props, "ARTIST");
+                if (album && artist)
+                    albums[album] = artist;
+                else if (artist) 
+                    albums[album] = "(no/unknown album)";
+            }
+        }
+        
+        $("#filterresultlist").html(null);
+        for (var album in albums) {
+            $("#filterresultlist").append($("<li>").append($("<a>").attr("href","javascript:getPlaylistForAlbum(\""
+ album + "\");").text(album))
+                    .append($("<span class=\"artist\">").text(" by " + albums[album])));
+        }
+    }
+
+    function filterByTitle(filter) {
+        session.deletePagingContext("doQueryByAlbum");
+        if (filter)
+            doQueryForPlaylist("SELECT * FROM AUDIO_FILE where TITLE LIKE '" + filter + "%'");
+        else
+            doQueryForPlaylist("SELECT * FROM AUDIO_FILE");
+    }
+    
+    function doQueryForPlaylist(queryString) {
+        checkSession("#alertpane");
+        $("#queryresponsesection *").remove();
+        trace("doing query: " + queryString);
+        session.doQueryPaged(queryString, "doQueryForPlaylist", function(data) {
+            if (!checkError(data, "#queryresponsesection")) {
+                var tbl = createPlaylist(data);
+                var pageCtx = session.getPagingContext("doQueryForPlaylist");
+                pageCtx.query = queryString;
+                var totalItems = pageCtx.totalItems==null ? 4294967295 : pageCtx.totalItems;
+                var page = Math.floor(pageCtx.skipCount / session.opCtx.maxItems) + 1;
+                var totalPages;
+                if (pageCtx.totalItems==null)
+                    totalPages = "(unknown)";
+                else
+                    totalPages = ((totalItems - (totalItems % session.opCtx.maxItems)) /
session.opCtx.maxItems) + 1;
+                
+                if (data.results.length == 0)
+                    $("#pagingbuttons").html($("<p>").text("No items found."));
+                else
+                    $("#pagingbuttons").html(null);
+                
+                if (pageCtx.getTotalPages() > 1) {
+                    // #queryresponsesection
+                    // $("#pagingbuttons").html($("<p>").text("Retrieved playlist from
server, found " + totalItems + 
+                    //         " items. Use buttons for paging through the list."))
+                    $("#pagingbuttons")
+                        .append($("<table>").append($("<tr>").append($("<td>")
+                        .append($("<button>").attr("value", "first").click(function()
{onClickQueryForPlaylistFirst();}).append($("<img>").attr("src", "images/first.png")))
+                        .append($("<button>").attr("value", "prev").click(function()
{onClickQueryForPlaylistPrev();}).append($("<img>").attr("src", "images/prev.png")))
+                        .append($("<button>").attr("value", "next").click(function()
{onClickQueryForPlaylistNext();}).append($("<img>").attr("src", "images/next.png")))
+                        .append($("<button>").attr("value", "last").click(function()
{onClickQueryForPlaylistLast();}).append($("<img>").attr("src", "images/last.png"))))
+                        .append($("<td>").text("Page " + page + " of " + totalPages
+ " / Items total: " + (totalItems==4294967295?"unknown":totalItems)))))
+                        .append($("<hr>"));
+                }
+            }
+        });
+    };
+    
+    function createPlaylist(queryResp) {
+        var playList = [];
+        
+        for (var child in queryResp.results) {
+            var props = queryResp.results[child].properties;
+            var typeId = getPropertyValue(props, "cmis:objectTypeId");
+            if (typeId != null && typeId === "audioFile") {
+                var playItem = {};
+                playItem.artist = getPropertyValue(props, "ARTIST");
+                playItem.title = getPropertyValue(props, "TITLE");
+                playItem.mp3 = getContentUrl(getPropertyValue(props, "cmis:objectId"));
+                playItem.poster = "images/musical-notes.jpg";
+                trace("add track: " + playItem.mp3);
+                playList.push(playItem);
+            }
+        }        
+        myPlaylist.setPlaylist(playList);
+    }
+
+    function onFilterByAlbum() {
+        checkSession("#alertpane");
+        $('#mainpane').load('filterbyalbum.html', function() {
+        });
+    }
+
+    function onFilterByArtist() {
+        checkSession("#alertpane");
+        $('#mainpane').load('filterbyartist.html', function() {
+        });
+    }
+    
+    function onFilterByTitle() {
+        checkSession("#alertpane");
+        $('#mainpane').load('filterbytitle.html', function() {
+            loadPlayer($('#playerpane'), function() {
+                });
+       });
+    }
+
+    $(document).ready(function() {
+
+        $(document).ajaxError(function(event, request, settings, excep){
+            var cmisError = CmisSession.defaultErrorHandler(event, request, settings, excep);
+            displayError(cmisError, '#alertpane');
+         });
+        
+        var myLayout = $('body').layout({
+            west__size:         200 // "25%"
+        ,   east__size:         0
+            // RESIZE Accordion widget when panes resize
+        ,   west__onresize:     $.layout.callbacks.resizePaneAccordions
+        });
+
+        // ACCORDION - in the West pane
+        $("#accordion1").accordion({ fillSpace: true,
+                                     active:     1
+                                   });        
+        connect();
+        
+        $('#connectbutton').click(function() {
+            connect();
+        });
+
+    });  
\ No newline at end of file



Mime
View raw message