From bb7d018de4ab3b9d0b801a2a76b13aad49b559ab Mon Sep 17 00:00:00 2001 From: Emory P Date: Wed, 12 Feb 2014 01:18:36 -0500 Subject: [PATCH] js-beautify all the controllers, services and directives (and jshint) --- js/_saved/angular-1.1.4.min.js | 173 ----- js/_saved/angular-cookies.js | 184 ----- js/_saved/angular-cookies.min.js | 7 - js/_saved/angular-resource.min.js | 11 - js/_saved/angular-sanitize.min.js | 13 - js/_saved/archiveViewModel.js | 43 -- js/_saved/demo.html | 15 - js/_saved/saved.html | 592 --------------- js/_saved/subsonicViewModel.js | 190 ----- js/_saved/subsonic_old.js | 21 - js/app.js | 94 ++- js/controllers/archive.js | 569 +++++++------- js/controllers/library.js | 1147 +++++++++++++++-------------- js/controllers/main.js | 1072 ++++++++++++++------------- js/controllers/partial.js | 52 -- js/controllers/playlists.js | 437 +++++------ js/controllers/podcasts.js | 238 +++--- js/controllers/queue.js | 12 +- js/controllers/settings.js | 180 +++-- js/player.js | 198 +++-- js/service.js | 380 +++++----- js/subsonic.js | 1 - js/utils.js | 350 +++++---- 23 files changed, 2533 insertions(+), 3446 deletions(-) delete mode 100644 js/_saved/angular-1.1.4.min.js delete mode 100644 js/_saved/angular-cookies.js delete mode 100644 js/_saved/angular-cookies.min.js delete mode 100644 js/_saved/angular-resource.min.js delete mode 100644 js/_saved/angular-sanitize.min.js delete mode 100644 js/_saved/archiveViewModel.js delete mode 100644 js/_saved/demo.html delete mode 100644 js/_saved/saved.html delete mode 100644 js/_saved/subsonicViewModel.js delete mode 100644 js/_saved/subsonic_old.js delete mode 100644 js/controllers/partial.js delete mode 100644 js/subsonic.js diff --git a/js/_saved/angular-1.1.4.min.js b/js/_saved/angular-1.1.4.min.js deleted file mode 100644 index 486d5e1..0000000 --- a/js/_saved/angular-1.1.4.min.js +++ /dev/null @@ -1,173 +0,0 @@ -/* - AngularJS v1.1.4 - (c) 2010-2012 Google, Inc. http://angularjs.org - License: MIT -*/ -(function(M,V,s){'use strict';function gc(){var b=M.angular;M.angular=hc;return b}function o(b,a,c){var d;if(b)if(I(b))for(d in b)d!="prototype"&&d!="length"&&d!="name"&&b.hasOwnProperty(d)&&a.call(c,b[d],d);else if(b.forEach&&b.forEach!==o)b.forEach(a,c);else if(!b||typeof b.length!=="number"?0:typeof b.hasOwnProperty!="function"&&typeof b.constructor!="function"||b instanceof P||ca&&b instanceof ca||Da.call(b)!=="[object Object]"||typeof b.callee==="function")for(d=0;d=0&&b.splice(c,1);return a}function W(b,a){if(ra(b)||b&&b.$evalAsync&&b.$watch)throw Error("Can't copy Window or Scope");if(a){if(b===a)throw Error("Can't copy equivalent objects or arrays");if(C(b))for(var c=a.length=0;c2?ka.call(arguments,2):[];return I(a)&&!(a instanceof RegExp)?c.length?function(){return arguments.length?a.apply(b,c.concat(ka.call(arguments,0))):a.apply(b,c)}:function(){return arguments.length?a.apply(b,arguments):a.call(b)}:a}function lc(b,a){var c=a;/^\$+/.test(b)?c=s:ra(a)?c="$WINDOW":a&&V===a?c="$DOCUMENT":a&&a.$evalAsync&&a.$watch&&(c="$SCOPE");return c}function da(b,a){return JSON.stringify(b,lc,a?" ":null)}function tb(b){return x(b)? -JSON.parse(b):b}function Ha(b){b&&b.length!==0?(b=J(""+b),b=!(b=="f"||b=="0"||b=="false"||b=="no"||b=="n"||b=="[]")):b=!1;return b}function ta(b){b=v(b).clone();try{b.html("")}catch(a){}var c=v("
").append(b).html();try{return b[0].nodeType===3?J(c):c.match(/^(<[^>]+>)/)[1].replace(/^<([\w\-]+)/,function(a,b){return"<"+J(b)})}catch(d){return J(c)}}function bb(b){var a={},c,d;o((b||"").split("&"),function(b){b&&(c=b.split("="),d=decodeURIComponent(c[0]),a[d]=w(c[1])?decodeURIComponent(c[1]):!0)}); -return a}function ub(b){var a=[];o(b,function(b,d){a.push(ua(d,!0)+(b===!0?"":"="+ua(b,!0)))});return a.length?a.join("&"):""}function cb(b){return ua(b,!0).replace(/%26/gi,"&").replace(/%3D/gi,"=").replace(/%2B/gi,"+")}function ua(b,a){return encodeURIComponent(b).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,a?"%20":"+")}function mc(b,a){function c(a){a&&d.push(a)}var d=[b],e,f,i=["ng:app","ng-app","x-ng-app","data-ng-app"],h=/\sng[:\-]app(:\s*([\w\d_]+);?)?\s/; -o(i,function(a){i[a]=!0;c(V.getElementById(a));a=a.replace(":","\\:");b.querySelectorAll&&(o(b.querySelectorAll("."+a),c),o(b.querySelectorAll("."+a+"\\:"),c),o(b.querySelectorAll("["+a+"]"),c))});o(d,function(a){if(!e){var b=h.exec(" "+a.className+" ");b?(e=a,f=(b[2]||"").replace(/\s+/g,",")):o(a.attributes,function(b){if(!e&&i[b.name])e=a,f=b.value})}});e&&a(e,f?[f]:[])}function vb(b,a){var c=function(){b=v(b);a=a||[];a.unshift(["$provide",function(a){a.value("$rootElement",b)}]);a.unshift("ng"); -var c=wb(a);c.invoke(["$rootScope","$rootElement","$compile","$injector",function(a,b,c,d){a.$apply(function(){b.data("$injector",d);c(b)(a)})}]);return c},d=/^NG_DEFER_BOOTSTRAP!/;if(M&&!d.test(M.name))return c();M.name=M.name.replace(d,"");Ia.resumeBootstrap=function(b){o(b,function(b){a.push(b)});c()}}function db(b,a){a=a||"_";return b.replace(nc,function(b,d){return(d?a:"")+b.toLowerCase()})}function eb(b,a,c){if(!b)throw Error("Argument '"+(a||"?")+"' is "+(c||"required"));return b}function va(b, -a,c){c&&C(b)&&(b=b[b.length-1]);eb(I(b),a,"not a function, got "+(b&&typeof b=="object"?b.constructor.name||"Object":typeof b));return b}function oc(b){function a(a,b,e){return a[b]||(a[b]=e())}return a(a(b,"angular",Object),"module",function(){var b={};return function(d,e,f){e&&b.hasOwnProperty(d)&&(b[d]=null);return a(b,d,function(){function a(c,d,e){return function(){b[e||"push"]([c,d,arguments]);return m}}if(!e)throw Error("No module: "+d);var b=[],c=[],g=a("$injector","invoke"),m={_invokeQueue:b, -_runBlocks:c,requires:e,name:d,provider:a("$provide","provider"),factory:a("$provide","factory"),service:a("$provide","service"),value:a("$provide","value"),constant:a("$provide","constant","unshift"),animation:a("$animationProvider","register"),filter:a("$filterProvider","register"),controller:a("$controllerProvider","register"),directive:a("$compileProvider","directive"),config:g,run:function(a){c.push(a);return this}};f&&g(f);return m})}})}function Ja(b){return b.replace(pc,function(a,b,d,e){return e? -d.toUpperCase():d}).replace(qc,"Moz$1")}function fb(b,a){function c(){var e;for(var b=[this],c=a,i,h,j,g,m,k;b.length;){i=b.shift();h=0;for(j=i.length;h 
"+b;a.removeChild(a.firstChild);gb(this,a.childNodes);this.remove()}else gb(this,b)}function hb(b){return b.cloneNode(!0)}function wa(b){xb(b);for(var a=0,b=b.childNodes||[];a-1}function Ab(b,a){a&&o(a.split(" "),function(a){b.className=S((" "+b.className+" ").replace(/[\n\t]/g," ").replace(" "+S(a)+" "," "))})}function Bb(b, -a){a&&o(a.split(" "),function(a){if(!Ma(b,a))b.className=S(b.className+" "+S(a))})}function gb(b,a){if(a)for(var a=!a.nodeName&&w(a.length)&&!ra(a)?a:[a],c=0;c4096&&c.warn("Cookie '"+a+"' possibly not set or overflowed because it was too large ("+d+" > 4096 bytes)!")}else{if(j.cookie!==H){H=j.cookie;d=H.split("; ");A={};for(g=0;g0&&(A[unescape(e.substring(0,h))]=unescape(e.substring(h+1)))}return A}};h.defer=function(a,b){var c;n++;c=k(function(){delete q[c];e(a)},b||0);q[c]=!0;return c};h.defer.cancel=function(a){return q[a]?(delete q[a],l(a),e(t),!0):!1}}function zc(){this.$get=["$window","$log","$sniffer","$document",function(b,a,c,d){return new yc(b,d,a,c)}]}function Ac(){this.$get=function(){function b(b,d){function e(a){if(a!=k){if(l){if(l==a)l=a.n}else l=a;f(a.n,a.p);f(a,k);k=a;k.n=null}}function f(a, -b){if(a!=b){if(a)a.p=b;if(b)b.n=a}}if(b in a)throw Error("cacheId "+b+" taken");var i=0,h=y({},d,{id:b}),j={},g=d&&d.capacity||Number.MAX_VALUE,m={},k=null,l=null;return a[b]={put:function(a,b){var c=m[a]||(m[a]={key:a});e(c);if(!u(b))return a in j||i++,j[a]=b,i>g&&this.remove(l.key),b},get:function(a){var b=m[a];if(b)return e(b),j[a]},remove:function(a){var b=m[a];if(b){if(b==k)k=b.p;if(b==l)l=b.n;f(b.n,b.p);delete m[a];delete j[a];i--}},removeAll:function(){j={};i=0;m={};k=l=null},destroy:function(){m= -h=j=null;delete a[b]},info:function(){return y({},h,{size:i})}}}var a={};b.info=function(){var b={};o(a,function(a,e){b[e]=a.info()});return b};b.get=function(b){return a[b]};return b}}function Bc(){this.$get=["$cacheFactory",function(b){return b("templates")}]}function Hb(b){var a={},c="Directive",d=/^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/,e=/(([\d\w\-_]+)(?:\:([^;]+))?;?)/,f="Template must have exactly one root element. was: ",i=/^\s*(https?|ftp|mailto|file):/;this.directive=function j(d,e){x(d)? -(eb(e,"directive"),a.hasOwnProperty(d)||(a[d]=[],b.factory(d+c,["$injector","$exceptionHandler",function(b,c){var e=[];o(a[d],function(a){try{var f=b.invoke(a);if(I(f))f={compile:Q(f)};else if(!f.compile&&f.link)f.compile=Q(f.link);f.priority=f.priority||0;f.name=f.name||d;f.require=f.require||f.controller&&f.name;f.restrict=f.restrict||"A";e.push(f)}catch(j){c(j)}});return e}])),a[d].push(e)):o(d,sb(j));return this};this.urlSanitizationWhitelist=function(a){return w(a)?(i=a,this):i};this.$get=["$injector", -"$interpolate","$exceptionHandler","$http","$templateCache","$parse","$controller","$rootScope","$document",function(b,g,m,k,l,q,n,B,r){function p(a,b,c){a instanceof v||(a=v(a));o(a,function(b,c){b.nodeType==3&&b.nodeValue.match(/\S+/)&&(a[c]=v(b).wrap("").parent()[0])});var d=D(a,b,a,c);return function(b,c){eb(b,"scope");for(var e=c?za.clone.call(a):a,g=0,f=e.length;gz.priority)break;if(y=z.scope)ea("isolated scope",ba,z,A),L(y)&&(E(A,"ng-isolate-scope"),ba=z),E(A, -"ng-scope"),D=D||z;T=z.name;if(y=z.controller)ha=ha||{},ea("'"+T+"' controller",ha[T],z,A),ha[T]=z;if(y=z.transclude)ea("transclusion",ga,z,A),ga=z,k=z.priority,y=="element"?(R=v(b),A=c.$$element=v(V.createComment(" "+T+": "+c[T]+" ")),b=A[0],fa(e,v(R[0]),b),ia=p(R,d,k)):(R=v(hb(b)).contents(),A.html(""),ia=p(R,d));if(z.template)if(ea("template",N,z,A),N=z,y=I(z.template)?z.template(A,c):z.template,y=Jb(y),z.replace){R=v("
"+S(y)+"
").contents();b=R[0];if(R.length!=1||b.nodeType!==1)throw Error(f+ -y);fa(e,A,b);T={$attr:{}};a=a.concat(G(b,a.splice(w+1,a.length-(w+1)),T));H(c,T);u=a.length}else A.html(y);if(z.templateUrl)ea("template",N,z,A),N=z,l=F(a.splice(w,a.length-w),l,A,c,e,z.replace,ia),u=a.length;else if(z.compile)try{t=z.compile(A,c,ia),I(t)?j(null,t):t&&j(t.pre,t.post)}catch(J){m(J,ta(A))}if(z.terminal)l.terminal=!0,k=Math.max(k,z.priority)}l.scope=D&&D.scope;l.transclude=ga&&ia;return l}function A(d,e,g,f){var l=!1;if(a.hasOwnProperty(e))for(var i,e=b.get(e+c),n=0,k=e.length;ni.priority)&&i.restrict.indexOf(g)!=-1)d.push(i),l=!0}catch(q){m(q)}return l}function H(a,b){var c=b.$attr,d=a.$attr,e=a.$$element;o(a,function(d,e){e.charAt(0)!="$"&&(b[e]&&(d+=(e==="style"?";":" ")+b[e]),a.$set(e,d,!0,c[e]))});o(b,function(b,g){g=="class"?(E(e,b),a["class"]=(a["class"]?a["class"]+" ":"")+b):g=="style"?e.attr("style",e.attr("style")+";"+b):g.charAt(0)!="$"&&!a.hasOwnProperty(g)&&(a[g]=b,d[g]=c[g])})}function F(a,b,c,d,e,g,j){var i=[],n,m,q=c[0],p=a.shift(),ya=y({}, -p,{controller:null,templateUrl:null,transclude:null,scope:null}),p=I(p.templateUrl)?p.templateUrl(c,d):p.templateUrl;c.html("");k.get(p,{cache:l}).success(function(l){var k,p,l=Jb(l);if(g){p=v("
"+S(l)+"
").contents();k=p[0];if(p.length!=1||k.nodeType!==1)throw Error(f+l);l={$attr:{}};fa(e,c,k);G(k,a,l);H(d,l)}else k=q,c.html(l);a.unshift(ya);n=R(a,k,d,j);for(m=D(c[0].childNodes,j);i.length;){var B=i.shift(),l=i.shift();p=i.shift();var r=i.shift(),F=k;l!==q&&(F=hb(k),fa(p,v(l),F));n(function(){b(m, -B,F,e,r)},B,F,e,r)}i=null}).error(function(a,b,c,d){throw Error("Failed to load template: "+d.url);});return function(a,c,d,e,g){i?(i.push(c),i.push(d),i.push(e),i.push(g)):n(function(){b(m,c,d,e,g)},c,d,e,g)}}function N(a,b){return b.priority-a.priority}function ea(a,b,c,d){if(b)throw Error("Multiple directives ["+b.name+", "+c.name+"] asking for "+a+" on: "+ta(d));}function ga(a,b){var c=g(b,!0);c&&a.push({priority:0,compile:Q(function(a,b){var d=b.parent(),e=d.data("$binding")||[];e.push(c);E(d.data("$binding", -e),"ng-binding");a.$watch(c,function(a){b[0].nodeValue=a})})})}function z(a,b,c,d){var e=g(c,!0);e&&b.push({priority:100,compile:Q(function(a,b,c){b=c.$$observers||(c.$$observers={});if(e=g(c[d],!0))c[d]=e(a),(b[d]||(b[d]=[])).$$inter=!0,(c.$$observers&&c.$$observers[d].$$scope||a).$watch(e,function(a){c.$set(d,a)})})})}function fa(a,b,c){var d=b[0],e=d.parentNode,g,f;if(a){g=0;for(f=a.length;g0){var e=F[0],g=e.text;if(g==a||g==b||g==c||g==d||!a&&!b&&!c&&!d)return e}return!1}function h(b,c,d,g){return(b=i(b,c,d,g))?(a&&!b.json&&e("is not valid json",b),F.shift(),b):!1}function j(a){h(a)||e("is unexpected, expecting ["+a+"]",i())}function g(a,b){return y(function(c,d){return a(c,d,b)},{constant:b.constant})}function m(a,b,c){return y(function(d,e){return b(d,e,a,c)},{constant:a.constant&&c.constant})}function k(){for(var a=[];;)if(F.length>0&&!i("}",")",";","]")&&a.push(fa()), -!h(";"))return a.length==1?a[0]:function(b,c){for(var d,e=0;e","<=",">="))a=m(a,b.fn,r());return a}function p(){for(var a=E(),b;b=h("*","/","%");)a=m(a,b.fn,E());return a}function E(){var a;return h("+")?D():(a=h("-"))?m(A,a.fn,E()):(a=h("!"))?g(a.fn,E()):D()}function D(){var a;if(h("("))a=fa(),j(")");else if(h("["))a=G();else if(h("{"))a=o();else{var b=h();(a=b.fn)||e("not a primary expression",b);if(b.json)a.constant=a.literal=!0}for(var c;b=h("(","[",".");)b.text=== -"("?(a=ea(a,c),c=null):b.text==="["?(c=a,a=z(a)):b.text==="."?(c=a,a=ga(a)):e("IMPOSSIBLE");return a}function G(){var a=[],b=!0;if(f().text!="]"){do{var c=N();a.push(c);c.constant||(b=!1)}while(h(","))}j("]");return y(function(b,c){for(var d=[],e=0;e1;d++){var e=a.shift(),f=b[e];f||(f={},b[e]=f);b=f}return b[a.shift()]=c}function kb(b,a,c){if(!a)return b;for(var a=a.split("."),d,e=b,f=a.length,i=0;ia)for(b in h++,e)e.hasOwnProperty(b)&&!f.hasOwnProperty(b)&&(o--,delete e[b])}else e!==f&&(e=f,h++);return h}, -function(){b(f,e,c)})},$digest:function(){var a,d,e,i,q=this.$$asyncQueue,n,o,r=b,p,E=[],D,G;f("$digest");do{o=!1;for(p=this;q.length;)try{p.$eval(q.shift())}catch(s){c(s)}do{if(i=p.$$watchers)for(n=i.length;n--;)try{if(a=i[n],(d=a.get(p))!==(e=a.last)&&!(a.eq?ja(d,e):typeof d=="number"&&typeof e=="number"&&isNaN(d)&&isNaN(e)))o=!0,a.last=a.eq?W(d):d,a.fn(d,e===h?d:e,p),r<5&&(D=4-r,E[D]||(E[D]=[]),G=I(a.exp)?"fn: "+(a.exp.name||a.exp.toString()):a.exp,G+="; newVal: "+da(d)+"; oldVal: "+da(e),E[D].push(G))}catch(A){c(A)}if(!(i= -p.$$childHead||p!==this&&p.$$nextSibling))for(;p!==this&&!(i=p.$$nextSibling);)p=p.$parent}while(p=i);if(o&&!r--)throw j.$$phase=null,Error(b+" $digest() iterations reached. Aborting!\nWatchers fired in the last 5 iterations: "+da(E));}while(o||q.length);j.$$phase=null},$destroy:function(){if(!(j==this||this.$$destroyed)){var a=this.$parent;this.$broadcast("$destroy");this.$$destroyed=!0;if(a.$$childHead==this)a.$$childHead=this.$$nextSibling;if(a.$$childTail==this)a.$$childTail=this.$$prevSibling; -if(this.$$prevSibling)this.$$prevSibling.$$nextSibling=this.$$nextSibling;if(this.$$nextSibling)this.$$nextSibling.$$prevSibling=this.$$prevSibling;this.$parent=this.$$nextSibling=this.$$prevSibling=this.$$childHead=this.$$childTail=null}},$eval:function(a,b){return d(a)(this,b)},$evalAsync:function(a){this.$$asyncQueue.push(a)},$apply:function(a){try{return f("$apply"),this.$eval(a)}catch(b){c(b)}finally{j.$$phase=null;try{j.$digest()}catch(d){throw c(d),d;}}},$on:function(a,b){var c=this.$$listeners[a]; -c||(this.$$listeners[a]=c=[]);c.push(b);return function(){c[Ga(c,b)]=null}},$emit:function(a,b){var d=[],e,f=this,h=!1,i={name:a,targetScope:f,stopPropagation:function(){h=!0},preventDefault:function(){i.defaultPrevented=!0},defaultPrevented:!1},j=[i].concat(ka.call(arguments,1)),p,o;do{e=f.$$listeners[a]||d;i.currentScope=f;p=0;for(o=e.length;p7),hasEvent:function(a){if(a=="input"&&X==9)return!1;if(u(c[a])){var b=e.createElement("div");c[a]="on"+a in b}return c[a]}, -csp:e.securityPolicy?e.securityPolicy.isActive:!1,vendorPrefix:f,supportsTransitions:j}}]}function Wc(){this.$get=Q(M)}function Qb(b){var a={},c,d,e;if(!b)return a;o(b.split("\n"),function(b){e=b.indexOf(":");c=J(S(b.substr(0,e)));d=S(b.substr(e+1));c&&(a[c]?a[c]+=", "+d:a[c]=d)});return a}function Xc(b,a){var c=Yc.exec(b);if(c==null)return!0;var d={protocol:c[2],host:c[4],port:K(c[6])||Ba[c[2]]||null,relativeProtocol:c[2]===s||c[2]===""},c=lb.exec(a),c={protocol:c[1],host:c[3],port:K(c[5])||Ba[c[1]]|| -null};return(d.protocol==c.protocol||d.relativeProtocol)&&d.host==c.host&&(d.port==c.port||d.relativeProtocol&&c.port==Ba[c.protocol])}function Rb(b){var a=L(b)?b:s;return function(c){a||(a=Qb(b));return c?a[J(c)]||null:a}}function Sb(b,a,c){if(I(c))return c(b,a);o(c,function(c){b=c(b,a)});return b}function Zc(){var b=/^\s*(\[|\{[^\{])/,a=/[\}\]]\s*$/,c=/^\)\]\}',?\n/,d=this.defaults={transformResponse:[function(d){x(d)&&(d=d.replace(c,""),b.test(d)&&a.test(d)&&(d=tb(d,!0)));return d}],transformRequest:[function(a){return L(a)&& -Da.apply(a)!=="[object File]"?da(a):a}],headers:{common:{Accept:"application/json, text/plain, */*"},post:{"Content-Type":"application/json;charset=utf-8"},put:{"Content-Type":"application/json;charset=utf-8"}},xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN"},e=this.interceptors=[],f=this.responseInterceptors=[];this.$get=["$httpBackend","$browser","$cacheFactory","$rootScope","$q","$injector",function(a,b,c,g,m,k){function l(a){function c(a){var b=y({},a,{data:Sb(a.data,a.headers,e.transformResponse)}); -return 200<=a.status&&a.status<300?b:m.reject(b)}var e={transformRequest:d.transformRequest,transformResponse:d.transformResponse},g={};y(e,a);e.headers=g;e.method=na(e.method);y(g,d.headers.common,d.headers[J(e.method)],a.headers);(a=Xc(e.url,b.url())?b.cookies()[e.xsrfCookieName||d.xsrfCookieName]:s)&&(g[e.xsrfHeaderName||d.xsrfHeaderName]=a);var f=[function(a){var b=Sb(a.data,Rb(g),a.transformRequest);u(a.data)&&delete g["Content-Type"];if(u(a.withCredentials)&&!u(d.withCredentials))a.withCredentials= -d.withCredentials;return q(a,b,g).then(c,c)},s],j=m.when(e);for(o(r,function(a){(a.request||a.requestError)&&f.unshift(a.request,a.requestError);(a.response||a.responseError)&&f.push(a.response,a.responseError)});f.length;)var a=f.shift(),i=f.shift(),j=j.then(a,i);j.success=function(a){j.then(function(b){a(b.data,b.status,b.headers,e)});return j};j.error=function(a){j.then(null,function(b){a(b.data,b.status,b.headers,e)});return j};return j}function q(b,c,e){function f(a,b,c){o&&(200<=a&&a<300?o.put(s, -[a,b,Qb(c)]):o.remove(s));h(b,a,c);g.$apply()}function h(a,c,d){c=Math.max(c,0);(200<=c&&c<300?k.resolve:k.reject)({data:a,status:c,headers:Rb(d),config:b})}function j(){var a=Ga(l.pendingRequests,b);a!==-1&&l.pendingRequests.splice(a,1)}var k=m.defer(),q=k.promise,o,r,s=n(b.url,b.params);l.pendingRequests.push(b);q.then(j,j);if((b.cache||d.cache)&&b.cache!==!1&&b.method=="GET")o=L(b.cache)?b.cache:L(d.cache)?d.cache:B;if(o)if(r=o.get(s))if(r.then)return r.then(j,j),r;else C(r)?h(r[1],r[0],W(r[2])): -h(r,200,{});else o.put(s,q);r||a(b.method,s,c,f,e,b.timeout,b.withCredentials,b.responseType);return q}function n(a,b){if(!b)return a;var c=[];ic(b,function(a,b){a==null||a==s||(C(a)||(a=[a]),o(a,function(a){L(a)&&(a=da(a));c.push(ua(b)+"="+ua(a))}))});return a+(a.indexOf("?")==-1?"?":"&")+c.join("&")}var B=c("$http"),r=[];o(e,function(a){r.unshift(x(a)?k.get(a):k.invoke(a))});o(f,function(a,b){var c=x(a)?k.get(a):k.invoke(a);r.splice(b,0,{response:function(a){return c(m.when(a))},responseError:function(a){return c(m.reject(a))}})}); -l.pendingRequests=[];(function(a){o(arguments,function(a){l[a]=function(b,c){return l(y(c||{},{method:a,url:b}))}})})("get","delete","head","jsonp");(function(a){o(arguments,function(a){l[a]=function(b,c,d){return l(y(d||{},{method:a,url:b,data:c}))}})})("post","put");l.defaults=d;return l}]}function $c(){this.$get=["$browser","$window","$document",function(b,a,c){return ad(b,bd,b.defer,a.angular.callbacks,c[0],a.location.protocol.replace(":",""))}]}function ad(b,a,c,d,e,f){function i(a,b){var c= -e.createElement("script"),d=function(){e.body.removeChild(c);b&&b()};c.type="text/javascript";c.src=a;X?c.onreadystatechange=function(){/loaded|complete/.test(c.readyState)&&d()}:c.onload=c.onerror=d;e.body.appendChild(c)}return function(e,j,g,m,k,l,q,n){function B(a,c,d,e){c=(j.match(lb)||["",f])[1]=="file"?d?200:404:c;a(c==1223?204:c,d,e);b.$$completeOutstandingRequest(t)}b.$$incOutstandingRequestCount();j=j||b.url();if(J(e)=="jsonp"){var r="_"+(d.counter++).toString(36);d[r]=function(a){d[r].data= -a};i(j.replace("JSON_CALLBACK","angular.callbacks."+r),function(){d[r].data?B(m,200,d[r].data):B(m,-2);delete d[r]})}else{var p=new a;p.open(e,j,!0);o(k,function(a,b){a&&p.setRequestHeader(b,a)});var s;p.onreadystatechange=function(){if(p.readyState==4){var a=p.getAllResponseHeaders(),b=["Cache-Control","Content-Language","Content-Type","Expires","Last-Modified","Pragma"];a||(a="",o(b,function(b){var c=p.getResponseHeader(b);c&&(a+=b+": "+c+"\n")}));B(m,s||p.status,p.responseType?p.response:p.responseText, -a)}};if(q)p.withCredentials=!0;if(n)p.responseType=n;p.send(g||"");l>0&&c(function(){s=-1;p.abort()},l)}}}function cd(){this.$get=function(){return{id:"en-us",NUMBER_FORMATS:{DECIMAL_SEP:".",GROUP_SEP:",",PATTERNS:[{minInt:1,minFrac:0,maxFrac:3,posPre:"",posSuf:"",negPre:"-",negSuf:"",gSize:3,lgSize:3},{minInt:1,minFrac:2,maxFrac:2,posPre:"\u00a4",posSuf:"",negPre:"(\u00a4",negSuf:")",gSize:3,lgSize:3}],CURRENCY_SYM:"$"},DATETIME_FORMATS:{MONTH:"January,February,March,April,May,June,July,August,September,October,November,December".split(","), -SHORTMONTH:"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(","),DAY:"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(","),SHORTDAY:"Sun,Mon,Tue,Wed,Thu,Fri,Sat".split(","),AMPMS:["AM","PM"],medium:"MMM d, y h:mm:ss a","short":"M/d/yy h:mm a",fullDate:"EEEE, MMMM d, y",longDate:"MMMM d, y",mediumDate:"MMM d, y",shortDate:"M/d/yy",mediumTime:"h:mm:ss a",shortTime:"h:mm a"},pluralCat:function(b){return b===1?"one":"other"}}}}function dd(){this.$get=["$rootScope","$browser","$q", -"$exceptionHandler",function(b,a,c,d){function e(e,h,j){var g=c.defer(),m=g.promise,k=w(j)&&!j,h=a.defer(function(){try{g.resolve(e())}catch(a){g.reject(a),d(a)}k||b.$apply()},h),j=function(){delete f[m.$$timeoutId]};m.$$timeoutId=h;f[h]=g;m.then(j,j);return m}var f={};e.cancel=function(b){return b&&b.$$timeoutId in f?(f[b.$$timeoutId].reject("canceled"),a.defer.cancel(b.$$timeoutId)):!1};return e}]}function Tb(b){function a(a,e){return b.factory(a+c,e)}var c="Filter";this.register=a;this.$get=["$injector", -function(a){return function(b){return a.get(b+c)}}];a("currency",Ub);a("date",Vb);a("filter",ed);a("json",fd);a("limitTo",gd);a("lowercase",hd);a("number",Wb);a("orderBy",Xb);a("uppercase",id)}function ed(){return function(b,a,c){if(!C(b))return b;var d=[];d.check=function(a){for(var b=0;b-1}}var e=function(a,b){if(typeof b=="string"&&b.charAt(0)==="!")return!e(a,b.substr(1));switch(typeof a){case "boolean":case "number":case "string":return c(a,b);case "object":switch(typeof b){case "object":return c(a,b);default:for(var d in a)if(d.charAt(0)!=="$"&&e(a[d],b))return!0}return!1;case "array":for(d=0;de+1?i="0":(h=i,g=!0)}if(!g){i=(i.split(Zb)[1]||"").length;u(e)&&(e=Math.min(Math.max(a.minFrac,i),a.maxFrac));var i=Math.pow(10,e),b=Math.round(b*i)/i,b=(""+b).split(Zb),i=b[0],b=b[1]||"",g=0,m=a.lgSize,k=a.gSize;if(i.length>=m+k)for(var g=i.length-m,l=0;l0||e>-c)e+=c;e===0&&c==-12&&(e=12);return ob(e,a,d)}}function Sa(b,a){return function(c, -d){var e=c["get"+b](),f=na(a?"SHORT"+b:b);return d[f][e]}}function Vb(b){function a(a){var b;if(b=a.match(c)){var a=new Date(0),f=0,i=0,h=b[8]?a.setUTCFullYear:a.setFullYear,j=b[8]?a.setUTCHours:a.setHours;b[9]&&(f=K(b[9]+b[10]),i=K(b[9]+b[11]));h.call(a,K(b[1]),K(b[2])-1,K(b[3]));j.call(a,K(b[4]||0)-f,K(b[5]||0)-i,K(b[6]||0),K(b[7]||0))}return a}var c=/^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;return function(c,e){var f="",i=[],h,j,e=e|| -"mediumDate",e=b.DATETIME_FORMATS[e]||e;x(c)&&(c=jd.test(c)?K(c):a(c));Za(c)&&(c=new Date(c));if(!qa(c))return c;for(;e;)(j=kd.exec(e))?(i=i.concat(ka.call(j,1)),e=i.pop()):(i.push(e),e=null);o(i,function(a){h=ld[a];f+=h?h(c,b.DATETIME_FORMATS):a.replace(/(^'|'$)/g,"").replace(/''/g,"'")});return f}}function fd(){return function(b){return da(b,!0)}}function gd(){return function(b,a){if(!C(b)&&!x(b))return b;a=K(a);if(x(b))return a?a>=0?b.slice(0,a):b.slice(a,b.length):"";var c=[],d,e;a>b.length?a= -b.length:a<-b.length&&(a=-b.length);a>0?(d=0,e=a):(d=b.length+a,e=b.length);for(;dk?(d.$setValidity("maxlength",!1),s):(d.$setValidity("maxlength",!0),a)};d.$parsers.push(e);d.$formatters.push(e)}}function pb(b,a){b="ngClass"+b;return Y(function(c,d,e){function f(b){if(a=== -!0||c.$index%2===a)j&&b!==j&&i(j),h(b);j=b}function i(a){L(a)&&!C(a)&&(a=$a(a,function(a,b){if(a)return b}));d.removeClass(C(a)?a.join(" "):a)}function h(a){L(a)&&!C(a)&&(a=$a(a,function(a,b){if(a)return b}));a&&d.addClass(C(a)?a.join(" "):a)}var j=s;c.$watch(e[b],f,!0);e.$observe("class",function(){var a=c.$eval(e[b]);f(a,a)});b!=="ngClass"&&c.$watch("$index",function(d,f){var j=d%2;j!==f%2&&(j==a?h(c.$eval(e[b])):i(c.$eval(e[b])))})})}var J=function(b){return x(b)?b.toLowerCase():b},na=function(b){return x(b)? -b.toUpperCase():b},X=K((/msie (\d+)/.exec(J(navigator.userAgent))||[])[1]),v,ca,ka=[].slice,Ya=[].push,Da=Object.prototype.toString,hc=M.angular,Ia=M.angular||(M.angular={}),xa,jb,Z=["0","0","0"];t.$inject=[];pa.$inject=[];jb=X<9?function(b){b=b.nodeName?b:b[0];return b.scopeName&&b.scopeName!="HTML"?na(b.scopeName+":"+b.nodeName):b.nodeName}:function(b){return b.nodeName?b.nodeName:b[0].nodeName};var nc=/[A-Z]/g,md={full:"1.1.4",major:1,minor:1,dot:4,codeName:"quantum-manipulation"},La=P.cache={}, -Ka=P.expando="ng-"+(new Date).getTime(),rc=1,ac=M.document.addEventListener?function(b,a,c){b.addEventListener(a,c,!1)}:function(b,a,c){b.attachEvent("on"+a,c)},ib=M.document.removeEventListener?function(b,a,c){b.removeEventListener(a,c,!1)}:function(b,a,c){b.detachEvent("on"+a,c)},pc=/([\:\-\_]+(.))/g,qc=/^moz([A-Z])/,za=P.prototype={ready:function(b){function a(){c||(c=!0,b())}var c=!1;V.readyState==="complete"?setTimeout(a):(this.bind("DOMContentLoaded",a),P(M).bind("load",a))},toString:function(){var b= -[];o(this,function(a){b.push(""+a)});return"["+b.join(", ")+"]"},eq:function(b){return b>=0?v(this[b]):v(this[this.length+b])},length:0,push:Ya,sort:[].sort,splice:[].splice},Oa={};o("multiple,selected,checked,disabled,readOnly,required,open".split(","),function(b){Oa[J(b)]=b});var Eb={};o("input,select,option,textarea,button,form,details".split(","),function(b){Eb[na(b)]=!0});o({data:zb,inheritedData:Na,scope:function(b){return Na(b,"$scope")},controller:Cb,injector:function(b){return Na(b,"$injector")}, -removeAttr:function(b,a){b.removeAttribute(a)},hasClass:Ma,css:function(b,a,c){a=Ja(a);if(w(c))b.style[a]=c;else{var d;X<=8&&(d=b.currentStyle&&b.currentStyle[a],d===""&&(d="auto"));d=d||b.style[a];X<=8&&(d=d===""?s:d);return d}},attr:function(b,a,c){var d=J(a);if(Oa[d])if(w(c))c?(b[a]=!0,b.setAttribute(a,d)):(b[a]=!1,b.removeAttribute(d));else return b[a]||(b.attributes.getNamedItem(a)||t).specified?d:s;else if(w(c))b.setAttribute(a,c);else if(b.getAttribute)return b=b.getAttribute(a,2),b===null? -s:b},prop:function(b,a,c){if(w(c))b[a]=c;else return b[a]},text:y(X<9?function(b,a){if(b.nodeType==1){if(u(a))return b.innerText;b.innerText=a}else{if(u(a))return b.nodeValue;b.nodeValue=a}}:function(b,a){if(u(a))return b.textContent;b.textContent=a},{$dv:""}),val:function(b,a){if(u(a))return b.value;b.value=a},html:function(b,a){if(u(a))return b.innerHTML;for(var c=0,d=b.childNodes;c":function(a,c,d,e){return d(a,c)>e(a,c)},"<=":function(a,c,d,e){return d(a,c)<=e(a,c)},">=":function(a,c,d,e){return d(a,c)>=e(a, -c)},"&&":function(a,c,d,e){return d(a,c)&&e(a,c)},"||":function(a,c,d,e){return d(a,c)||e(a,c)},"&":function(a,c,d,e){return d(a,c)&e(a,c)},"|":function(a,c,d,e){return e(a,c)(a,c,d(a,c))},"!":function(a,c,d){return!d(a,c)}},Nc={n:"\n",f:"\u000c",r:"\r",t:"\t",v:"\u000b","'":"'",'"':'"'},nb={},Yc=/^(([^:]+):)?\/\/(\w+:{0,1}\w*@)?([\w\.-]*)?(:([0-9]+))?(.*)$/,bd=M.XMLHttpRequest||function(){try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(c){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(d){}throw Error("This browser does not support XMLHttpRequest."); -};Tb.$inject=["$provide"];Ub.$inject=["$locale"];Wb.$inject=["$locale"];var Zb=".",ld={yyyy:O("FullYear",4),yy:O("FullYear",2,0,!0),y:O("FullYear",1),MMMM:Sa("Month"),MMM:Sa("Month",!0),MM:O("Month",2,1),M:O("Month",1,1),dd:O("Date",2),d:O("Date",1),HH:O("Hours",2),H:O("Hours",1),hh:O("Hours",2,-12),h:O("Hours",1,-12),mm:O("Minutes",2),m:O("Minutes",1),ss:O("Seconds",2),s:O("Seconds",1),sss:O("Milliseconds",3),EEEE:Sa("Day"),EEE:Sa("Day",!0),a:function(a,c){return a.getHours()<12?c.AMPMS[0]:c.AMPMS[1]}, -Z:function(a){var a=-1*a.getTimezoneOffset(),c=a>=0?"+":"";c+=ob(Math[a>0?"floor":"ceil"](a/60),2)+ob(Math.abs(a%60),2);return c}},kd=/((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/,jd=/^\d+$/;Vb.$inject=["$locale"];var hd=Q(J),id=Q(na);Xb.$inject=["$parse"];var od=Q({restrict:"E",compile:function(a,c){X<=8&&(!c.href&&!c.name&&c.$set("href",""),a.append(V.createComment("IE fix")));return function(a,c){c.bind("click",function(a){c.attr("href")||a.preventDefault()})}}}), -qb={};o(Oa,function(a,c){var d=aa("ng-"+c);qb[d]=function(){return{priority:100,compile:function(){return function(a,f,i){a.$watch(i[d],function(a){i.$set(c,!!a)})}}}}});o(["src","href"],function(a){var c=aa("ng-"+a);qb[c]=function(){return{priority:99,link:function(d,e,f){f.$observe(c,function(c){c&&(f.$set(a,c),X&&e.prop(a,f[a]))})}}}});var Va={$addControl:t,$removeControl:t,$setValidity:t,$setDirty:t,$setPristine:t};$b.$inject=["$element","$attrs","$scope"];var Ya=function(a){return["$timeout", -function(c){var d={name:"form",restrict:"E",controller:$b,compile:function(){return{pre:function(a,d,i,h){if(!i.action){var j=function(a){a.preventDefault?a.preventDefault():a.returnValue=!1};ac(d[0],"submit",j);d.bind("$destroy",function(){c(function(){ib(d[0],"submit",j)},0,!1)})}var g=d.parent().controller("form"),m=i.name||i.ngForm;m&&(a[m]=h);g&&d.bind("$destroy",function(){g.$removeControl(h);m&&(a[m]=s);y(h,Va)})}}}};return a?y(W(d),{restrict:"EAC"}):d}]},pd=Ya(),qd=Ya(!0),rd=/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/, -sd=/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/,td=/^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/,cc={text:Xa,number:function(a,c,d,e,f,i){Xa(a,c,d,e,f,i);e.$parsers.push(function(a){var c=U(a);return c||td.test(a)?(e.$setValidity("number",!0),a===""?null:c?a:parseFloat(a)):(e.$setValidity("number",!1),s)});e.$formatters.push(function(a){return U(a)?"":""+a});if(d.min){var h=parseFloat(d.min),a=function(a){return!U(a)&&aj?(e.$setValidity("max",!1),s):(e.$setValidity("max",!0),a)};e.$parsers.push(d);e.$formatters.push(d)}e.$formatters.push(function(a){return U(a)||Za(a)?(e.$setValidity("number",!0),a):(e.$setValidity("number",!1),s)})},url:function(a,c,d,e,f,i){Xa(a,c,d,e,f,i);a=function(a){return U(a)||rd.test(a)?(e.$setValidity("url",!0),a):(e.$setValidity("url",!1),s)};e.$formatters.push(a);e.$parsers.push(a)},email:function(a, -c,d,e,f,i){Xa(a,c,d,e,f,i);a=function(a){return U(a)||sd.test(a)?(e.$setValidity("email",!0),a):(e.$setValidity("email",!1),s)};e.$formatters.push(a);e.$parsers.push(a)},radio:function(a,c,d,e){u(d.name)&&c.attr("name",Ea());c.bind("click",function(){c[0].checked&&a.$apply(function(){e.$setViewValue(d.value)})});e.$render=function(){c[0].checked=d.value==e.$viewValue};d.$observe("value",e.$render)},checkbox:function(a,c,d,e){var f=d.ngTrueValue,i=d.ngFalseValue;x(f)||(f=!0);x(i)||(i=!1);c.bind("click", -function(){a.$apply(function(){e.$setViewValue(c[0].checked)})});e.$render=function(){c[0].checked=e.$viewValue};e.$formatters.push(function(a){return a===f});e.$parsers.push(function(a){return a?f:i})},hidden:t,button:t,submit:t,reset:t},dc=["$browser","$sniffer",function(a,c){return{restrict:"E",require:"?ngModel",link:function(d,e,f,i){i&&(cc[J(f.type)]||cc.text)(d,e,f,i,c,a)}}}],Ua="ng-valid",Ta="ng-invalid",oa="ng-pristine",Wa="ng-dirty",ud=["$scope","$exceptionHandler","$attrs","$element","$parse", -function(a,c,d,e,f){function i(a,c){c=c?"-"+db(c,"-"):"";e.removeClass((a?Ta:Ua)+c).addClass((a?Ua:Ta)+c)}this.$modelValue=this.$viewValue=Number.NaN;this.$parsers=[];this.$formatters=[];this.$viewChangeListeners=[];this.$pristine=!0;this.$dirty=!1;this.$valid=!0;this.$invalid=!1;this.$name=d.name;var h=f(d.ngModel),j=h.assign;if(!j)throw Error(Ib+d.ngModel+" ("+ta(e)+")");this.$render=t;var g=e.inheritedData("$formController")||Va,m=0,k=this.$error={};e.addClass(oa);i(!0);this.$setValidity=function(a, -c){if(k[a]!==!c){if(c){if(k[a]&&m--,!m)i(!0),this.$valid=!0,this.$invalid=!1}else i(!1),this.$invalid=!0,this.$valid=!1,m++;k[a]=!c;i(c,a);g.$setValidity(a,c,this)}};this.$setPristine=function(){this.$dirty=!1;this.$pristine=!0;e.removeClass(Wa).addClass(oa)};this.$setViewValue=function(d){this.$viewValue=d;if(this.$pristine)this.$dirty=!0,this.$pristine=!1,e.removeClass(oa).addClass(Wa),g.$setDirty();o(this.$parsers,function(a){d=a(d)});if(this.$modelValue!==d)this.$modelValue=d,j(a,d),o(this.$viewChangeListeners, -function(a){try{a()}catch(d){c(d)}})};var l=this;a.$watch(function(){var c=h(a);if(l.$modelValue!==c){var d=l.$formatters,e=d.length;for(l.$modelValue=c;e--;)c=d[e](c);if(l.$viewValue!==c)l.$viewValue=c,l.$render()}})}],vd=function(){return{require:["ngModel","^?form"],controller:ud,link:function(a,c,d,e){var f=e[0],i=e[1]||Va;i.$addControl(f);c.bind("$destroy",function(){i.$removeControl(f)})}}},wd=Q({require:"ngModel",link:function(a,c,d,e){e.$viewChangeListeners.push(function(){a.$eval(d.ngChange)})}}), -ec=function(){return{require:"?ngModel",link:function(a,c,d,e){if(e){d.required=!0;var f=function(a){if(d.required&&(U(a)||a===!1))e.$setValidity("required",!1);else return e.$setValidity("required",!0),a};e.$formatters.push(f);e.$parsers.unshift(f);d.$observe("required",function(){f(e.$viewValue)})}}}},xd=function(){return{require:"ngModel",link:function(a,c,d,e){var f=(a=/\/(.*)\//.exec(d.ngList))&&RegExp(a[1])||d.ngList||",";e.$parsers.push(function(a){var c=[];a&&o(a.split(f),function(a){a&&c.push(S(a))}); -return c});e.$formatters.push(function(a){return C(a)?a.join(", "):s})}}},yd=/^(true|false|\d+)$/,zd=function(){return{priority:100,compile:function(a,c){return yd.test(c.ngValue)?function(a,c,f){f.$set("value",a.$eval(f.ngValue))}:function(a,c,f){a.$watch(f.ngValue,function(a){f.$set("value",a,!1)})}}}},Ad=Y(function(a,c,d){c.addClass("ng-binding").data("$binding",d.ngBind);a.$watch(d.ngBind,function(a){c.text(a==s?"":a)})}),Bd=["$interpolate",function(a){return function(c,d,e){c=a(d.attr(e.$attr.ngBindTemplate)); -d.addClass("ng-binding").data("$binding",c);e.$observe("ngBindTemplate",function(a){d.text(a)})}}],Cd=[function(){return function(a,c,d){c.addClass("ng-binding").data("$binding",d.ngBindHtmlUnsafe);a.$watch(d.ngBindHtmlUnsafe,function(a){c.html(a||"")})}}],Dd=pb("",!0),Ed=pb("Odd",0),Fd=pb("Even",1),Gd=Y({compile:function(a,c){c.$set("ngCloak",s);a.removeClass("ng-cloak")}}),Hd=[function(){return{scope:!0,controller:"@"}}],Id=["$sniffer",function(a){return{priority:1E3,compile:function(){a.csp=!0}}}], -fc={};o("click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress".split(" "),function(a){var c=aa("ng-"+a);fc[c]=["$parse",function(d){return function(e,f,i){var h=d(i[c]);f.bind(J(a),function(a){e.$apply(function(){h(e,{$event:a})})})}}]});var Jd=Y(function(a,c,d){c.bind("submit",function(){a.$apply(d.ngSubmit)})}),Kd=["$http","$templateCache","$anchorScroll","$compile","$animator",function(a,c,d,e,f){return{restrict:"ECA",terminal:!0,compile:function(i, -h){var j=h.ngInclude||h.src,g=h.onload||"",m=h.autoscroll;return function(h,i,o){var n=f(h,o),s=0,r,p=function(){r&&(r.$destroy(),r=null);n.leave(i.contents(),i)};h.$watch(j,function(f){var j=++s;f?a.get(f,{cache:c}).success(function(a){j===s&&(r&&r.$destroy(),r=h.$new(),n.leave(i.contents(),i),a=v("
").html(a).contents(),n.enter(a,i),e(a)(r),w(m)&&(!m||h.$eval(m))&&d(),r.$emit("$includeContentLoaded"),h.$eval(g))}).error(function(){j===s&&p()}):p()})}}}}],Ld=Y({compile:function(){return{pre:function(a, -c,d){a.$eval(d.ngInit)}}}}),Md=Y({terminal:!0,priority:1E3}),Nd=["$locale","$interpolate",function(a,c){var d=/{}/g;return{restrict:"EA",link:function(e,f,i){var h=i.count,j=f.attr(i.$attr.when),g=i.offset||0,m=e.$eval(j),k={},l=c.startSymbol(),q=c.endSymbol();o(m,function(a,e){k[e]=c(a.replace(d,l+h+"-"+g+q))});e.$watch(function(){var c=parseFloat(e.$eval(h));return isNaN(c)?"":(m[c]||(c=a.pluralCat(c-g)),k[c](e,f,!0))},function(a){f.text(a)})}}}],Od=["$parse","$animator",function(a,c){return{transclude:"element", -priority:1E3,terminal:!0,compile:function(d,e,f){return function(d,e,j){var g=c(d,j),m=j.ngRepeat,k=m.match(/^\s*(.+)\s+in\s+(.*?)\s*(\s+track\s+by\s+(.+)\s*)?$/),l,q,n,s,r,p={$id:la};if(!k)throw Error("Expected ngRepeat in form of '_item_ in _collection_[ track by _id_]' but got '"+m+"'.");j=k[1];n=k[2];(k=k[4])?(l=a(k),q=function(a,c,e){r&&(p[r]=a);p[s]=c;p.$index=e;return l(d,p)}):q=function(a,c){return la(c)};k=j.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/);if(!k)throw Error("'item' in 'item in collection' should be identifier or (key, value) but got '"+ -j+"'.");s=k[3]||k[1];r=k[2];var y={};d.$watchCollection(n,function(a){var c,j,k=e,l,n={},p,t,v,z,w,u,x=[];if(C(a))w=a;else{w=[];for(v in a)a.hasOwnProperty(v)&&v.charAt(0)!="$"&&w.push(v);w.sort()}p=w.length;j=x.length=w.length;for(c=0;c
").html(k).contents(),c);var k=f(c.contents()),m=d.current;l=m.scope=a.$new();if(m.controller)h.$scope=l,h=i(m.controller,h),c.children().data("$ngControllerController",h);k(l);l.$emit("$viewContentLoaded");l.$eval(o);e()}else n.leave(c.contents(),c),l&&(l.$destroy(),l=null)}var l,o=m.onload||"",n=h(a,m);a.$on("$routeChangeSuccess",k);k()}}}],Xd=["$templateCache",function(a){return{restrict:"E",terminal:!0,compile:function(c, -d){d.type=="text/ng-template"&&a.put(d.id,c[0].text)}}}],Yd=Q({terminal:!0}),Zd=["$compile","$parse",function(a,c){var d=/^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w\d]*)|(?:\(\s*([\$\w][\$\w\d]*)\s*,\s*([\$\w][\$\w\d]*)\s*\)))\s+in\s+(.*)$/,e={$setViewValue:t};return{restrict:"E",require:["select","?ngModel"],controller:["$element","$scope","$attrs",function(a,c,d){var j=this,g={},m=e,k;j.databound=d.ngModel;j.init=function(a,c,d){m=a;k=d};j.addOption=function(c){g[c]= -!0;m.$viewValue==c&&(a.val(c),k.parent()&&k.remove())};j.removeOption=function(a){this.hasOption(a)&&(delete g[a],m.$viewValue==a&&this.renderUnknownOption(a))};j.renderUnknownOption=function(c){c="? "+la(c)+" ?";k.val(c);a.prepend(k);a.val(c);k.prop("selected",!0)};j.hasOption=function(a){return g.hasOwnProperty(a)};c.$on("$destroy",function(){j.renderUnknownOption=t})}],link:function(e,i,h,j){function g(a,c,d,e){d.$render=function(){var a=d.$viewValue;e.hasOption(a)?(x.parent()&&x.remove(),c.val(a), -a===""&&p.prop("selected",!0)):u(a)&&p?c.val(""):e.renderUnknownOption(a)};c.bind("change",function(){a.$apply(function(){x.parent()&&x.remove();d.$setViewValue(c.val())})})}function m(a,c,d){var e;d.$render=function(){var a=new Pa(d.$viewValue);o(c.find("option"),function(c){c.selected=w(a.get(c.value))})};a.$watch(function(){ja(e,d.$viewValue)||(e=W(d.$viewValue),d.$render())});c.bind("change",function(){a.$apply(function(){var a=[];o(c.find("option"),function(c){c.selected&&a.push(c.value)});d.$setViewValue(a)})})} -function k(e,f,h){function g(){var a={"":[]},c=[""],d,i,t,v,u;t=h.$modelValue;v=p(e)||[];var w=l?rb(v):v,z,x,A;x={};u=!1;var B,C;if(n)u=new Pa(t);else if(t===null||r)a[""].push({selected:t===null,id:"",label:""}),u=!0;for(A=0;z=w.length,AA;)v.pop().element.remove()}for(;q.length>x;)q.pop()[0].element.remove()}var i;if(!(i=t.match(d)))throw Error("Expected ngOptions in form of '_select_ (as _label_)? for (_key_,)?_value_ in _collection_' but got '"+t+"'.");var j=c(i[2]||i[1]),k=i[4]||i[6],l=i[5],m=c(i[3]||""),o=c(i[2]?i[1]:k),p=c(i[7]),q=[[{element:f,label:""}]];r&&(a(r)(e),r.removeClass("ng-scope"),r.remove());f.html("");f.bind("change", -function(){e.$apply(function(){var a,c=p(e)||[],d={},g,i,j,m,r,t;if(n){i=[];m=0;for(t=q.length;m@charset "UTF-8";[ng\\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak{display:none;}ng\\:form{display:block;}'); diff --git a/js/_saved/angular-cookies.js b/js/_saved/angular-cookies.js deleted file mode 100644 index f9eccc1..0000000 --- a/js/_saved/angular-cookies.js +++ /dev/null @@ -1,184 +0,0 @@ -/** - * @license AngularJS v1.1.4 - * (c) 2010-2012 Google, Inc. http://angularjs.org - * License: MIT - */ -(function(window, angular, undefined) { -'use strict'; - -/** - * @ngdoc overview - * @name ngCookies - */ - - -angular.module('ngCookies', ['ng']). - /** - * @ngdoc object - * @name ngCookies.$cookies - * @requires $browser - * - * @description - * Provides read/write access to browser's cookies. - * - * Only a simple Object is exposed and by adding or removing properties to/from - * this object, new cookies are created/deleted at the end of current $eval. - * - * @example - - - - - - */ - factory('$cookies', ['$rootScope', '$browser', function ($rootScope, $browser) { - var cookies = {}, - lastCookies = {}, - lastBrowserCookies, - runEval = false, - copy = angular.copy, - isUndefined = angular.isUndefined; - - //creates a poller fn that copies all cookies from the $browser to service & inits the service - $browser.addPollFn(function() { - var currentCookies = $browser.cookies(); - if (lastBrowserCookies != currentCookies) { //relies on browser.cookies() impl - lastBrowserCookies = currentCookies; - copy(currentCookies, lastCookies); - copy(currentCookies, cookies); - if (runEval) $rootScope.$apply(); - } - })(); - - runEval = true; - - //at the end of each eval, push cookies - //TODO: this should happen before the "delayed" watches fire, because if some cookies are not - // strings or browser refuses to store some cookies, we update the model in the push fn. - $rootScope.$watch(push); - - return cookies; - - - /** - * Pushes all the cookies from the service to the browser and verifies if all cookies were stored. - */ - function push() { - var name, - value, - browserCookies, - updated; - - //delete any cookies deleted in $cookies - for (name in lastCookies) { - if (isUndefined(cookies[name])) { - $browser.cookies(name, undefined); - } - } - - //update all cookies updated in $cookies - for(name in cookies) { - value = cookies[name]; - if (!angular.isString(value)) { - if (angular.isDefined(lastCookies[name])) { - cookies[name] = lastCookies[name]; - } else { - delete cookies[name]; - } - } else if (value !== lastCookies[name]) { - $browser.cookies(name, value); - updated = true; - } - } - - //verify what was actually stored - if (updated){ - updated = false; - browserCookies = $browser.cookies(); - - for (name in cookies) { - if (cookies[name] !== browserCookies[name]) { - //delete or reset all cookies that the browser dropped from $cookies - if (isUndefined(browserCookies[name])) { - delete cookies[name]; - } else { - cookies[name] = browserCookies[name]; - } - updated = true; - } - } - } - } - }]). - - - /** - * @ngdoc object - * @name ngCookies.$cookieStore - * @requires $cookies - * - * @description - * Provides a key-value (string-object) storage, that is backed by session cookies. - * Objects put or retrieved from this storage are automatically serialized or - * deserialized by angular's toJson/fromJson. - * @example - */ - factory('$cookieStore', ['$cookies', function($cookies) { - - return { - /** - * @ngdoc method - * @name ngCookies.$cookieStore#get - * @methodOf ngCookies.$cookieStore - * - * @description - * Returns the value of given cookie key - * - * @param {string} key Id to use for lookup. - * @returns {Object} Deserialized cookie value. - */ - get: function(key) { - return angular.fromJson($cookies[key]); - }, - - /** - * @ngdoc method - * @name ngCookies.$cookieStore#put - * @methodOf ngCookies.$cookieStore - * - * @description - * Sets a value for given cookie key - * - * @param {string} key Id for the `value`. - * @param {Object} value Value to be stored. - */ - put: function(key, value) { - $cookies[key] = angular.toJson(value); - }, - - /** - * @ngdoc method - * @name ngCookies.$cookieStore#remove - * @methodOf ngCookies.$cookieStore - * - * @description - * Remove given cookie - * - * @param {string} key Id of the key-value pair to delete. - */ - remove: function(key) { - delete $cookies[key]; - } - }; - - }]); - - -})(window, window.angular); diff --git a/js/_saved/angular-cookies.min.js b/js/_saved/angular-cookies.min.js deleted file mode 100644 index b8f78ab..0000000 --- a/js/_saved/angular-cookies.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/* - AngularJS v1.1.4 - (c) 2010-2012 Google, Inc. http://angularjs.org - License: MIT -*/ -(function(m,f,l){'use strict';f.module("ngCookies",["ng"]).factory("$cookies",["$rootScope","$browser",function(d,c){var b={},g={},h,i=!1,j=f.copy,k=f.isUndefined;c.addPollFn(function(){var a=c.cookies();h!=a&&(h=a,j(a,g),j(a,b),i&&d.$apply())})();i=!0;d.$watch(function(){var a,e,d;for(a in g)k(b[a])&&c.cookies(a,l);for(a in b)e=b[a],f.isString(e)?e!==g[a]&&(c.cookies(a,e),d=!0):f.isDefined(g[a])?b[a]=g[a]:delete b[a];if(d)for(a in e=c.cookies(),b)b[a]!==e[a]&&(k(e[a])?delete b[a]:b[a]=e[a])});return b}]).factory("$cookieStore", -["$cookies",function(d){return{get:function(c){return f.fromJson(d[c])},put:function(c,b){d[c]=f.toJson(b)},remove:function(c){delete d[c]}}}])})(window,window.angular); diff --git a/js/_saved/angular-resource.min.js b/js/_saved/angular-resource.min.js deleted file mode 100644 index 024dbfd..0000000 --- a/js/_saved/angular-resource.min.js +++ /dev/null @@ -1,11 +0,0 @@ -/* - AngularJS v1.1.4 - (c) 2010-2012 Google, Inc. http://angularjs.org - License: MIT -*/ -(function(B,f,x){'use strict';f.module("ngResource",["ng"]).factory("$resource",["$http","$parse",function(y,z){function v(g,c){this.template=g+"#";this.defaults=c||{};this.urlParams={}}function w(g,c,d){function j(e,b){var p={},b=q({},c,b);k(b,function(a,b){l(a)&&(a=a());var h;a.charAt&&a.charAt(0)=="@"?(h=a.substr(1),h=z(h)(e)):h=a;p[b]=h});return p}function b(b){u(b||{},this)}var m=new v(g),d=q({},A,d);k(d,function(e,c){e.method=f.uppercase(e.method);var p=e.method=="POST"||e.method=="PUT"||e.method== -"PATCH";b[c]=function(a,c,h,g){function f(){i.$resolved=!0}var n={},d,o=r,s=null;switch(arguments.length){case 4:s=g,o=h;case 3:case 2:if(l(c)){if(l(a)){o=a;s=c;break}o=c;s=h}else{n=a;d=c;o=h;break}case 1:l(a)?o=a:p?d=a:n=a;break;case 0:break;default:throw"Expected between 0-4 arguments [params, data, success, error], got "+arguments.length+" arguments.";}var i=this instanceof b?this:e.isArray?[]:new b(d),t={};k(e,function(a,b){b!="params"&&b!="isArray"&&(t[b]=u(a))});t.data=d;m.setUrlParams(t,q({}, -j(d,e.params||{}),n),e.url);n=y(t);i.$resolved=!1;n.then(f,f);i.$then=n.then(function(a){var c=a.data,h=i.$then,d=i.$resolved;if(c)e.isArray?(i.length=0,k(c,function(a){i.push(new b(a))})):(u(c,i),i.$then=h,i.$resolved=d);(o||r)(i,a.headers);a.resource=i;return a},s).then;return i};b.prototype["$"+c]=function(a,e,h){var d=j(this),f=r,g;switch(arguments.length){case 3:d=a;f=e;g=h;break;case 2:case 1:l(a)?(f=a,g=e):(d=a,f=e||r);case 0:break;default:throw"Expected between 1-3 arguments [params, success, error], got "+ -arguments.length+" arguments.";}b[c].call(this,d,p?this:x,f,g)}});b.bind=function(b){return w(g,q({},c,b),d)};return b}var A={get:{method:"GET"},save:{method:"POST"},query:{method:"GET",isArray:!0},remove:{method:"DELETE"},"delete":{method:"DELETE"}},r=f.noop,k=f.forEach,q=f.extend,u=f.copy,l=f.isFunction;v.prototype={setUrlParams:function(g,c,d){var j=this,b=d||j.template,m,e,l=j.urlParams={};k(b.split(/\W/),function(c){c&&RegExp("(^|[^\\\\]):"+c+"(\\W|$)").test(b)&&(l[c]=!0)});b=b.replace(/\\:/g, -":");c=c||{};k(j.urlParams,function(d,a){m=c.hasOwnProperty(a)?c[a]:j.defaults[a];f.isDefined(m)&&m!==null?(e=encodeURIComponent(m).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"%20").replace(/%26/gi,"&").replace(/%3D/gi,"=").replace(/%2B/gi,"+"),b=b.replace(RegExp(":"+a+"(\\W|$)","g"),e+"$1")):b=b.replace(RegExp("(/?):"+a+"(\\W|$)","g"),function(a,b,c){return c.charAt(0)=="/"?c:b+c})});g.url=b.replace(/\/?#$/,"").replace(/\/*$/,"");k(c,function(b, -a){if(!j.urlParams[a])g.params=g.params||{},g.params[a]=b})}};return w}])})(window,window.angular); diff --git a/js/_saved/angular-sanitize.min.js b/js/_saved/angular-sanitize.min.js deleted file mode 100644 index 6f898f4..0000000 --- a/js/_saved/angular-sanitize.min.js +++ /dev/null @@ -1,13 +0,0 @@ -/* - AngularJS v1.1.4 - (c) 2010-2012 Google, Inc. http://angularjs.org - License: MIT -*/ -(function(I,h){'use strict';function i(a){var d={},a=a.split(","),c;for(c=0;c=0;c--)if(e[c]==b)break;if(c>=0){for(g=e.length-1;g>=c;g--)d.end&&d.end(e[g]);e.length= -c}}var b,f,e=[],j=a;for(e.last=function(){return e[e.length-1]};a;){f=!0;if(!e.last()||!q[e.last()]){if(a.indexOf("<\!--")===0)b=a.indexOf("--\>"),b>=0&&(d.comment&&d.comment(a.substring(4,b)),a=a.substring(b+3),f=!1);else if(B.test(a)){if(b=a.match(r))a=a.substring(b[0].length),b[0].replace(r,g),f=!1}else if(C.test(a)&&(b=a.match(s)))a=a.substring(b[0].length),b[0].replace(s,c),f=!1;f&&(b=a.indexOf("<"),f=b<0?a:a.substring(0,b),a=b<0?"":a.substring(b),d.chars&&d.chars(k(f)))}else a=a.replace(RegExp("(.*)<\\s*\\/\\s*"+ -e.last()+"[^>]*>","i"),function(a,b){b=b.replace(D,"$1").replace(E,"$1");d.chars&&d.chars(k(b));return""}),g("",e.last());if(a==j)throw"Parse Error: "+a;j=a}g()}function k(a){l.innerHTML=a.replace(//g,">")}function u(a){var d=!1,c=h.bind(a,a.push);return{start:function(a,b,f){a=h.lowercase(a);!d&&q[a]&&(d=a);!d&&v[a]== -!0&&(c("<"),c(a),h.forEach(b,function(a,b){var d=h.lowercase(b);if(G[d]==!0&&(w[d]!==!0||a.match(H)))c(" "),c(b),c('="'),c(t(a)),c('"')}),c(f?"/>":">"))},end:function(a){a=h.lowercase(a);!d&&v[a]==!0&&(c(""));a==d&&(d=!1)},chars:function(a){d||c(t(a))}}}var s=/^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)\s*>/,r=/^<\s*\/\s*([\w:-]+)[^>]*>/,A=/([\w:-]+)(?:\s*=\s*(?:(?:"((?:[^"])*)")|(?:'((?:[^'])*)')|([^>\s]+)))?/g,C=/^/g, -E=//g,H=/^((ftp|https?):\/\/|mailto:|tel:|#)/,F=/([^\#-~| |!])/g,p=i("area,br,col,hr,img,wbr"),x=i("colgroup,dd,dt,li,p,tbody,td,tfoot,th,thead,tr"),y=i("rp,rt"),o=h.extend({},y,x),m=h.extend({},x,i("address,article,aside,blockquote,caption,center,del,dir,div,dl,figure,figcaption,footer,h1,h2,h3,h4,h5,h6,header,hgroup,hr,ins,map,menu,nav,ol,pre,script,section,table,ul")),n=h.extend({},y,i("a,abbr,acronym,b,bdi,bdo,big,br,cite,code,del,dfn,em,font,i,img,ins,kbd,label,map,mark,q,ruby,rp,rt,s,samp,small,span,strike,strong,sub,sup,time,tt,u,var")), -q=i("script,style"),v=h.extend({},p,m,n,o),w=i("background,cite,href,longdesc,src,usemap"),G=h.extend({},w,i("abbr,align,alt,axis,bgcolor,border,cellpadding,cellspacing,class,clear,color,cols,colspan,compact,coords,dir,face,headers,height,hreflang,hspace,ismap,lang,language,nohref,nowrap,rel,rev,rows,rowspan,rules,scope,scrolling,shape,span,start,summary,target,title,type,valign,value,vspace,width")),l=document.createElement("pre");h.module("ngSanitize",[]).value("$sanitize",function(a){var d=[]; -z(a,u(d));return d.join("")});h.module("ngSanitize").directive("ngBindHtml",["$sanitize",function(a){return function(d,c,g){c.addClass("ng-binding").data("$binding",g.ngBindHtml);d.$watch(g.ngBindHtml,function(b){b=a(b);c.html(b||"")})}}]);h.module("ngSanitize").filter("linky",function(){var a=/((ftp|https?):\/\/|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s\.\;\,\(\)\{\}\<\>]/,d=/^mailto:/;return function(c,g){if(!c)return c;var b,f=c,e=[],j=u(e),i,k,l={};if(h.isDefined(g))l.target=g;for(;b=f.match(a);)i= -b[0],b[2]==b[3]&&(i="mailto:"+i),k=b.index,j.chars(f.substr(0,k)),l.href=i,j.start("a",l),j.chars(b[0].replace(d,"")),j.end("a"),f=f.substring(k+b[0].length);j.chars(f);return e.join("")}})})(window,window.angular); diff --git a/js/_saved/archiveViewModel.js b/js/_saved/archiveViewModel.js deleted file mode 100644 index 560cfbb..0000000 --- a/js/_saved/archiveViewModel.js +++ /dev/null @@ -1,43 +0,0 @@ -define(['knockout', 'postbox', 'mapping', 'global', 'utils', 'model', 'player', 'jquery.layout', 'jquery.dateFormat'], function (ko, postbox, mapping, global, utils, model, player) { - return function () { - - self.selectSong = function (data, event) { - if (self.selectedSongs.indexOf(this) >= 0) { - self.selectedSongs.remove(this); - this.selected(false); - } else { - self.selectedSongs.push(this); - this.selected(true); - } - } - self.addSongsToQueue = function (data, event) { - ko.utils.arrayForEach(self.selectedSongs(), function (item) { - self.queue.push(item); - item.selected(false); - }); - utils.updateMessage(self.selectedSongs().length + ' Song(s) Added to Queue', true); - } - - - - self.openLink = function (data, event) { - return true; - } - - - - - self.selectAll = function (data, event) { - ko.utils.arrayForEach(self.song(), function (item) { - self.selectedSongs.push(item); - item.selected(true); - }); - } - self.selectNone = function (data, event) { - ko.utils.arrayForEach(self.song(), function (item) { - self.selectedSongs([]); - item.selected(false); - }); - } - } -}); \ No newline at end of file diff --git a/js/_saved/demo.html b/js/_saved/demo.html deleted file mode 100644 index 8c2aa44..0000000 --- a/js/_saved/demo.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - Contact Manager - - -

AngularJS Contact Manager

- [index] -
- - - - - diff --git a/js/_saved/saved.html b/js/_saved/saved.html deleted file mode 100644 index ff3151e..0000000 --- a/js/_saved/saved.html +++ /dev/null @@ -1,592 +0,0 @@ - - - - - Jamstash - - - - - - - - - - -
- -
- -
-
- - -
- - -
-
- All - None - + Queue - + Playlist - -
-
-
-
-
-
-
Library
-
- -
    -
  • Auto Albums
  • - -
  • -
    - - -
    -
  • - -
- -
- A-Z -
- -
    -
  • -
      -
    • -
    -
-
-
-
-
Playlists
-
-
-
Podcasts
-
-
-
Archive.org
-
-
-
-
-
-
-
-
    -
    -
    -
    -
    -
    - - -
    -
    -
    - -
    -
    - All - None - + Queue -
    -
    -
    -
    -
    -
      -
    • -
    -
    -
    -
      -
    • - - - - -
    • -
    -
      -
      -
      -
        -
        -
        -
        -
        -
        - - - - - - - -
        - -
        -
          -
        • -
          - -
          -
          -
          -
          -
          - -
          -
          -
          -
          -
          -
        • -
        -
        -
        -
        -
        - - -
        -
        - - + New -
        - -
        -
        -
        -
        -
        • Auto Playlists
        -
          -
          • Folder Playlists
          -
            -
            • Saved Playlists
            -
              -
              -
              -
              - - - -
              -
              -
              -
              0 song(s), 00:00:00 total time
              -
              - - - -
              -
              - -
              -
              ***Opens new window to the video URL... -
              -
              -
              - - - -
              -
              -
              -
              -
              -
              - - -
              - -
              -
              -
              -
              -
              -

              Login

              -
              -
              -
              -
              -
              -
              - -
              -

              -

              Archive.org Settings

              -
              -
              -
              - Launch Welcome -

              Welcome

              -
              -
              -

              Options

              -
              -
              -
              -
              -
              - -
              -
              -
              -
              -
              -
              -
              -
              -
              -
              - General -
              - -
              -
              - -
              -
              - -
              -
              - -
              -
              -
              - Advanced -
              - -
              -
              - -
              -
              - -
              -
              -
              - HTML5 [Beta] - Notifications
              -
              -
              - -
              -
              - -
              - Local Storage
              -
              -
              - -
              -
              -
              -
              -
              -
              *All settings will be automatically saved
              -
              -
              -

              Tips

              -
                -
              • Click the Notification to quickly Skip the Song
              • -
              • Click on a song to play the rest of the album
              • -
              -

              Keyboard Shortcuts

              -
                - -
              • [a-z] Use to Quickly Browse to an Artist
              • -
              • Home Scroll to Top of Artist List
              • -
              • Spacebar Play/Pause
              • -
              • Next Track
              • -
              • Previous Track
              • -
              • -/_ Volume Down =/+ Volume Up
              • -
              • Media Keys via Sway.fm Unified Music Media Keys
              • -
              - -
              -
              -
              -

              Change Log

              -
                -
              • - - - -
              • -
              - Show More -
              -
              -
              -

              Links

              - -

              Thanks

              - -
              -
              -
              -
              - - - -
              - -
              -
              -
              -
              - - - - -
              -
              - -
              -
                -
              • -
              • -
              • -
              • - - - - - -
              • -
              -
              -
              -
              -
              -
              - -
              -
              -
              -
              -
              -
              -
              00:00/00:00
              -
              -
              -
              -
              -
              -
              -
              -
              - - - - - diff --git a/js/_saved/subsonicViewModel.js b/js/_saved/subsonicViewModel.js deleted file mode 100644 index 7761fd2..0000000 --- a/js/_saved/subsonicViewModel.js +++ /dev/null @@ -1,190 +0,0 @@ -define(['knockout', 'postbox', 'mapping', 'global', 'utils', 'model', 'player', 'subsonic', 'jquery.scrollTo', 'jquery.layout', 'jquery.dateFormat'], function (ko, postbox, mapping, global, utils, model, player, subsonic) { - return function () { - var self = this; - - - self.settings = global.settings; - self.queue = ko.observableArray([]).syncWith("queue", true); - //self.layoutSubsonic = ko.observable().syncWith("layoutSubsonic"); - //self.layoutArchive = ko.observable().syncWith("layoutArchive"); - - - self.addFromPlayedToQueue = function (data, event) { - var i = self.song.indexOf(this); - var count = 0; - ko.utils.arrayForEach(self.song.slice(i, self.song().length), function (item) { - self.queue.push(item); - //item.selected(true); - count++; - }); - player.nextTrack(); - //self.selectedSongs([]); - //self.selectNone(); - utils.updateMessage(count + ' Song(s) Added to Queue', true); - } - - - self.albumMapping = { - create: function (options) { - var album = options.data; - var coverart, starred; - if (typeof album.coverArt != 'undefined') { - coverart = self.settings.BaseURL() + '/getCoverArt.view?' + self.settings.BaseParams() + '&size=50&id=' + album.coverArt; - } - if (typeof album.starred !== 'undefined') { starred = true; } else { starred = false; } - return new model.Album(album.id, album.parent, album.album, album.artist, coverart, $.format.date(new Date(album.created), "yyyy-MM-dd h:mm a"), starred, '', ''); - } - } - - - - - - // Referenced Functions - self.getRandomSongs = function (action, genre, folder) { return subsonic.getRandomSongs(action, genre, folder); } - self.updateFavorite = function (data, event) { return subsonic.updateFavorite(data, event); } - - - /* Start Archive.org */ - self.getArchiveArtists = function (data) { - var map = { - create: function (options) { - //return new model.Artist('', options.data); - return new model.Album(options.data, null, options.data, null, '', null, false, '', ''); - } - }; - mapping.fromJS(self.settings.SavedCollections().split(","), map, self.album); - }; - self.getArchiveAlbums = function (from) { - var id, name; - if (from == 'collection') { - self.selectedArtist(this); - id = this.id(); - name = this.name(); - } else { - id = self.selectedArtist().id(); - name = self.selectedArtist().name(); - } - var map = { - create: function (options) { - var song = options.data; - var coverart, starred; - var url = self.archiveUrl + 'details/' + song.identifier; - coverart = 'images/albumdefault_50.jpg'; - if (parseInt(song.avg_rating) == 5) { starred = true; } else { starred = false; } - //var description = 'Details
              '; - var description = 'Source: ' + song.source + '
              '; - description += 'Date: ' + song.date + '
              '; - description += typeof song.publisher != 'undefined' ? 'Transferer: ' + song.publisher + '
              ' : ''; - description += typeof song.avg_rating != 'undefined' ? 'Rating: ' + song.avg_rating + '
              ' : ''; - description += 'Downloads: ' + song.downloads + '
              '; - //description += typeof song.description == 'undefined' ? '' : song.description.replace("\n", "
              "); - return new model.Album(song.identifier, null, song.title, null, coverart, $.format.date(new Date(song.publicdate), "yyyy-MM-dd h:mm a"), starred, description, url); - } - } - //var url = self.settings.BaseURL() + 'advancedsearch.php?q=collection%3A%28GreenskyBluegrass%29%20AND%20format%3A%28mp3%29&fl%5B%5D=avg_rating&fl%5B%5D=collection&fl%5B%5D=date&fl%5B%5D=description&fl%5B%5D=downloads&fl%5B%5D=headerImage&fl%5B%5D=identifier&fl%5B%5D=publicdate&fl%5B%5D=source&fl%5B%5D=subject&fl%5B%5D=title&format=mp3&sort%5B%5D=addeddate+desc&rows=50&page=1&output=json'; - var url = self.archiveUrl + 'advancedsearch.php?q=collection:(' + name + ') AND format:(MP3)'; - if (self.selectedSource()) { - url += ' AND source:(' + self.selectedSource() + ')'; - } - if (self.selectedYear()) { - if (parseInt(self.selectedYear())) { - url += ' AND year:(' + self.selectedYear() + ')'; - } - } - if (self.selectedDescription()) { - url += ' AND description:(' + self.selectedDescription() + ')'; - } - url += '&fl[]=avg_rating,collection,date,description,downloads,headerImage,identifier,publisher,publicdate,source,subject,title,year'; - if (self.selectedArchiveAlbumSort()) { - url += '&sort[]=' + self.selectedArchiveAlbumSort() - } - url += '&rows=50&page=1&output=json'; - $.ajax({ - url: url, - method: 'GET', - dataType: self.protocol, - timeout: 10000, - success: function (data) { - var items = []; - if (data["response"].docs.length > 0) { - items = data["response"].docs; - //alert(JSON.stringify(data["response"])); - mapping.fromJS(items, map, self.album); - } else { - utils.updateMessage("0 records returned", true); - } - }, - error: function () { - alert('Archive.org service down :('); - } - }); - }; - - - - - - - - - // Init for page load - if (utils.getValue('SubsonicAccordion')) { - var id = utils.getValue('SubsonicAccordion'); - self.toggleAccordion(id); - } - if (settings.Server() != '' && settings.Username() != '' && settings.Password() != '') { - self.ping(); - self.getMusicFolders(); - self.getArtists(); - } - - return { - index: self.index, - shortcut: self.shortcut, - album: self.album, - song: self.song, - templateToUse: self.templateToUse, - selectedArtist: self.selectedArtist, - selectedAlbum: self.selectedAlbum, - selectedPlaylist: self.selectedPlaylist, - selectedSongs: self.selectedSongs, - selectSong: self.selectSong, - addSongsToQueue: self.addSongsToQueue, - addFromPlayedToQueue: self.addFromPlayedToQueue, - getArtists: self.getArtists, - AutoAlbums: self.AutoAlbums, - selectedAutoAlbum: self.selectedAutoAlbum, - getAlbums: self.getAlbums, - offset: self.offset, - getAlbumListBy: self.getAlbumListBy, - getSongs: self.getSongs, - getRandomSongs: self.getRandomSongs, - search: self.search, - updateFavorite: self.updateFavorite, - MusicFolders: self.MusicFolders, - selectedMusicFolders: self.selectedMusicFolders, - getMusicFolders: self.getMusicFolders, - scrollToTop: self.scrollToTop, - scrollToIndex: self.scrollToIndex, - selectAll: self.selectAll, - selectNone: self.selectNone, - rescanLibrary: self.rescanLibrary, - toggleAZ: self.toggleAZ, - selectedSubsonicAlbumSort: self.selectedSubsonicAlbumSort, - SubsonicSort: self.SubsonicSort, - getPodcasts: self.getPodcasts, - getPodcast: self.getPodcast, - getPlaylists: self.getPlaylists, - getPlaylist: self.getPlaylist, - addSongsToPlaylist: self.addSongsToPlaylist, - newPlaylist: self.newPlaylist, - savePlaylist: self.savePlaylist, - deletePlaylist: self.deletePlaylist, - addToPlaylist: self.addToPlaylist, - playlistMenu: self.playlistMenu, - removeSelectedSongs: self.removeSelectedSongs, - toggleAccordion: self.toggleAccordion - }; - } -}); \ No newline at end of file diff --git a/js/_saved/subsonic_old.js b/js/_saved/subsonic_old.js deleted file mode 100644 index 2360db9..0000000 --- a/js/_saved/subsonic_old.js +++ /dev/null @@ -1,21 +0,0 @@ -define(['knockout', 'postbox', 'mapping', 'global', 'utils', 'model'], function (ko, postbox, mapping, global, utils, model) { - var self = this; - self.album = new ko.observableArray([]); - self.song = new ko.observableArray([]).syncWith("song"); - self.templateToUse = ko.observable(); - - self.settings = global.settings; - self.queue = new ko.observableArray([]).syncWith("queue", true); - self.selectedArtist = ko.observable(); - self.selectedAlbum = ko.observable(); - self.selectedSongs = new ko.observableArray([]); - - - - - - return { - getRandomSongs: self.getRandomSongs, - updateFavorite: self.updateFavorite - }; -}); \ No newline at end of file diff --git a/js/app.js b/js/app.js index 146d7c8..ab163e6 100755 --- a/js/app.js +++ b/js/app.js @@ -1,6 +1,5 @@ -/* Declare app level module */ var JamStash = angular.module('JamStash', ['ngCookies', 'ngRoute', 'ngSanitize']); -//var JamStash = angular.module('JamStash', ['ngCookies', 'ngRoute']); + /* JamStash.config(function ($sceDelegateProvider) { $sceDelegateProvider.resourceUrlWhitelist(['/^\s*(https?|file|ms-appx):/', 'self']); @@ -10,38 +9,75 @@ JamStash.config(function ($sceDelegateProvider) { // URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby // Route: /Chapter/:chapterId/Section/:sectionId // -// Then -$routeParams ==> {chapterId:1, sectionId:2, search:'moby'} +// Then $routeParams ==> {chapterId:1, sectionId:2, search:'moby'} */ -JamStash.config(function ($routeProvider) { +JamStash.config(function($routeProvider) { $routeProvider - .when('/index', { redirectTo: '/library' }) - .when('/settings', { templateUrl: 'js/partials/settings.html', controller: 'SettingsCtrl' }) - .when('/queue', { templateUrl: 'js/partials/queue.html', controller: 'QueueCtrl' }) - .when('/library', { templateUrl: 'js/partials/library.html', controller: 'SubsonicCtrl' }) - .when('/library/:artistId', { templateUrl: 'js/partials/library.html', controller: 'SubsonicCtrl', reloadOnSearch: false }) - .when('/library/:artistId/:albumId', { templateUrl: 'js/partials/library.html', controller: 'SubsonicCtrl', reloadOnSearch: false }) - .when('/playlists', { templateUrl: 'js/partials/playlists.html', controller: 'PlaylistCtrl' }) - .when('/podcasts', { templateUrl: 'js/partials/podcasts.html', controller: 'PodcastCtrl' }) - .when('/archive', { templateUrl: 'js/partials/archive.html', controller: 'ArchiveCtrl' }) - .when('/archive/:artist', { templateUrl: 'js/partials/archive.html', controller: 'ArchiveCtrl' }) - .when('/archive/:artist/:album', { templateUrl: 'js/partials/archive.html', controller: 'ArchiveCtrl' }) - .otherwise({ redirectTo: '/index' }); + .when('/index', { + redirectTo: '/library' + }) + .when('/settings', { + templateUrl: 'js/partials/settings.html', + controller: 'SettingsCtrl' + }) + .when('/queue', { + templateUrl: 'js/partials/queue.html', + controller: 'QueueCtrl' + }) + .when('/library', { + templateUrl: 'js/partials/library.html', + controller: 'SubsonicCtrl' + }) + .when('/library/:artistId', { + templateUrl: 'js/partials/library.html', + controller: 'SubsonicCtrl', + reloadOnSearch: false + }) + .when('/library/:artistId/:albumId', { + templateUrl: 'js/partials/library.html', + controller: 'SubsonicCtrl', + reloadOnSearch: false + }) + .when('/playlists', { + templateUrl: 'js/partials/playlists.html', + controller: 'PlaylistCtrl' + }) + .when('/podcasts', { + templateUrl: 'js/partials/podcasts.html', + controller: 'PodcastCtrl' + }) + .when('/archive', { + templateUrl: 'js/partials/archive.html', + controller: 'ArchiveCtrl' + }) + .when('/archive/:artist', { + templateUrl: 'js/partials/archive.html', + controller: 'ArchiveCtrl' + }) + .when('/archive/:artist/:album', { + templateUrl: 'js/partials/archive.html', + controller: 'ArchiveCtrl' + }) + .otherwise({ + redirectTo: '/index' + }); }) -.run(['$rootScope', '$location', 'globals', function ($rootScope, $location, globals) { - $rootScope.$on("$locationChangeStart", function (event, next, current) { - $rootScope.loggedIn = false; - var path = $location.path().replace(/^\/([^\/]*).*$/, '$1'); - if (globals.settings.Username != "" && globals.settings.Password != "" && globals.settings.Server != "" && path != 'archive') { - $rootScope.loggedIn = true; + .run(['$rootScope', '$location', 'globals', + function($rootScope, $location, globals) { + $rootScope.$on("$locationChangeStart", function(event, next, current) { + $rootScope.loggedIn = false; + var path = $location.path().replace(/^\/([^\/]*).*$/, '$1'); + if (globals.settings.Username !== "" && globals.settings.Password !== "" && globals.settings.Server !== "" && path !== 'archive') { + $rootScope.loggedIn = true; + } + if (!$rootScope.loggedIn && (path != 'settings' && path != 'archive')) { + $location.path('/settings'); + } + }); } - if (!$rootScope.loggedIn && (path != 'settings' && path != 'archive')) { - $location.path('/settings'); - } - }); -}]); + ]); /* JamStash.config(function ($httpProvider, globals) { $httpProvider.defaults.timeout = globals.settings.Timeout; }) -*/ \ No newline at end of file +*/ diff --git a/js/controllers/archive.js b/js/controllers/archive.js index d4a6e51..713086e 100644 --- a/js/controllers/archive.js +++ b/js/controllers/archive.js @@ -1,288 +1,323 @@ JamStash.controller('ArchiveCtrl', -function ArchiveCtrl($scope, $rootScope, $location, $routeParams, $http, utils, globals, model, notifications, player, json) { - //$("#left-component").layout($scope.layoutThreeCol); + function ArchiveCtrl($scope, $rootScope, $location, $routeParams, $http, utils, globals, model, notifications, player, json) { + //$("#left-component").layout($scope.layoutThreeCol); - $scope.settings = globals.settings; - $scope.itemType = 'archive'; - $rootScope.song = []; - $scope.Protocol = 'jsonp'; - $scope.artist = []; - $scope.album = []; - $scope.selectedArtist; - $scope.selectedAlbum; - $scope.selectedSongs = []; - $scope.SavedCollections = globals.SavedCollections; - $scope.AllCollections = []; - $scope.loadedCollection = false; - json.getCollections(function (data) { - $scope.AllCollections = data; - $scope.loadedCollection = true; - }); - $scope.writeSavedCollection = function () { - utils.setValue('SavedCollections', $scope.SavedCollections.join(), false); - /* - $scope.$apply(function () { + $scope.settings = globals.settings; + $scope.itemType = 'archive'; + $rootScope.song = []; + $scope.Protocol = 'jsonp'; + $scope.artist = []; + $scope.album = []; + $scope.selectedArtist = null; + $scope.selectedAlbum = null; + $scope.selectedSongs = []; + $scope.SavedCollections = globals.SavedCollections; + $scope.AllCollections = []; + $scope.loadedCollection = false; + + json.getCollections(function(data) { + $scope.AllCollections = data; + $scope.loadedCollection = true; }); - */ - globals.SavedCollections = $scope.SavedCollections; - } - $scope.addSavedCollection = function (newValue) { - if ($scope.SavedCollections.indexOf(newValue) == -1) { - $scope.SavedCollections.push(newValue); + + $scope.writeSavedCollection = function() { + utils.setValue('SavedCollections', $scope.SavedCollections.join(), false); + globals.SavedCollections = $scope.SavedCollections; + }; + + $scope.addSavedCollection = function(newValue) { + if ($scope.SavedCollections.indexOf(newValue) == -1) { + $scope.SavedCollections.push(newValue); + $scope.writeSavedCollection(); + } + }; + + $scope.deleteSavedCollection = function(index) { + $scope.SavedCollections.splice(index, 1); $scope.writeSavedCollection(); - } - } - $scope.deleteSavedCollection = function (index) { - $scope.SavedCollections.splice(index, 1); - $scope.writeSavedCollection(); - } - $scope.selectedCollection; - $scope.$watch("selectedCollection", function (newValue, oldValue) { - if (newValue !== oldValue) { - $scope.addSavedCollection(newValue); - } - }); - $scope.setupDemoCollections = function () { - var demo = ["YonderMountainStringBand", "GreenskyBluegrass"]; - angular.forEach(demo, function (item, key) { - if ($scope.SavedCollections.indexOf(item) == -1) { - $scope.SavedCollections.push(item); + }; + + $scope.selectedCollection = null; + + $scope.$watch("selectedCollection", function(newValue, oldValue) { + if (newValue !== oldValue) { + $scope.addSavedCollection(newValue); } }); - } - $scope.archiveUrl = 'https://archive.org/'; - /* Filter */ - $scope.selectedArchiveAlbumSort = "date desc"; - $scope.ArchiveAlbumSort = [ - 'addeddate desc', - 'addeddate asc', - 'avg_rating desc', - 'avg_rating asc', - 'createdate desc', - 'createdate asc', - 'date desc', - 'date asc', - 'downloads desc', - 'downloads asc', - 'num_reviews desc', - 'num_reviews asc', - 'publicdate desc', - 'publicdate asc', - 'stars desc', - 'stars asc' - ], - $scope.$watch("selectedArchiveAlbumSort", function (newValue, oldValue) { - if (utils.getValue('AlbumSort') != newValue) { - if (typeof newValue != 'undefined') { - utils.setValue('AlbumSort', newValue, true); + $scope.setupDemoCollections = function() { + var demo = ["YonderMountainStringBand", "GreenskyBluegrass"]; + angular.forEach(demo, function(item, key) { + if ($scope.SavedCollections.indexOf(item) == -1) { + $scope.SavedCollections.push(item); + } + }); + }; + + $scope.archiveUrl = 'https://archive.org/'; + + /* Filter */ + $scope.selectedArchiveAlbumSort = "date desc"; + + $scope.ArchiveAlbumSort = [ + 'addeddate desc', + 'addeddate asc', + 'avg_rating desc', + 'avg_rating asc', + 'createdate desc', + 'createdate asc', + 'date desc', + 'date asc', + 'downloads desc', + 'downloads asc', + 'num_reviews desc', + 'num_reviews asc', + 'publicdate desc', + 'publicdate asc', + 'stars desc', + 'stars asc' + ]; + + $scope.$watch("selectedArchiveAlbumSort", function(newValue, oldValue) { + if (utils.getValue('AlbumSort') != newValue) { + if (typeof newValue != 'undefined') { + utils.setValue('AlbumSort', newValue, true); + } else { + utils.setValue('AlbumSort', null, true); + } + //alert(newValue); + $scope.getAlbums(''); + } + }); + + $scope.getYears = function(startYear) { + var currentYear = new Date().getFullYear(), + years = []; + startYear = startYear || 1950; + while (startYear <= currentYear) { + years.push(startYear++); + } + return years; + }; + + $scope.Years = $scope.getYears(); + + $scope.filter = { + Year: "", + Source: "", + Description: "" + }; + + $scope.filterSave = function() { + if ($scope.selectedArtist) { + $scope.getAlbums('', ''); + } + }; + + /* End Filter */ + + $scope.getAlbums = function(name, identifier) { + var url = $scope.archiveUrl + 'advancedsearch.php?q='; + + if (name !== '') { + $scope.selectedArtist = name; + url += 'collection:(' + name + ') AND format:(MP3)'; + } else if ($scope.selectedArtist) { + url += 'collection:(' + $scope.selectedArtist + ') AND format:(MP3)'; } else { - utils.setValue('AlbumSort', null, true); + url += 'identifier:(' + identifier + ')'; } - //alert(newValue); - $scope.getAlbums(''); - } - }); - $scope.getYears = function (startYear) { - var currentYear = new Date().getFullYear(), years = []; - startYear = startYear || 1950; - while (startYear <= currentYear) { - years.push(startYear++); - } - return years; - } - $scope.Years = $scope.getYears(), - $scope.filter = { - Year: "", - Source: "", - Description: "" - }; - $scope.filterSave = function () { - if ($scope.selectedArtist) { - $scope.getAlbums('', ''); - } - } - /* End Filter */ - /* - $scope.getArtists = function (data) { - var map = function (data) { - return new model.Artist('', data); - }; - angular.forEach($scope.SavedCollections, function (item, key) { - $scope.artist.push(map(item)); - }); - }; - */ - $scope.getAlbums = function (name, identifier) { - var url = $scope.archiveUrl + 'advancedsearch.php?q='; - if (name != '') { - $scope.selectedArtist = name; - url += 'collection:(' + name + ') AND format:(MP3)'; - } else if ($scope.selectedArtist) { - url += 'collection:(' + $scope.selectedArtist + ') AND format:(MP3)'; - } else { - url += 'identifier:(' + identifier + ')'; - } - var map = function (data) { - var song = data; - var coverartthumb, coverartfull, starred; - var url = $scope.archiveUrl + 'details/' + song.identifier; - coverartthumb = 'images/albumdefault_50.jpg'; - coverartfull = 'images/albumdefault_160.jpg'; - if (parseInt(song.avg_rating) == 5) { starred = true; } else { starred = false; } - //var description = 'Details
              '; - var description = 'Source: ' + song.source + '
              '; - description += 'Date: ' + song.date + '
              '; - description += typeof song.publisher != 'undefined' ? 'Transferer: ' + song.publisher + '
              ' : ''; - description += typeof song.avg_rating != 'undefined' ? 'Rating: ' + song.avg_rating + '
              ' : ''; - description += typeof song.downloads != 'undefined' ? 'Downloads: ' + song.downloads + '
              ' : ''; - return new model.Album(song.identifier, null, song.title, song.collection[0], '', coverartthumb, coverartfull, $.format.date(new Date(song.publicdate), "yyyy-MM-dd h:mm a"), starred, description, url); - } - if ($scope.filter.Source) { - url += ' AND source:(' + $scope.filter.Source + ')'; - } - if ($scope.filter.Year) { - if (parseInt($scope.filter.Year)) { - url += ' AND year:(' + $scope.filter.Year + ')'; - } - } - if ($scope.filter.Description) { - url += ' AND description:(' + $scope.filter.Description + ')'; - } - if ($scope.selectedArchiveAlbumSort) { - url += '&sort[]=' + $scope.selectedArchiveAlbumSort; - } - url += '&fl[]=avg_rating,collection,date,description,downloads,headerImage,identifier,publisher,publicdate,source,subject,title,year'; - url += '&rows=50&page=1&output=json'; - $.ajax({ - url: url, - method: 'GET', - dataType: $scope.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - var items = []; - if (data["response"].docs.length > 0) { - items = data["response"].docs; - //alert(JSON.stringify(data["response"])); - $scope.album = []; - $rootScope.song = []; - angular.forEach(items, function (item, key) { - $scope.album.push(map(item)); - }); - $scope.$apply(); - notifications.updateMessage($scope.album.length, true); + var map = function(data) { + var song = data; + var coverartthumb, coverartfull, starred; + var url = $scope.archiveUrl + 'details/' + song.identifier; + coverartthumb = 'images/albumdefault_50.jpg'; + coverartfull = 'images/albumdefault_160.jpg'; + if (parseInt(song.avg_rating) == 5) { + starred = true; } else { - notifications.updateMessage("Sorry :(", true); + starred = false; } - }, - error: function () { - alert('Archive.org service down :('); + //var description = 'Details
              '; + var description = 'Source: ' + song.source + '
              '; + description += 'Date: ' + song.date + '
              '; + description += typeof song.publisher != 'undefined' ? 'Transferer: ' + song.publisher + '
              ' : ''; + description += typeof song.avg_rating != 'undefined' ? 'Rating: ' + song.avg_rating + '
              ' : ''; + description += typeof song.downloads != 'undefined' ? 'Downloads: ' + song.downloads + '
              ' : ''; + return new model.Album(song.identifier, null, song.title, song.collection[0], '', coverartthumb, coverartfull, $.format.date(new Date(song.publicdate), "yyyy-MM-dd h:mm a"), starred, description, url); + }; + + if ($scope.filter.Source) { + url += ' AND source:(' + $scope.filter.Source + ')'; } - }); - }; - utils.mapSong = function (key, song, server, dir, identifier, coverart) { - var url, time, track, title, rating, starred, contenttype, suffix; - var specs = '' - if (song.format == 'VBR MP3') { - url = 'http://' + server + dir + key; - if (typeof song.bitrate == 'undefined' || typeof song.format == 'undefined') { specs = ' '; } else { specs = song.bitrate + 'kbps, ' + song.format.toLowerCase(); } - if (typeof song.track == 'undefined') { track = ' '; } else { track = song.track; } - if (typeof song.title == 'undefined') { title = ' '; } else { title = song.title; } - if (typeof song.length == 'undefined') { time = ' '; } else { time = utils.timeToSeconds(song.length); } - return new model.Song(song.md5, identifier, song.track, title, song.creator, '', song.album, '', coverart, coverart, time, '', '', 'mp3', specs, url, 0, ''); - } - }; - $scope.getSongs = function (id, action) { - $scope.selectedAlbum = id; - var url = $scope.archiveUrl + 'details/' + id + '?output=json'; - $.ajax({ - url: url, - method: 'GET', - dataType: $scope.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - var coverart = ''; - var server = data.server; - var dir = data.dir; - var identifier = data.metadata.identifier[0]; - if (typeof data.misc.image != 'undefined') { - coverart = data.misc.image; + + if ($scope.filter.Year) { + if (parseInt($scope.filter.Year)) { + url += ' AND year:(' + $scope.filter.Year + ')'; } - var items = data.files; - if (action == 'add') { - angular.forEach(items, function (item, key) { - var song = utils.mapSong(key, item, server, dir, identifier, coverart); - if (song) { - $rootScope.queue.push(song); - } - }); - $rootScope.showQueue(); - notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true); - $scope.$apply(); - } else if (action == 'play') { - $rootScope.queue = []; - angular.forEach(items, function (item, key) { - var song = utils.mapSong(key, item, server, dir, identifier, coverart); - if (song) { - $rootScope.queue.push(song); - } - }); - var next = $rootScope.queue[0]; - $scope.$apply(function () { - $rootScope.playSong(false, next); - }); - $rootScope.showQueue(); - notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true); + } + + if ($scope.filter.Description) { + url += ' AND description:(' + $scope.filter.Description + ')'; + } + + if ($scope.selectedArchiveAlbumSort) { + url += '&sort[]=' + $scope.selectedArchiveAlbumSort; + } + + url += '&fl[]=avg_rating,collection,date,description,downloads,headerImage,identifier,publisher,publicdate,source,subject,title,year'; + url += '&rows=50&page=1&output=json'; + + $.ajax({ + url: url, + method: 'GET', + dataType: $scope.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + var items = []; + if (data.response.docs.length > 0) { + items = data.response.docs; + $scope.album = []; + $rootScope.song = []; + angular.forEach(items, function(item, key) { + $scope.album.push(map(item)); + }); + $scope.$apply(); + notifications.updateMessage($scope.album.length, true); + } else { + notifications.updateMessage("Sorry :(", true); + } + }, + error: function() { + alert('Archive.org service down :('); + } + }); + }; + + utils.mapSong = function(key, song, server, dir, identifier, coverart) { + var url, time, track, title, rating, starred, contenttype, suffix; + var specs = ''; + if (song.format == 'VBR MP3') { + url = 'http://' + server + dir + key; + if (typeof song.bitrate == 'undefined' || typeof song.format == 'undefined') { + specs = ' '; } else { - $scope.album = []; - $rootScope.song = []; - angular.forEach(items, function (item, key) { - var song = utils.mapSong(key, item, server, dir, identifier, coverart); - if (song) { - $rootScope.song.push(song); - } - }); - $scope.$apply(); + specs = song.bitrate + 'kbps, ' + song.format.toLowerCase(); } + if (typeof song.track == 'undefined') { + track = ' '; + } else { + track = song.track; + } + if (typeof song.title == 'undefined') { + title = ' '; + } else { + title = song.title; + } + if (typeof song.length == 'undefined') { + time = ' '; + } else { + time = utils.timeToSeconds(song.length); + } + return new model.Song(song.md5, identifier, song.track, title, song.creator, '', song.album, '', coverart, coverart, time, '', '', 'mp3', specs, url, 0, ''); } - }); - }; - $scope.addSongsToQueue = function () { - if ($scope.selectedSongs.length > 0) { - angular.forEach($scope.selectedSongs, function (item, key) { - $scope.queue.push(item); + }; + + $scope.getSongs = function(id, action) { + $scope.selectedAlbum = id; + var url = $scope.archiveUrl + 'details/' + id + '?output=json'; + $.ajax({ + url: url, + method: 'GET', + dataType: $scope.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + var coverart = ''; + var server = data.server; + var dir = data.dir; + var identifier = data.metadata.identifier[0]; + if (typeof data.misc.image != 'undefined') { + coverart = data.misc.image; + } + var items = data.files; + if (action == 'add') { + angular.forEach(items, function(item, key) { + var song = utils.mapSong(key, item, server, dir, identifier, coverart); + if (song) { + $rootScope.queue.push(song); + } + }); + $rootScope.showQueue(); + notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true); + $scope.$apply(); + } else if (action == 'play') { + $rootScope.queue = []; + angular.forEach(items, function(item, key) { + var song = utils.mapSong(key, item, server, dir, identifier, coverart); + if (song) { + $rootScope.queue.push(song); + } + }); + var next = $rootScope.queue[0]; + $scope.$apply(function() { + $rootScope.playSong(false, next); + }); + $rootScope.showQueue(); + notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true); + } else { + $scope.album = []; + $rootScope.song = []; + angular.forEach(items, function(item, key) { + var song = utils.mapSong(key, item, server, dir, identifier, coverart); + if (song) { + $rootScope.song.push(song); + } + }); + $scope.$apply(); + } + } + }); + }; + + $scope.addSongsToQueue = function() { + if ($scope.selectedSongs.length > 0) { + angular.forEach($scope.selectedSongs, function(item, key) { + $scope.queue.push(item); + item.selected = false; + }); + $rootScope.showQueue(); + notifications.updateMessage($scope.selectedSongs.length + ' Song(s) Added to Queue', true); + } + }; + + $scope.scrollToTop = function() { + $('#Artists').stop().scrollTo('#auto', 400); + }; + + $scope.selectAll = function() { + angular.forEach($rootScope.song, function(item, key) { + $scope.selectedSongs.push(item); + item.selected = true; + }); + }; + + $scope.selectNone = function() { + angular.forEach($rootScope.song, function(item, key) { + $scope.selectedSongs = []; item.selected = false; }); - $rootScope.showQueue(); - notifications.updateMessage($scope.selectedSongs.length + ' Song(s) Added to Queue', true); - } - } - $scope.scrollToTop = function () { - $('#Artists').stop().scrollTo('#auto', 400); - } - $scope.selectAll = function () { - angular.forEach($rootScope.song, function (item, key) { - $scope.selectedSongs.push(item); - item.selected = true; - }); - } - $scope.selectNone = function () { - angular.forEach($rootScope.song, function (item, key) { - $scope.selectedSongs = []; - item.selected = false; - }); - } + }; - /* Launch on Startup */ - if ($routeParams.artist) { - if ($routeParams.album) { - //collection:(GreenskyBluegrass) AND format:(MP3) AND identifier:(gsbg2013-09-20.flac16) - $scope.getAlbums('', $routeParams.album); - } else { - $scope.getAlbums($routeParams.artist, ''); + /* Launch on Startup */ + if ($routeParams.artist) { + if ($routeParams.album) { + //collection:(GreenskyBluegrass) AND format:(MP3) AND identifier:(gsbg2013-09-20.flac16) + $scope.getAlbums('', $routeParams.album); + } else { + $scope.getAlbums($routeParams.artist, ''); + } + $scope.addSavedCollection($routeParams.artist); } - $scope.addSavedCollection($routeParams.artist); - } - /* End Startup */ -}); \ No newline at end of file + /* End Startup */ + }); diff --git a/js/controllers/library.js b/js/controllers/library.js index 9d00069..162cbcc 100644 --- a/js/controllers/library.js +++ b/js/controllers/library.js @@ -1,578 +1,643 @@ JamStash.controller('SubsonicCtrl', -function SubsonicCtrl($scope, $rootScope, $location, $window, $routeParams, utils, globals, model, notifications, player) { - //$("#SubsonicAlbums").layout($scope.layoutThreeCol); + function SubsonicCtrl($scope, $rootScope, $location, $window, $routeParams, utils, globals, model, notifications, player) { - $rootScope.song = []; - //$scope.artistId = $routeParams.artistId; - //$scope.albumId = $routeParams.albumId; - $scope.settings = globals.settings; - $scope.itemType = 'ss'; - $scope.index = []; - $scope.shortcut = []; - $scope.album = []; - $scope.Server = globals.settings.Server; - $scope.playlistMenu = []; - $scope.AutoAlbums = [ - { id: "random", name: "Random" }, - { id: "newest", name: "Recently Added" }, - { id: "starred", name: "Starred" }, - { id: "highest", name: "Top Rated" }, - { id: "frequent", name: "Most Played" }, - { id: "recent", name: "Recently Played" } - ]; - $scope.selectedAutoAlbum; - $scope.selectedArtist; - $scope.selectedAlbum; - $scope.SelectedAlbumSort = globals.settings.DefaultAlbumSort; - $scope.AlbumSort = globals.AlbumSorts; - $scope.BreadCrumbs = []; - $scope.$watch("SelectedAlbumSort.id", function (newValue, oldValue) { - if (newValue !== oldValue) { - if ($rootScope.song.length > 0) { - $scope.sortSubsonicSongs(newValue); - } else if ($scope.album.length > 0) { - $scope.sortSubsonicAlbums(newValue); - indexes = $.map(globals.AlbumSorts, function (obj, index) { - if (obj.id == newValue) { - return index; - } - }) - globals.settings.DefaultAlbumSort = globals.AlbumSorts[indexes]; - } - } - }); - $rootScope.$watch("SelectedMusicFolder", function (newValue, oldValue) { - if (newValue !== oldValue) { - utils.setValue('MusicFolders', angular.toJson(newValue), true); - $scope.getArtists(newValue.id); - } - }); - $scope.SearchType = globals.settings.DefaultSearchType; - $scope.SearchTypes = globals.SearchTypes; - $scope.rescanLibrary = function (data, event) { - $.ajax({ - url: globals.BaseURL() + '/getUser.view?' + globals.BaseParams() + '&username=' + globals.settings.Username, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - if (data["subsonic-response"].user.adminRole == true) { - $.get(globals.settings.Server + '/musicFolderSettings.view?scanNow'); - } else { - alert('You are not logged in as an admin user!'); - } - } - }); - } - $scope.mapArtist = function (data) { - var name = ''; - var artist = data.artist; - var artists = []; - if (artist.length > 0) { - artists = artist; - } else { - artists[0] = artist; - } - angular.forEach(artists, function (item, key) { - if (typeof item.name !== 'undefined') { item.name = item.name.toString(); } - }); - if (typeof data.name !== 'undefined') { name = data.name.toString(); } - return new model.Index(name, artists); - } - $scope.mapIndex = function (data) { - var name, id = ''; - if (typeof data.id !== 'undefined') { id = data.id; } - if (typeof data.name !== 'undefined') { name = data.name.toString(); } - return new model.Artist(id, name); - } - $scope.mapPlaylist = function (data) { - return new model.Artist(data.id, data.name); - } - $scope.getArtists = function (id) { - var url, id; - if (utils.getValue('MusicFolders')) { - var folder = angular.fromJson(utils.getValue('MusicFolders')); - id = folder.id; - } - if (id) { - url = globals.BaseURL() + '/getIndexes.view?' + globals.BaseParams() + '&musicFolderId=' + id; - } else { - url = globals.BaseURL() + '/getIndexes.view?' + globals.BaseParams(); - } - $.ajax({ - url: url, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - done: function () { if (globals.settings.Debug) { console.log("DONE!"); } }, - error: function () { if (globals.settings.Debug) { console.log("ERROR!"); } }, - success: function (data) { - var indexes = []; - if (typeof data["subsonic-response"].indexes.index != 'undefined') { - if (data["subsonic-response"].indexes.index.length > 0) { - //angular.forEach(items, function(item, key) { - //}); - //$.makeArray(obj) - indexes = data["subsonic-response"].indexes.index; - } else { - indexes[0] = data["subsonic-response"].indexes.index; - } - } - // TODO: AZIndex, build letters here. Make it a click button somewhere then a larger popup with letters finger friendly size - $scope.shortcut = []; - var items = []; - if (typeof data["subsonic-response"].indexes.shortcut != 'undefined') { - if (data["subsonic-response"].indexes.shortcut.length > 0) { - items = data["subsonic-response"].indexes.shortcut; - } else { - items[0] = data["subsonic-response"].indexes.shortcut; - } - angular.forEach(items, function (item, key) { - $scope.shortcut.push($scope.mapIndex(item)); - }); - } - $scope.index = []; - angular.forEach(indexes, function (item, key) { - $scope.index.push($scope.mapArtist(item)); - }); - $scope.$apply(); - } - }); - }; - $scope.refreshArtists = function (id) { - utils.setValue('MusicFolders', null, true); - $scope.getArtists(); - }; - - $scope.mapAlbum = function (data) { - var album = data; - var title, coverartthumb, coverartfull, starred; - if (typeof album.coverArt != 'undefined') { - coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=160&id=' + album.coverArt; - coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + album.coverArt; - } - if (typeof album.starred !== 'undefined') { starred = true; } else { starred = false; } - if (typeof album.title !== 'undefined') { title = album.title; } else { title = album.name; } - var type; - if (album.isDir) { - type = 'byfolder'; - } else { - type = 'bytag'; - } - return new model.Album(album.id, album.parent, title, album.artist, album.artistId, coverartthumb, coverartfull, $.format.date(new Date(album.created), "yyyy-MM-dd h:mm a"), starred, '', '', type); - } - $scope.getAlbums = function (id, name) { - $scope.selectedAutoAlbum = null; - $scope.selectedArtist = id; - $scope.BreadCrumbs = []; - $scope.BreadCrumbs.push({ 'type': 'artist', 'id': id, 'name': name }); - var url = globals.BaseURL() + '/getMusicDirectory.view?' + globals.BaseParams() + '&id=' + id; - $.ajax({ - url: url, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - var items = []; - if (typeof data["subsonic-response"].directory.child != 'undefined') { - if (data["subsonic-response"].directory.child.length > 0) { - items = data["subsonic-response"].directory.child; - } else { - items[0] = data["subsonic-response"].directory.child; - } - $scope.album = []; - $rootScope.song = []; - - angular.forEach(items, function (item, key) { - if (item.isDir) { - $scope.album.push($scope.mapAlbum(item)); - } else { - $rootScope.song.push(utils.mapSong(item)); - } - }); - if ($scope.SelectedAlbumSort.id != "default") { - $scope.sortSubsonicAlbums($scope.SelectedAlbumSort.id); - } - $scope.$apply(); - } else { - notifications.updateMessage('No Albums Returned :(', true); - } - } - }); - }; - $scope.getArtistByTag = function (id) { // Gets Artist by ID3 tag - /* - var map = { - create: function (options) { - var album = options.data; - var coverart, starred; - if (typeof album.coverArt != 'undefined') { - coverart = self.settings.BaseURL() + '/getCoverArt.view?' + self.settings.BaseParams() + '&size=50&id=' + album.coverArt; - } - if (typeof album.starred !== 'undefined') { starred = true; } else { starred = false; } - return new model.Album(album.id, album.parent, album.name, album.artist, coverart, album.created, starred, '', ''); - } - } - */ + $rootScope.song = []; + //$scope.artistId = $routeParams.artistId; + //$scope.albumId = $routeParams.albumId; + $scope.settings = globals.settings; + $scope.itemType = 'ss'; + $scope.index = []; + $scope.shortcut = []; + $scope.album = []; + $scope.Server = globals.settings.Server; + $scope.playlistMenu = []; + $scope.AutoAlbums = [{ + id: "random", + name: "Random" + }, { + id: "newest", + name: "Recently Added" + }, { + id: "starred", + name: "Starred" + }, { + id: "highest", + name: "Top Rated" + }, { + id: "frequent", + name: "Most Played" + }, { + id: "recent", + name: "Recently Played" + }]; $scope.selectedAutoAlbum = null; - $scope.selectedArtist = id; - var url = globals.BaseURL() + '/getArtist.view?' + globals.BaseParams() + '&id=' + id; - $.ajax({ - url: url, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - var items = []; - if (typeof data["subsonic-response"].artist != 'undefined') { - if (data["subsonic-response"].artist.album.length > 0) { - items = data["subsonic-response"].artist.album; - } else { - items[0] = data["subsonic-response"].artist.album; - } - $scope.album = []; - $rootScope.song = []; - - angular.forEach(items, function (item, key) { - $scope.album.push($scope.mapAlbum(item)); - }); - $scope.$apply(); - } else { - notifications.updateMessage('No Albums Returned :(', true); - } - } - }); - }; - $scope.getAlbumByTag = function (id) { // Gets Album by ID3 tag - $.ajax({ - url: globals.BaseURL() + '/getAlbum.view?' + globals.BaseParams() + '&id=' + id, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - if (typeof data["subsonic-response"].album != 'undefined') { - $scope.album = []; - $rootScope.song = []; - - $scope.album.push($scope.mapAlbum(data["subsonic-response"].album)); - - var items = []; - if (data["subsonic-response"].album.song.length > 0) { - items = data["subsonic-response"].album.song; - } else { - items[0] = data["subsonic-response"].album.song; - } - angular.forEach(items, function (item, key) { - $rootScope.song.push(utils.mapSong(item)); - }); - $scope.$apply(); - } - } - }); - }; - $scope.offset = 0; - $scope.getAlbumListBy = function (id, offset) { - var size, url; $scope.selectedArtist = null; - $scope.selectedAutoAlbum = id; + $scope.selectedAlbum = null; + + $scope.SelectedAlbumSort = globals.settings.DefaultAlbumSort; + $scope.AlbumSort = globals.AlbumSorts; $scope.BreadCrumbs = []; - if (offset == 'next') { - $scope.offset = $scope.offset + globals.settings.AutoAlbumSize; - } else if (offset == 'prev') { - $scope.offset = $scope.offset - globals.settings.AutoAlbumSize; - } - if ($scope.offset > 0) { - url = globals.BaseURL() + '/getAlbumList.view?' + globals.BaseParams() + '&size=' + globals.settings.AutoAlbumSize.toString() + '&type=' + id + '&offset=' + $scope.offset; - } else { - url = globals.BaseURL() + '/getAlbumList.view?' + globals.BaseParams() + '&size=' + globals.settings.AutoAlbumSize.toString() + '&type=' + id; - } - $.ajax({ - url: url, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - var items = []; - if (typeof data["subsonic-response"].albumList.album != 'undefined') { - if (data["subsonic-response"].albumList.album.length > 0) { - items = data["subsonic-response"].albumList.album; - } else { - items[0] = data["subsonic-response"].albumList.album; - } - $scope.album = []; - $rootScope.song = []; - angular.forEach(items, function (item, key) { - if (item.isDir) { - $scope.album.push($scope.mapAlbum(item)); - } else { - $rootScope.song.push($scope.mapAlbum(item)); + + $scope.$watch("SelectedAlbumSort.id", function(newValue, oldValue) { + if (newValue !== oldValue) { + if ($rootScope.song.length > 0) { + $scope.sortSubsonicSongs(newValue); + } else if ($scope.album.length > 0) { + $scope.sortSubsonicAlbums(newValue); + + indexes = $.map(globals.AlbumSorts, function(obj, index) { + if (obj.id == newValue) { + return index; } }); - if ($scope.SelectedAlbumSort.id != "default") { - $scope.sortSubsonicAlbums($scope.SelectedAlbumSort.id); - } - $scope.$apply(); - } else { - notifications.updateMessage('No Albums Returned :(', true); + + globals.settings.DefaultAlbumSort = globals.AlbumSorts[indexes]; } } }); - }; - $scope.getSongs = function (id, action) { - $scope.selectedAlbum = id; - var url = globals.BaseURL() + '/getMusicDirectory.view?' + globals.BaseParams() + '&id=' + id; - $.ajax({ - url: url, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - var items = []; - if (typeof data["subsonic-response"].directory.child != 'undefined') { - if (data["subsonic-response"].directory.child.length > 0) { - items = data["subsonic-response"].directory.child; + + $rootScope.$watch("SelectedMusicFolder", function(newValue, oldValue) { + if (newValue !== oldValue) { + utils.setValue('MusicFolders', angular.toJson(newValue), true); + $scope.getArtists(newValue.id); + } + }); + + $scope.SearchType = globals.settings.DefaultSearchType; + $scope.SearchTypes = globals.SearchTypes; + + $scope.rescanLibrary = function(data, event) { + $.ajax({ + url: globals.BaseURL() + '/getUser.view?' + globals.BaseParams() + '&username=' + globals.settings.Username, + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + if (data["subsonic-response"].user.adminRole === true) { + $.get(globals.settings.Server + '/musicFolderSettings.view?scanNow'); } else { - items[0] = data["subsonic-response"].directory.child; + alert('You are not logged in as an admin user!'); } - if (action == 'add') { - angular.forEach(items, function (item, key) { - $rootScope.queue.push(utils.mapSong(item)); - }); - $scope.$apply(); - $rootScope.showQueue(); - notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); - } else if (action == 'play') { - $rootScope.queue = []; - angular.forEach(items, function (item, key) { - $rootScope.queue.push(utils.mapSong(item)); - }); - var next = $rootScope.queue[0]; - $scope.$apply(function () { - $rootScope.playSong(false, next); - }); - $rootScope.showQueue(); - notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); - } else if (action == 'preview') { - $scope.songpreview = []; - angular.forEach(items, function (item, key) { - if (!item.isDir) { - $rootScope.songpreview.push(utils.mapSong(item)); - } - }); - $scope.$apply(); - } else { - if (typeof data["subsonic-response"].directory.id != 'undefined') { - var albumId = data["subsonic-response"].directory.id; - var albumName = data["subsonic-response"].directory.name; - if ($scope.BreadCrumbs.length > 0) { $scope.BreadCrumbs.splice(1, ($scope.BreadCrumbs.length - 1)) }; - $scope.BreadCrumbs.push({ 'type': 'album', 'id': albumId, 'name': albumName }); + } + }); + }; + + $scope.mapArtist = function(data) { + var name = ''; + var artist = data.artist; + var artists = []; + if (artist.length > 0) { + artists = artist; + } else { + artists[0] = artist; + } + angular.forEach(artists, function(item, key) { + if (typeof item.name !== 'undefined') { + item.name = item.name.toString(); + } + }); + if (typeof data.name !== 'undefined') { + name = data.name.toString(); + } + return new model.Index(name, artists); + }; + + $scope.mapIndex = function(data) { + var name, id = ''; + if (typeof data.id !== 'undefined') { + id = data.id; + } + if (typeof data.name !== 'undefined') { + name = data.name.toString(); + } + return new model.Artist(id, name); + }; + + $scope.mapPlaylist = function(data) { + return new model.Artist(data.id, data.name); + }; + + $scope.getArtists = function(id) { + var url; + if (utils.getValue('MusicFolders')) { + var folder = angular.fromJson(utils.getValue('MusicFolders')); + id = folder.id; + } + if (id) { + url = globals.BaseURL() + '/getIndexes.view?' + globals.BaseParams() + '&musicFolderId=' + id; + } else { + url = globals.BaseURL() + '/getIndexes.view?' + globals.BaseParams(); + } + $.ajax({ + url: url, + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + done: function() { + if (globals.settings.Debug) { + console.log("DONE!"); + } + }, + error: function() { + if (globals.settings.Debug) { + console.log("ERROR!"); + } + }, + success: function(data) { + var indexes = []; + if (typeof data["subsonic-response"].indexes.index != 'undefined') { + if (data["subsonic-response"].indexes.index.length > 0) { + //angular.forEach(items, function(item, key) { + //}); + //$.makeArray(obj) + indexes = data["subsonic-response"].indexes.index; + } else { + indexes[0] = data["subsonic-response"].indexes.index; + } + } + // TODO: AZIndex, build letters here. Make it a click button somewhere then a larger popup with letters finger friendly size + $scope.shortcut = []; + var items = []; + if (typeof data["subsonic-response"].indexes.shortcut != 'undefined') { + if (data["subsonic-response"].indexes.shortcut.length > 0) { + items = data["subsonic-response"].indexes.shortcut; + } else { + items[0] = data["subsonic-response"].indexes.shortcut; + } + angular.forEach(items, function(item, key) { + $scope.shortcut.push($scope.mapIndex(item)); + }); + } + $scope.index = []; + angular.forEach(indexes, function(item, key) { + $scope.index.push($scope.mapArtist(item)); + }); + $scope.$apply(); + } + }); + }; + + $scope.refreshArtists = function(id) { + utils.setValue('MusicFolders', null, true); + $scope.getArtists(); + }; + + $scope.mapAlbum = function(data) { + var album = data; + var title, coverartthumb, coverartfull, starred; + if (typeof album.coverArt != 'undefined') { + coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=160&id=' + album.coverArt; + coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + album.coverArt; + } + if (typeof album.starred !== 'undefined') { + starred = true; + } else { + starred = false; + } + if (typeof album.title !== 'undefined') { + title = album.title; + } else { + title = album.name; + } + var type; + if (album.isDir) { + type = 'byfolder'; + } else { + type = 'bytag'; + } + return new model.Album(album.id, album.parent, title, album.artist, album.artistId, coverartthumb, coverartfull, $.format.date(new Date(album.created), "yyyy-MM-dd h:mm a"), starred, '', '', type); + }; + + $scope.getAlbums = function(id, name) { + $scope.selectedAutoAlbum = null; + $scope.selectedArtist = id; + $scope.BreadCrumbs = []; + $scope.BreadCrumbs.push({ + 'type': 'artist', + 'id': id, + 'name': name + }); + var url = globals.BaseURL() + '/getMusicDirectory.view?' + globals.BaseParams() + '&id=' + id; + $.ajax({ + url: url, + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + var items = []; + if (typeof data["subsonic-response"].directory.child != 'undefined') { + if (data["subsonic-response"].directory.child.length > 0) { + items = data["subsonic-response"].directory.child; + } else { + items[0] = data["subsonic-response"].directory.child; } - $rootScope.song = []; $scope.album = []; - var albums = []; - angular.forEach(items, function (item, key) { + $rootScope.song = []; + + angular.forEach(items, function(item, key) { if (item.isDir) { - albums.push($scope.mapAlbum(item)); + $scope.album.push($scope.mapAlbum(item)); } else { $rootScope.song.push(utils.mapSong(item)); } }); - if (albums.length > 0) { - $scope.album = albums; - if ($scope.SelectedAlbumSort.id != "default") { - $scope.sortSubsonicAlbums($scope.SelectedAlbumSort.id); - } + if ($scope.SelectedAlbumSort.id != "default") { + $scope.sortSubsonicAlbums($scope.SelectedAlbumSort.id); } $scope.$apply(); - } - } else { - notifications.updateMessage('No Songs Returned :(', true); - } - } - }); - }; - $scope.search = function () { - var query = $('#Search').val(); - if (query != '') { - var type = $('#SearchType').val(); - $.ajax({ - url: globals.BaseURL() + '/search2.view?' + globals.BaseParams() + '&query=' + query, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - if (data["subsonic-response"].searchResult2 !== "") { - var header; - var items = []; - if (type === '0') { - if (data["subsonic-response"].searchResult2.song !== undefined) { - if (data["subsonic-response"].searchResult2.song.length > 0) { - items = data["subsonic-response"].searchResult2.song; - } else { - items[0] = data["subsonic-response"].searchResult2.song; - } - $rootScope.song = []; - angular.forEach(items, function (item, key) { - $rootScope.song.push(utils.mapSong(item)); - }); - $scope.$apply(); - } - } - if (type === '1') { - if (data["subsonic-response"].searchResult2.album !== undefined) { - if (data["subsonic-response"].searchResult2.album.length > 0) { - items = data["subsonic-response"].searchResult2.album; - } else { - items[0] = data["subsonic-response"].searchResult2.album; - } - $scope.album = []; - angular.forEach(items, function (item, key) { - if (item.isDir) { - $scope.album.push($scope.mapAlbum(item)); - } else { - $rootScope.song.push($scope.mapAlbum(item)); - } - }); - $scope.$apply(); - } - } - if (type === '2') { - if (data["subsonic-response"].searchResult2.artist !== undefined) { - if (data["subsonic-response"].searchResult2.artist.length > 0) { - items = data["subsonic-response"].searchResult2.artist; - } else { - items[0] = data["subsonic-response"].searchResult2.artist; - } - angular.forEach(items, function (item, key) { - $scope.shortcut.push(item); - }); - $scope.$apply(); - } - } + } else { + notifications.updateMessage('No Albums Returned :(', true); } } }); - //$('#Search').val(""); - } - } - $scope.toggleAZ = function (event) { - $scope.toggleSubmenu('#submenu_AZIndex', '#AZIndex', 'right', 44); - } - $scope.loadPlaylistsForMenu = function (data, event) { - $.ajax({ - url: globals.BaseURL() + '/getPlaylists.view?' + globals.BaseParams(), - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - var playlists = []; - $scope.playlistMenu = []; - if (typeof data["subsonic-response"].playlists.playlist != 'undefined') { - if (data["subsonic-response"].playlists.playlist.length > 0) { - playlists = data["subsonic-response"].playlists.playlist; - } else { - playlists[0] = data["subsonic-response"].playlists.playlist; - } - angular.forEach(playlists, function (item, key) { - if (item.owner == globals.settings.Username) { - $scope.playlistMenu.push($scope.mapPlaylist(item)); + }; + + $scope.getArtistByTag = function(id) { // Gets Artist by ID3 tag + $scope.selectedAutoAlbum = null; + $scope.selectedArtist = id; + var url = globals.BaseURL() + '/getArtist.view?' + globals.BaseParams() + '&id=' + id; + $.ajax({ + url: url, + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + var items = []; + if (typeof data["subsonic-response"].artist != 'undefined') { + if (data["subsonic-response"].artist.album.length > 0) { + items = data["subsonic-response"].artist.album; + } else { + items[0] = data["subsonic-response"].artist.album; } - }); - if ($scope.playlistMenu.length > 0) { + $scope.album = []; + $rootScope.song = []; + + angular.forEach(items, function(item, key) { + $scope.album.push($scope.mapAlbum(item)); + }); $scope.$apply(); - $scope.toggleSubmenu('#submenu_AddToPlaylist', '#action_AddToPlaylist', 'left', 124); } else { - notifications.updateMessage('No Playlists :(', true); + notifications.updateMessage('No Albums Returned :(', true); } } - /* + }); + }; + + $scope.getAlbumByTag = function(id) { // Gets Album by ID3 tag + $.ajax({ + url: globals.BaseURL() + '/getAlbum.view?' + globals.BaseParams() + '&id=' + id, + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + if (typeof data["subsonic-response"].album != 'undefined') { + $scope.album = []; + $rootScope.song = []; + + $scope.album.push($scope.mapAlbum(data["subsonic-response"].album)); + + var items = []; + if (data["subsonic-response"].album.song.length > 0) { + items = data["subsonic-response"].album.song; + } else { + items[0] = data["subsonic-response"].album.song; + } + angular.forEach(items, function(item, key) { + $rootScope.song.push(utils.mapSong(item)); + }); + $scope.$apply(); + } + } + }); + }; + + $scope.offset = 0; + $scope.getAlbumListBy = function(id, offset) { + var size, url; + $scope.selectedArtist = null; + $scope.selectedAutoAlbum = id; + $scope.BreadCrumbs = []; + + if (offset == 'next') { + $scope.offset = $scope.offset + globals.settings.AutoAlbumSize; + } else if (offset == 'prev') { + $scope.offset = $scope.offset - globals.settings.AutoAlbumSize; + } + + if ($scope.offset > 0) { + url = globals.BaseURL() + '/getAlbumList.view?' + globals.BaseParams() + '&size=' + globals.settings.AutoAlbumSize.toString() + '&type=' + id + '&offset=' + $scope.offset; + } else { + url = globals.BaseURL() + '/getAlbumList.view?' + globals.BaseParams() + '&size=' + globals.settings.AutoAlbumSize.toString() + '&type=' + id; + } + + $.ajax({ + url: url, + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + var items = []; + if (typeof data["subsonic-response"].albumList.album != 'undefined') { + if (data["subsonic-response"].albumList.album.length > 0) { + items = data["subsonic-response"].albumList.album; + } else { + items[0] = data["subsonic-response"].albumList.album; + } + $scope.album = []; + $rootScope.song = []; + angular.forEach(items, function(item, key) { + if (item.isDir) { + $scope.album.push($scope.mapAlbum(item)); + } else { + $rootScope.song.push($scope.mapAlbum(item)); + } + }); + if ($scope.SelectedAlbumSort.id != "default") { + $scope.sortSubsonicAlbums($scope.SelectedAlbumSort.id); + } + $scope.$apply(); + } else { + notifications.updateMessage('No Albums Returned :(', true); + } + } + }); + }; + + $scope.getSongs = function(id, action) { + $scope.selectedAlbum = id; + var url = globals.BaseURL() + '/getMusicDirectory.view?' + globals.BaseParams() + '&id=' + id; + $.ajax({ + url: url, + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + var items = []; + if (typeof data["subsonic-response"].directory.child != 'undefined') { + if (data["subsonic-response"].directory.child.length > 0) { + items = data["subsonic-response"].directory.child; + } else { + items[0] = data["subsonic-response"].directory.child; + } + if (action == 'add') { + angular.forEach(items, function(item, key) { + $rootScope.queue.push(utils.mapSong(item)); + }); + $scope.$apply(); + $rootScope.showQueue(); + notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); + } else if (action == 'play') { + $rootScope.queue = []; + angular.forEach(items, function(item, key) { + $rootScope.queue.push(utils.mapSong(item)); + }); + var next = $rootScope.queue[0]; + $scope.$apply(function() { + $rootScope.playSong(false, next); + }); + $rootScope.showQueue(); + notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); + } else if (action == 'preview') { + $scope.songpreview = []; + angular.forEach(items, function(item, key) { + if (!item.isDir) { + $rootScope.songpreview.push(utils.mapSong(item)); + } + }); + $scope.$apply(); + } else { + if (typeof data["subsonic-response"].directory.id != 'undefined') { + var albumId = data["subsonic-response"].directory.id; + var albumName = data["subsonic-response"].directory.name; + + if ($scope.BreadCrumbs.length > 0) { + $scope.BreadCrumbs.splice(1, ($scope.BreadCrumbs.length - 1)); + } + + $scope.BreadCrumbs.push({ + 'type': 'album', + 'id': albumId, + 'name': albumName + }); + } + $rootScope.song = []; + $scope.album = []; + var albums = []; + angular.forEach(items, function(item, key) { + if (item.isDir) { + albums.push($scope.mapAlbum(item)); + } else { + $rootScope.song.push(utils.mapSong(item)); + } + }); + if (albums.length > 0) { + $scope.album = albums; + if ($scope.SelectedAlbumSort.id != "default") { + $scope.sortSubsonicAlbums($scope.SelectedAlbumSort.id); + } + } + $scope.$apply(); + } + } else { + notifications.updateMessage('No Songs Returned :(', true); + } + } + }); + }; + + $scope.search = function() { + var query = $('#Search').val(); + if (query !== '') { + var type = $('#SearchType').val(); + $.ajax({ + url: globals.BaseURL() + '/search2.view?' + globals.BaseParams() + '&query=' + query, + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + if (data["subsonic-response"].searchResult2 !== "") { + var header; + var items = []; + if (type === '0') { + if (data["subsonic-response"].searchResult2.song !== undefined) { + if (data["subsonic-response"].searchResult2.song.length > 0) { + items = data["subsonic-response"].searchResult2.song; + } else { + items[0] = data["subsonic-response"].searchResult2.song; + } + $rootScope.song = []; + angular.forEach(items, function(item, key) { + $rootScope.song.push(utils.mapSong(item)); + }); + $scope.$apply(); + } + } + if (type === '1') { + if (data["subsonic-response"].searchResult2.album !== undefined) { + if (data["subsonic-response"].searchResult2.album.length > 0) { + items = data["subsonic-response"].searchResult2.album; + } else { + items[0] = data["subsonic-response"].searchResult2.album; + } + $scope.album = []; + angular.forEach(items, function(item, key) { + if (item.isDir) { + $scope.album.push($scope.mapAlbum(item)); + } else { + $rootScope.song.push($scope.mapAlbum(item)); + } + }); + $scope.$apply(); + } + } + if (type === '2') { + if (data["subsonic-response"].searchResult2.artist !== undefined) { + if (data["subsonic-response"].searchResult2.artist.length > 0) { + items = data["subsonic-response"].searchResult2.artist; + } else { + items[0] = data["subsonic-response"].searchResult2.artist; + } + angular.forEach(items, function(item, key) { + $scope.shortcut.push(item); + }); + $scope.$apply(); + } + } + } + } + }); + } + }; + + $scope.toggleAZ = function(event) { + $scope.toggleSubmenu('#submenu_AZIndex', '#AZIndex', 'right', 44); + }; + + $scope.loadPlaylistsForMenu = function(data, event) { + $.ajax({ + url: globals.BaseURL() + '/getPlaylists.view?' + globals.BaseParams(), + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + var playlists = []; + $scope.playlistMenu = []; + if (typeof data["subsonic-response"].playlists.playlist != 'undefined') { + if (data["subsonic-response"].playlists.playlist.length > 0) { + playlists = data["subsonic-response"].playlists.playlist; + } else { + playlists[0] = data["subsonic-response"].playlists.playlist; + } + angular.forEach(playlists, function(item, key) { + if (item.owner == globals.settings.Username) { + $scope.playlistMenu.push($scope.mapPlaylist(item)); + } + }); + if ($scope.playlistMenu.length > 0) { + $scope.$apply(); + $scope.toggleSubmenu('#submenu_AddToPlaylist', '#action_AddToPlaylist', 'left', 124); + } else { + notifications.updateMessage('No Playlists :(', true); + } + } + /* $("+ New
              ").appendTo("#" + menu); $.each(playlists, function (i, playlist) { $('' + playlist.name + '
              ').appendTo("#" + menu); }); */ - } - }); - } - $scope.addToPlaylist = function (id) { - var songs = []; - if ($scope.selectedSongs.length !== 0) { - angular.forEach($scope.selectedSongs, function (item, key) { - songs.push(item.id); + } }); - var runningVersion = utils.parseVersionString(globals.settings.ApiVersion); - var minimumVersion = utils.parseVersionString('1.8.0'); - if (utils.checkVersion(runningVersion, minimumVersion)) { // is 1.8.0 or newer - $.ajax({ - type: 'GET', - url: globals.BaseURL() + '/updatePlaylist.view?' + globals.BaseParams(), - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - data: { playlistId: id, songIdToAdd: songs }, - success: function (data) { - $scope.selectedSongs.length = 0; - notifications.updateMessage('Playlist Updated!', true); - }, - traditional: true // Fixes POST with an array in JQuery 1.4 - }); - } - } - } - $scope.sortDateFunction = function (a, b) { - return a.date < b.date ? 1 : -1; - }; - $scope.sortArtistFunction = function (a, b) { - return a.artist.toLowerCase() < b.artist.toLowerCase() ? -1 : 1; - }; - $scope.sortAlbumFunction = function (a, b) { - return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1; - }; - $scope.sortTrackFunction = function (a, b) { - return parseInt(a.track) > parseInt(b.track) ? -1 : 1; - }; - $scope.sortSubsonicAlbums = function (newValue) { - if (typeof newValue != 'undefined') { - //alert(newValue); - switch (newValue) { - case 'createdate desc': - $scope.album.sort($scope.sortDateFunction); - break; - case 'artist': - $scope.album.sort($scope.sortArtistFunction); - break; - case 'album': - $scope.album.sort($scope.sortAlbumFunction); - break; - } - } - }; - $scope.sortSubsonicSongs = function (newValue) { - if (typeof newValue != 'undefined') { - //alert(newValue); - switch (newValue) { - case 'createdate desc': - $rootScope.song.sort($scope.sortDateFunction); - break; - case 'artist': - $rootScope.song.sort($scope.sortArtistFunction); - break; - case 'album': - $rootScope.song.sort($scope.sortAlbumFunction); - break; - case 'track': - $rootScope.song.sort($scope.sortTrackFunction); - break; - } - } - }; + }; - /* Launch on Startup */ - $scope.getArtists(); - if ($routeParams.artistId && $routeParams.albumId) { - $scope.getAlbumByTag($routeParams.albumId); - } else if ($routeParams.artistId) { - $scope.getAlbums($routeParams.artistId); - } - /* End Startup */ -}); + $scope.addToPlaylist = function(id) { + var songs = []; + if ($scope.selectedSongs.length !== 0) { + angular.forEach($scope.selectedSongs, function(item, key) { + songs.push(item.id); + }); + var runningVersion = utils.parseVersionString(globals.settings.ApiVersion); + var minimumVersion = utils.parseVersionString('1.8.0'); + if (utils.checkVersion(runningVersion, minimumVersion)) { // is 1.8.0 or newer + $.ajax({ + type: 'GET', + url: globals.BaseURL() + '/updatePlaylist.view?' + globals.BaseParams(), + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + data: { + playlistId: id, + songIdToAdd: songs + }, + success: function(data) { + $scope.selectedSongs.length = 0; + notifications.updateMessage('Playlist Updated!', true); + }, + traditional: true // Fixes POST with an array in JQuery 1.4 + }); + } + } + }; + + $scope.sortDateFunction = function(a, b) { + return a.date < b.date ? 1 : -1; + }; + + $scope.sortArtistFunction = function(a, b) { + return a.artist.toLowerCase() < b.artist.toLowerCase() ? -1 : 1; + }; + + $scope.sortAlbumFunction = function(a, b) { + return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1; + }; + + $scope.sortTrackFunction = function(a, b) { + return parseInt(a.track) > parseInt(b.track) ? -1 : 1; + }; + + $scope.sortSubsonicAlbums = function(newValue) { + if (typeof newValue != 'undefined') { + //alert(newValue); + switch (newValue) { + case 'createdate desc': + $scope.album.sort($scope.sortDateFunction); + break; + case 'artist': + $scope.album.sort($scope.sortArtistFunction); + break; + case 'album': + $scope.album.sort($scope.sortAlbumFunction); + break; + } + } + }; + + $scope.sortSubsonicSongs = function(newValue) { + if (typeof newValue != 'undefined') { + //alert(newValue); + switch (newValue) { + case 'createdate desc': + $rootScope.song.sort($scope.sortDateFunction); + break; + case 'artist': + $rootScope.song.sort($scope.sortArtistFunction); + break; + case 'album': + $rootScope.song.sort($scope.sortAlbumFunction); + break; + case 'track': + $rootScope.song.sort($scope.sortTrackFunction); + break; + } + } + }; + + /* Launch on Startup */ + $scope.getArtists(); + if ($routeParams.artistId && $routeParams.albumId) { + $scope.getAlbumByTag($routeParams.albumId); + } else if ($routeParams.artistId) { + $scope.getAlbums($routeParams.artistId); + } + /* End Startup */ + }); diff --git a/js/controllers/main.js b/js/controllers/main.js index 6e8686a..de7efc5 100644 --- a/js/controllers/main.js +++ b/js/controllers/main.js @@ -1,78 +1,164 @@ JamStash.controller('AppCtrl', -function AppCtrl($scope, $rootScope, $document, $location, $cookieStore, utils, globals, model, notifications, player) { - $rootScope.settings = globals.settings; - $rootScope.song = []; - $rootScope.queue = []; - $rootScope.playingSong; - $rootScope.MusicFolders = []; - $rootScope.Genres = []; - $rootScope.selectedPlaylist = ""; - $rootScope.selectedAutoPlaylist = ""; - $rootScope.SelectedMusicFolder = ""; - $rootScope.unity; - $rootScope.loggedIn = function () { - if (globals.settings.Server != '' && globals.settings.Username != '' && globals.settings.Password != '') { - return true; - } else { - return false; - } - } - $rootScope.totalDisplayed = 50; - $rootScope.loadMore = function () { - $scope.totalDisplayed += 50; - }; - /* - $scope.playSong = function (loadonly, data) { - $scope.$apply(function () { - $rootScope.playSong(loadonly, data); - }); - } - */ + function AppCtrl($scope, $rootScope, $document, $location, $cookieStore, utils, globals, model, notifications, player) { + $rootScope.settings = globals.settings; + $rootScope.song = []; + $rootScope.queue = []; + $rootScope.playingSong = null; + $rootScope.MusicFolders = []; + $rootScope.Genres = []; + $rootScope.selectedPlaylist = ""; + $rootScope.selectedAutoPlaylist = ""; + $rootScope.SelectedMusicFolder = ""; + $rootScope.unity = null; - // Reads cookies and sets globals.settings values - $scope.loadSettings = function () { - // Temporary Code to Convert Cookies added 2/2/2014 - if ($cookieStore.get('Settings')) { - utils.setValue('Settings', $cookieStore.get('Settings'), false); - $cookieStore.remove('Settings'); - } - if (utils.getValue('Settings')) { - $.each(utils.getValue('Settings'), function (k, v) { - if (v == 'false') { v = false; } - if (v == 'true') { v = true; } - globals.settings[k] = v; + $rootScope.loggedIn = function() { + if (globals.settings.Server !== '' && globals.settings.Username !== '' && globals.settings.Password !== '') { + return true; + } else { + return false; + } + }; + + $rootScope.totalDisplayed = 50; + + $rootScope.loadMore = function() { + $scope.totalDisplayed += 50; + }; + + // Reads cookies and sets globals.settings values + $scope.loadSettings = function() { + // Temporary Code to Convert Cookies added 2/2/2014 + if ($cookieStore.get('Settings')) { + utils.setValue('Settings', $cookieStore.get('Settings'), false); + $cookieStore.remove('Settings'); + } + if (utils.getValue('Settings')) { + $.each(utils.getValue('Settings'), function(k, v) { + if (v == 'false') { + v = false; + } + if (v == 'true') { + v = true; + } + globals.settings[k] = v; + }); + } + if (utils.getValue("SavedCollections")) { + globals.SavedCollections = utils.getValue("SavedCollections").split(","); + } + if (utils.getValue("SavedGenres")) { + globals.SavedGenres = utils.getValue("SavedGenres").split(","); + } + if (globals.settings.Debug) { + console.log('Settings: ' + JSON.stringify(globals.settings, null, 2)); + } + }; + + $scope.toggleSetting = function(setting) { + var id = setting; + if (globals.settings[id]) { + globals.settings[id] = false; + } else { + globals.settings[id] = true; + } + notifications.updateMessage(setting + ' : ' + globals.settings[id], true); + }; + + $.ajaxSetup({ + 'beforeSend': function() { + $("#loading").show(); + }, + 'complete': function() { + $("#loading").hide(); + } + }); + + $(".coverartfancy").on("click", "a", function() { + $("a.coverartfancy").fancybox({ + beforeShow: function() { + //this.title = $('#songdetails_artist').html(); + }, + afterLoad: function() { + //this.inner.prepend( '

              1. My custom title

              ' ); + //this.content = '

              2. My custom title

              '; + }, + hideOnContentClick: true, + type: 'image', + openEffect: 'none', + closeEffect: 'none' }); - } - if (utils.getValue("SavedCollections")) { globals.SavedCollections = utils.getValue("SavedCollections").split(","); } - if (utils.getValue("SavedGenres")) { globals.SavedGenres = utils.getValue("SavedGenres").split(","); } - if (globals.settings.Debug) { console.log('Settings: ' + JSON.stringify(globals.settings, null, 2)); } - } - $scope.toggleSetting = function (setting) { - var id = setting; - if (globals.settings[id]) { - globals.settings[id] = false; - } else { - globals.settings[id] = true; - } - notifications.updateMessage(setting + ' : ' + globals.settings[id], true); - } + }); - $.ajaxSetup({ - 'beforeSend': function () { - $("#loading").show(); - }, - 'complete': function () { - $("#loading").hide(); - } - }); + var submenu_active = false; + $('div.submenu').mouseenter(function() { + submenu_active = true; + }); + $('div.submenu').mouseleave(function() { + submenu_active = false; + $('div.submenu').hide(); + //setTimeout(function () { if (submenu_active == false) $('div.submenu').stop().fadeOut(); }, 400); + }); + + $scope.toggleSubmenu = function(menu, pl, pos, margin) { + var submenu = $(menu); + if (submenu.css('display') !== 'none') { + submenu.fadeOut(); + } else { + var el = $(pl); + off = el.offset(); + width = el.width(); + height = el.height(); + switch (pos) { + case 'right': + //show the menu to the right of placeholder + submenu.css({ + "left": (off.left + margin) + "px", + "top": (off.top) + "px" + }).fadeIn(400); + break; + case 'left': + //show the menu to the right of placeholder + submenu.css({ + "left": (off.left - margin) + "px", + "top": (off.top) + "px" + }).fadeIn(400); + break; + } + setTimeout(function() { + if (submenu_active === false) $('div.submenu').stop().fadeOut(); + }, 10000); + } + }; + + $rootScope.showQueue = function() { + var submenu = $('#QueuePreview'); + submenu.fadeIn(400); + var timeout = globals.settings.Timeout; + setTimeout(function() { + submenu.fadeOut(); + }, timeout); + }; + + $rootScope.hideQueue = function() { + var submenu = $('#QueuePreview'); + submenu.fadeOut(); + }; + + $scope.toggleQueue = function() { + var submenu = $('#QueuePreview'); + if (submenu.css('display') == 'none') { + $rootScope.showQueue(); + } else { + $rootScope.hideQueue(); + } + }; - $(".coverartfancy").on("click", "a", function () { $("a.coverartfancy").fancybox({ - beforeShow: function () { + beforeShow: function() { //this.title = $('#songdetails_artist').html(); }, - afterLoad: function () { + afterLoad: function() { //this.inner.prepend( '

              1. My custom title

              ' ); //this.content = '

              2. My custom title

              '; }, @@ -81,155 +167,89 @@ function AppCtrl($scope, $rootScope, $document, $location, $cookieStore, utils, openEffect: 'none', closeEffect: 'none' }); - }); - var submenu_active = false; - $('div.submenu').mouseenter(function () { - submenu_active = true; - }); - $('div.submenu').mouseleave(function () { - submenu_active = false; - $('div.submenu').hide(); - //setTimeout(function () { if (submenu_active == false) $('div.submenu').stop().fadeOut(); }, 400); - }); - $scope.toggleSubmenu = function (menu, pl, pos, margin) { - var submenu = $(menu); - if (submenu.css('display') !== 'none') { - submenu.fadeOut(); - } else { - var el = $(pl); - off = el.offset(); - width = el.width(); - height = el.height(); - switch (pos) { - case 'right': - //show the menu to the right of placeholder - submenu.css({ "left": (off.left + margin) + "px", "top": (off.top) + "px" }).fadeIn(400); - break; - case 'left': - //show the menu to the right of placeholder - submenu.css({ "left": (off.left - margin) + "px", "top": (off.top) + "px" }).fadeIn(400); - break; - } - setTimeout(function () { if (submenu_active == false) $('div.submenu').stop().fadeOut(); }, 10000); - } - } - $rootScope.showQueue = function () { - var submenu = $('#QueuePreview'); - submenu.fadeIn(400); - var timeout = globals.settings.Timeout; - setTimeout(function () { submenu.fadeOut(); }, timeout); - } - $rootScope.hideQueue = function () { - var submenu = $('#QueuePreview'); - submenu.fadeOut(); - } - $scope.toggleQueue = function () { - var submenu = $('#QueuePreview'); - if (submenu.css('display') == 'none') { - $rootScope.showQueue(); - } else { - $rootScope.hideQueue(); - } - } - $("a.coverartfancy").fancybox({ - beforeShow: function () { - //this.title = $('#songdetails_artist').html(); - }, - afterLoad: function () { - //this.inner.prepend( '

              1. My custom title

              ' ); - //this.content = '

              2. My custom title

              '; - }, - hideOnContentClick: true, - type: 'image', - openEffect: 'none', - closeEffect: 'none' - }); - - $('#action_Welcome').fancybox({ - openEffect: 'none', - closeEffect: 'none' - }); - - $('#audiocontainer .scrubber').mouseover(function (e) { - $('.audiojs .scrubber').stop().animate({ height: '8px' }); - }); - $('#audiocontainer .scrubber').mouseout(function (e) { - $('.audiojs .scrubber').stop().animate({ height: '4px' }); - }); - - $('.message').on('click', function () { $(this).remove(); }); - - // Sway.fm Unity Plugin - $rootScope.unity = UnityMusicShim(); - $rootScope.unity.setSupports({ - playpause: true, - next: true, - previous: true - }); - $rootScope.unity.setCallbackObject({ - pause: function () { - if (globals.settings.Debug) { console.log("Unity: Recieved playpause command"); } - player.playPauseSong(); - }, - next: function () { - if (globals.settings.Debug) { console.log("Unity: Recieved next command"); } - $rootScope.nextTrack(); - }, - previous: function () { - if (globals.settings.Debug) { console.log("Unity: Recieved previous command"); } - $rootScope.previousTrack(); - } - }); - - - // JQuery UI Sortable - Drag and drop sorting - /* - var fixHelper = function (e, ui) { - ui.children().each(function () { - $(this).width($(this).width()); + $('#action_Welcome').fancybox({ + openEffect: 'none', + closeEffect: 'none' }); - return ui; - }; - $("#QueuePreview ul.songlist").sortable({ - helper: fixHelper - }); - */ - /* JQuery Layout Plugin - I don't think this is used anywhere - function resizePageLayout() { - var pageLayout = $("body").data("layout"); - if (pageLayout) pageLayout.resizeAll(); - }; - */ - // Global Functions - window.onbeforeunload = function () { - if (!globals.settings.Debug) { - if ($rootScope.queue.length > 0) { - return "You're about to end your session, are you sure?"; + $('#audiocontainer .scrubber').mouseover(function(e) { + $('.audiojs .scrubber').stop().animate({ + height: '8px' + }); + }); + $('#audiocontainer .scrubber').mouseout(function(e) { + $('.audiojs .scrubber').stop().animate({ + height: '4px' + }); + }); + + $('.message').on('click', function() { + $(this).remove(); + }); + + // Sway.fm Unity Plugin + $rootScope.unity = UnityMusicShim(); + $rootScope.unity.setSupports({ + playpause: true, + next: true, + previous: true + }); + + $rootScope.unity.setCallbackObject({ + pause: function() { + if (globals.settings.Debug) { + console.log("Unity: Recieved playpause command"); + } + player.playPauseSong(); + }, + next: function() { + if (globals.settings.Debug) { + console.log("Unity: Recieved next command"); + } + $rootScope.nextTrack(); + }, + previous: function() { + if (globals.settings.Debug) { + console.log("Unity: Recieved previous command"); + } + $rootScope.previousTrack(); } - } - } + }); - $scope.dragStart = function (e, ui) { - ui.item.data('start', ui.item.index()); - } - $scope.dragEnd = function (e, ui) { - var start = ui.item.data('start'), - end = ui.item.index(); - $rootScope.queue.splice(end, 0, - $rootScope.queue.splice(start, 1)[0]); - $scope.$apply(); - } - $document.keydown(function (e) { - $scope.scrollToIndex(e); - }); - $scope.scrollToIndex = function (e) { - var source = e.target.id; - if (source != 'Search' && source != 'Source' && source != 'Description' && source != 'ChatMsg' && source != 'AutoPlaylists') { - var unicode = e.charCode ? e.charCode : e.keyCode; - if (globals.settings.Debug) { console.log('Keycode Triggered: ' + unicode); } - /* + // Global Functions + window.onbeforeunload = function() { + if (!globals.settings.Debug) { + if ($rootScope.queue.length > 0) { + return "You're about to end your session, are you sure?"; + } + } + }; + + $scope.dragStart = function(e, ui) { + ui.item.data('start', ui.item.index()); + }; + + $scope.dragEnd = function(e, ui) { + var start = ui.item.data('start'), + end = ui.item.index(); + $rootScope.queue.splice(end, 0, + $rootScope.queue.splice(start, 1)[0]); + $scope.$apply(); + }; + + $document.keydown(function(e) { + $scope.scrollToIndex(e); + }); + + $scope.scrollToIndex = function(e) { + var source = e.target.id; + if (source != 'Search' && source != 'Source' && source != 'Description' && source != 'ChatMsg' && source != 'AutoPlaylists') { + var unicode = e.charCode ? e.charCode : e.keyCode; + if (globals.settings.Debug) { + console.log('Keycode Triggered: ' + unicode); + } + /* if (unicode == 49) { utils.changeTab('tabQueue'); } else if (unicode == 50) { @@ -244,329 +264,343 @@ function AppCtrl($scope, $rootScope, $document, $location, $cookieStore, utils, utils.changeTab('tabSettings'); } */ - if (unicode >= 65 && unicode <= 90 && $('#tabLibrary').is(':visible')) { // a-z - var key = utils.findKeyForCode(unicode); - if (key == 'x' || key == 'y' || key == 'z') { - key = 'x-z'; + if (unicode >= 65 && unicode <= 90 && $('#tabLibrary').is(':visible')) { // a-z + var key = utils.findKeyForCode(unicode); + if (key == 'x' || key == 'y' || key == 'z') { + key = 'x-z'; + } + var el = '#' + key.toUpperCase(); + if ($(el).length > 0) { + $('#left-component').stop().scrollTo(el, 400); + } + } else if (unicode == 39 || unicode == 176) { // right arrow + $rootScope.nextTrack(); + } else if (unicode == 37 || unicode == 177) { // back arrow + $rootScope.previousTrack(); + } else if (unicode == 32 || unicode == 179 || unicode.toString() == '0179') { // spacebar + player.playPauseSong(); + return false; + } else if (unicode == 36 && $('#tabLibrary').is(':visible')) { // home + $('#left-component').stop().scrollTo('#MusicFolders', 400); } - var el = '#' + key.toUpperCase(); - if ($(el).length > 0) { - $('#left-component').stop().scrollTo(el, 400); + + var volume; + + if (unicode == 189) { // dash - volume down + volume = utils.getValue('Volume') ? parseFloat(utils.getValue('Volume')) : 1; + if (volume <= 1 && volume > 0 && source === '') { + volume += -0.1; + $(player1).jPlayer({ + volume: volume + }); + utils.setValue('Volume', volume, true); + //updateMessage('Volume: ' + Math.round(volume * 100) + '%'); + } } - } else if (unicode == 39 || unicode == 176) { // right arrow - $rootScope.nextTrack(); - } else if (unicode == 37 || unicode == 177) { // back arrow - $rootScope.previousTrack(); - } else if (unicode == 32 || unicode == 179 || unicode.toString() == '0179') { // spacebar - player.playPauseSong(); - return false; - } else if (unicode == 36 && $('#tabLibrary').is(':visible')) { // home - $('#left-component').stop().scrollTo('#MusicFolders', 400); - } - if (unicode == 189) { // dash - volume down - var volume = utils.getValue('Volume') ? parseFloat(utils.getValue('Volume')) : 1; - if (volume <= 1 && volume > 0 && source == '') { - volume += -.1; - $(player1).jPlayer({ - volume: volume - }); - utils.setValue('Volume', volume, true); - //updateMessage('Volume: ' + Math.round(volume * 100) + '%'); + + if (unicode == 187) { // equals - volume up + volume = utils.getValue('Volume') ? parseFloat(utils.getValue('Volume')) : 1; + if (volume < 1 && volume >= 0 && source === '') { + volume += 0.1; + $(player1).jPlayer({ + volume: volume + }); + utils.setValue('Volume', volume, true); + //updateMessage('Volume: ' + Math.round(volume * 100) + '%'); + } } } - if (unicode == 187) { // equals - volume up - var volume = utils.getValue('Volume') ? parseFloat(utils.getValue('Volume')) : 1; - if (volume < 1 && volume >= 0 && source == '') { - volume += .1; - $(player1).jPlayer({ - volume: volume - }); - utils.setValue('Volume', volume, true); - //updateMessage('Volume: ' + Math.round(volume * 100) + '%'); - } + return true; + }; + + $scope.scrollToIndexName = function(index) { + var el = '#' + index; + if ($(el).length > 0) { + $('#left-component').stop().scrollTo(el, 400); } - } - return true; - }; - $scope.scrollToIndexName = function (index) { - var el = '#' + index; - if ($(el).length > 0) { - $('#left-component').stop().scrollTo(el, 400); - } - }; - $scope.scrollToTop = function () { - $('#Artists').stop().scrollTo('#auto', 400); - } - $scope.selectAll = function () { - angular.forEach($rootScope.song, function (item, key) { - $scope.selectedSongs.push(item); - item.selected = true; - }); - } - $scope.playAll = function () { - $rootScope.queue = []; - $scope.selectAll(); - $scope.addSongsToQueue(); - var next = $rootScope.queue[0]; - $rootScope.playSong(false, next); - } - $scope.selectNone = function () { - angular.forEach($rootScope.song, function (item, key) { - $scope.selectedSongs = []; - item.selected = false; - }); - } - $scope.addSongsToQueue = function () { - if ($scope.selectedSongs.length !== 0) { - angular.forEach($scope.selectedSongs, function (item, key) { - $scope.queue.push(item); + }; + + $scope.scrollToTop = function() { + $('#Artists').stop().scrollTo('#auto', 400); + }; + + $scope.selectAll = function() { + angular.forEach($rootScope.song, function(item, key) { + $scope.selectedSongs.push(item); + item.selected = true; + }); + }; + + $scope.playAll = function() { + $rootScope.queue = []; + $scope.selectAll(); + $scope.addSongsToQueue(); + var next = $rootScope.queue[0]; + $rootScope.playSong(false, next); + }; + + $scope.selectNone = function() { + angular.forEach($rootScope.song, function(item, key) { + $scope.selectedSongs = []; item.selected = false; }); - $rootScope.showQueue(); - notifications.updateMessage($scope.selectedSongs.length + ' Song(s) Added to Queue', true); - $scope.selectedSongs.length = 0; - } - } - $scope.isActive = function (route) { - return route === $location.path(); - }; - $scope.getMusicFolders = function () { - $.ajax({ - url: globals.BaseURL() + '/getMusicFolders.view?' + globals.BaseParams(), - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - if (data["subsonic-response"].musicFolders.musicFolder !== undefined) { - var folders = []; - if (data["subsonic-response"].musicFolders.musicFolder.length > 0) { - folders = data["subsonic-response"].musicFolders.musicFolder; - } else { - folders[0] = data["subsonic-response"].musicFolders.musicFolder; - } + }; - $rootScope.MusicFolders = folders; - if (utils.getValue('MusicFolders')) { - var folder = angular.fromJson(utils.getValue('MusicFolders')); - var i = 0, index = ""; - angular.forEach($rootScope.MusicFolders, function (item, key) { - if (item.id == folder.id) { - index = i; - } - i++; - }); - $rootScope.SelectedMusicFolder = $rootScope.MusicFolders[index]; - } - $scope.$apply(); - } + $scope.addSongsToQueue = function() { + if ($scope.selectedSongs.length !== 0) { + angular.forEach($scope.selectedSongs, function(item, key) { + $scope.queue.push(item); + item.selected = false; + }); + $rootScope.showQueue(); + notifications.updateMessage($scope.selectedSongs.length + ' Song(s) Added to Queue', true); + $scope.selectedSongs.length = 0; } - }); - } - $scope.getGenres = function () { - var genres = 'Acid Rock,Acoustic,Alt Country,Alt/Indie,Alternative & Punk,Alternative Metal,Alternative,AlternRock,Awesome,Bluegrass,Blues,Blues-Rock,Classic Hard Rock,Classic Rock,Comedy,Country,Country-Rock,Dance,Dance-Rock,Deep Funk,Easy Listening,Electronic,Electronica,Electronica/Dance,Folk,Folk/Rock,Funk,Grunge,Hard Rock,Heavy Metal,Holiday,House,Improg,Indie Rock,Indie,International,Irish,Jam Band,Jam,Jazz Fusion,Jazz,Latin,Live Albums,Metal,Music,Oldies,Other,Pop,Pop/Rock,Post Rock,Progressive Rock,Psychedelic Rock,Psychedelic,Punk,R&B,Rap & Hip-Hop,Reggae,Rock & Roll,Rock,Rock/Pop,Roots,Ska,Soft Rock,Soul,Southern Rock,Thrash Metal,Unknown,Vocal,World'; - $rootScope.Genres = genres.split(','); - /* This is broken in version 4.8, unable to convert XML to JSON - $.ajax({ - url: globals.BaseURL() + '/getGenres.view?' + globals.BaseParams(), - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - if (typeof data["subsonic-response"].genres != 'undefined') { - var items = []; - if (data["subsonic-response"].genres.length > 0) { - items = data["subsonic-response"].genres; - } else { - items[0] = data["subsonic-response"].genres; - } + }; - $rootScope.Genres = items; - $scope.$apply(); - } - } - }); - */ - } - $scope.download = function (id) { - $.ajax({ - url: globals.BaseURL() + '/getUser.view?' + globals.BaseParams() + '&username=' + globals.settings.Username, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - if (typeof data["subsonic-response"].error != 'undefined') { - notifications.updateMessage('Error: ' + data["subsonic-response"].error.message, true); - } else { - if (data["subsonic-response"].user.downloadRole == true) { - $window.location.href = globals.BaseURL() + '/download.view?' + globals.BaseParams() + '&id=' + id; - } else { - notifications.updateMessage('You do not have permission to Download', true); + $scope.isActive = function(route) { + return route === $location.path(); + }; + + $scope.getMusicFolders = function() { + $.ajax({ + url: globals.BaseURL() + '/getMusicFolders.view?' + globals.BaseParams(), + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + if (data["subsonic-response"].musicFolders.musicFolder !== undefined) { + var folders = []; + if (data["subsonic-response"].musicFolders.musicFolder.length > 0) { + folders = data["subsonic-response"].musicFolders.musicFolder; + } else { + folders[0] = data["subsonic-response"].musicFolders.musicFolder; + } + + $rootScope.MusicFolders = folders; + if (utils.getValue('MusicFolders')) { + var folder = angular.fromJson(utils.getValue('MusicFolders')); + var i = 0, + index = ""; + angular.forEach($rootScope.MusicFolders, function(item, key) { + if (item.id == folder.id) { + index = i; + } + i++; + }); + $rootScope.SelectedMusicFolder = $rootScope.MusicFolders[index]; + } + $scope.$apply(); } } - } - }); - } - $scope.ping = function () { - $.ajax({ - url: globals.BaseURL() + '/ping.view?' + globals.BaseParams(), - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - if (data["subsonic-response"].status == 'ok') { - globals.settings.ApiVersion = data["subsonic-response"].version; - } else { + }); + }; + + $scope.getGenres = function() { + var genres = 'Acid Rock,Acoustic,Alt Country,Alt/Indie,Alternative & Punk,Alternative Metal,Alternative,AlternRock,Awesome,Bluegrass,Blues,Blues-Rock,Classic Hard Rock,Classic Rock,Comedy,Country,Country-Rock,Dance,Dance-Rock,Deep Funk,Easy Listening,Electronic,Electronica,Electronica/Dance,Folk,Folk/Rock,Funk,Grunge,Hard Rock,Heavy Metal,Holiday,House,Improg,Indie Rock,Indie,International,Irish,Jam Band,Jam,Jazz Fusion,Jazz,Latin,Live Albums,Metal,Music,Oldies,Other,Pop,Pop/Rock,Post Rock,Progressive Rock,Psychedelic Rock,Psychedelic,Punk,R&B,Rap & Hip-Hop,Reggae,Rock & Roll,Rock,Rock/Pop,Roots,Ska,Soft Rock,Soul,Southern Rock,Thrash Metal,Unknown,Vocal,World'; + $rootScope.Genres = genres.split(','); + // TODO: fix this + }; + + $scope.download = function(id) { + $.ajax({ + url: globals.BaseURL() + '/getUser.view?' + globals.BaseParams() + '&username=' + globals.settings.Username, + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { if (typeof data["subsonic-response"].error != 'undefined') { - notifications.updateMessage(data["subsonic-response"].error.message); + notifications.updateMessage('Error: ' + data["subsonic-response"].error.message, true); + } else { + if (data["subsonic-response"].user.downloadRole === true) { + $window.location.href = globals.BaseURL() + '/download.view?' + globals.BaseParams() + '&id=' + id; + } else { + notifications.updateMessage('You do not have permission to Download', true); + } } } - }, - error: function () { - notifications.updateMessage('Unable to connect to Subsonic server'); - } - }); - } - $scope.addSongToQueue = function (data) { - $rootScope.queue.push(data); - } - $scope.queueRemoveSelected = function (data, event) { - angular.forEach($scope.selectedSongs, function (item, key) { - var index = $rootScope.queue.indexOf(item); - if (index > -1) { - $rootScope.queue.splice(index, 1); - } - }); - } - $scope.queueEmpty = function () { - //self.selectedSongs([]); - $rootScope.queue = []; - } - $scope.queueTotal = function () { - var total = 0; - ko.utils.arrayForEach(self.queue(), function (item) { - total += parseInt(item.duration()); - }); - if (self.queue().length > 0) { - return self.queue().length + ' song(s), ' + utils.secondsToTime(total) + ' total time'; - } else { - return '0 song(s), 00:00:00 total time'; - } - } - $scope.queueShuffle = function () { - $rootScope.queue.sort(function () { return 0.5 - Math.random() }); - } - $scope.selectedSongs = []; - $scope.selectSong = function (data) { - var i = $scope.selectedSongs.indexOf(data); - if (i >= 0) { - $scope.selectedSongs.splice(i, 1); - data.selected = false; - } else { - $scope.selectedSongs.push(data); - data.selected = true; - } - //$scope.$apply(); - } - $rootScope.getRandomSongs = function (action, genre, folder) { - if (globals.settings.Debug) { console.log('action:' + action + ', genre:' + genre + ', folder:' + folder); } - var size = globals.settings.AutoPlaylistSize; - $rootScope.selectedPlaylist = null; - if (typeof folder == 'number') { - $rootScope.selectedAutoPlaylist = folder; - } else if (genre != '') { - $rootScope.selectedAutoPlaylist = genre; - } else { - $rootScope.selectedAutoPlaylist = 'random'; - } - var genreParams = ''; - if (genre != '' && genre != 'Random') { - genreParams = '&genre=' + genre; - } - folderParams = ''; - if (typeof folder == 'number' && folder != '' && folder != 'all') { - //alert(folder); - folderParams = '&musicFolderId=' + folder; - } else if (typeof $rootScope.SelectedMusicFolder.id != 'undefined') { - //alert($rootScope.SelectedMusicFolder.id); - folderParams = '&musicFolderId=' + $rootScope.SelectedMusicFolder.id; - } - $.ajax({ - url: globals.BaseURL() + '/getRandomSongs.view?' + globals.BaseParams() + '&size=' + size + genreParams + folderParams, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - if (typeof data["subsonic-response"].randomSongs.song != 'undefined') { - var items = []; - if (data["subsonic-response"].randomSongs.song.length > 0) { - items = data["subsonic-response"].randomSongs.song; - } else { - items[0] = data["subsonic-response"].randomSongs.song; - } - if (action == 'add') { - angular.forEach(items, function (item, key) { - $rootScope.queue.push(utils.mapSong(item)); - }); - $scope.$apply(); - $rootScope.showQueue(); - notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); - } else if (action == 'play') { - $rootScope.queue = []; - angular.forEach(items, function (item, key) { - $rootScope.queue.push(utils.mapSong(item)); - }); - var next = $rootScope.queue[0]; - $scope.$apply(function () { - $rootScope.playSong(false, next); - }); - $rootScope.showQueue(); - notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); - } else { - $rootScope.song = []; - angular.forEach(items, function (item, key) { - $rootScope.song.push(utils.mapSong(item)); - }); - $scope.$apply(); - } - } - } - }); - } - $scope.updateFavorite = function (item) { - var id = item.id; - var starred = item.starred; - var url; - if (starred) { - url = globals.BaseURL() + '/unstar.view?' + globals.BaseParams() + '&id=' + id; - item.starred = undefined; - } else { - url = globals.BaseURL() + '/star.view?' + globals.BaseParams() + '&id=' + id; - item.starred = true; - } - $.ajax({ - url: url, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function () { - notifications.updateMessage('Favorite Updated!', true); - } - }); - } - $scope.toTrusted = function (html) { - return $sce.trustAsHtml(html); - } + }); + }; - /* Launch on Startup */ - $scope.loadSettings(); - utils.switchTheme(globals.settings.Theme); - if ($scope.loggedIn()) { - $scope.ping(); - $scope.getMusicFolders(); - if (globals.settings.SaveTrackPosition) { - player.loadTrackPosition(); - player.startSaveTrackPosition(); + $scope.ping = function() { + $.ajax({ + url: globals.BaseURL() + '/ping.view?' + globals.BaseParams(), + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + if (data["subsonic-response"].status == 'ok') { + globals.settings.ApiVersion = data["subsonic-response"].version; + } else { + if (typeof data["subsonic-response"].error != 'undefined') { + notifications.updateMessage(data["subsonic-response"].error.message); + } + } + }, + error: function() { + notifications.updateMessage('Unable to connect to Subsonic server'); + } + }); + }; + + $scope.addSongToQueue = function(data) { + $rootScope.queue.push(data); + }; + + $scope.queueRemoveSelected = function(data, event) { + angular.forEach($scope.selectedSongs, function(item, key) { + var index = $rootScope.queue.indexOf(item); + if (index > -1) { + $rootScope.queue.splice(index, 1); + } + }); + }; + + $scope.queueEmpty = function() { + //self.selectedSongs([]); + $rootScope.queue = []; + }; + + $scope.queueTotal = function() { + var total = 0; + ko.utils.arrayForEach(self.queue(), function(item) { + total += parseInt(item.duration()); + }); + if (self.queue().length > 0) { + return self.queue().length + ' song(s), ' + utils.secondsToTime(total) + ' total time'; + } else { + return '0 song(s), 00:00:00 total time'; + } + }; + + $scope.queueShuffle = function() { + $rootScope.queue.sort(function() { + return 0.5 - Math.random(); + }); + }; + + $scope.selectedSongs = []; + $scope.selectSong = function(data) { + var i = $scope.selectedSongs.indexOf(data); + if (i >= 0) { + $scope.selectedSongs.splice(i, 1); + data.selected = false; + } else { + $scope.selectedSongs.push(data); + data.selected = true; + } + //$scope.$apply(); + }; + + $rootScope.getRandomSongs = function(action, genre, folder) { + if (globals.settings.Debug) { + console.log('action:' + action + ', genre:' + genre + ', folder:' + folder); + } + var size = globals.settings.AutoPlaylistSize; + $rootScope.selectedPlaylist = null; + if (typeof folder == 'number') { + $rootScope.selectedAutoPlaylist = folder; + } else if (genre !== '') { + $rootScope.selectedAutoPlaylist = genre; + } else { + $rootScope.selectedAutoPlaylist = 'random'; + } + + var genreParams = ''; + + if (genre !== '' && genre != 'Random') { + genreParams = '&genre=' + genre; + } + + folderParams = ''; + + if (typeof folder == 'number' && folder !== '' && folder != 'all') { + //alert(folder); + folderParams = '&musicFolderId=' + folder; + } else if (typeof $rootScope.SelectedMusicFolder.id != 'undefined') { + //alert($rootScope.SelectedMusicFolder.id); + folderParams = '&musicFolderId=' + $rootScope.SelectedMusicFolder.id; + } + + $.ajax({ + url: globals.BaseURL() + '/getRandomSongs.view?' + globals.BaseParams() + '&size=' + size + genreParams + folderParams, + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + if (typeof data["subsonic-response"].randomSongs.song != 'undefined') { + var items = []; + if (data["subsonic-response"].randomSongs.song.length > 0) { + items = data["subsonic-response"].randomSongs.song; + } else { + items[0] = data["subsonic-response"].randomSongs.song; + } + if (action == 'add') { + angular.forEach(items, function(item, key) { + $rootScope.queue.push(utils.mapSong(item)); + }); + $scope.$apply(); + $rootScope.showQueue(); + notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); + } else if (action == 'play') { + $rootScope.queue = []; + angular.forEach(items, function(item, key) { + $rootScope.queue.push(utils.mapSong(item)); + }); + var next = $rootScope.queue[0]; + $scope.$apply(function() { + $rootScope.playSong(false, next); + }); + $rootScope.showQueue(); + notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); + } else { + $rootScope.song = []; + angular.forEach(items, function(item, key) { + $rootScope.song.push(utils.mapSong(item)); + }); + $scope.$apply(); + } + } + } + }); + }; + + $scope.updateFavorite = function(item) { + var id = item.id; + var starred = item.starred; + var url; + if (starred) { + url = globals.BaseURL() + '/unstar.view?' + globals.BaseParams() + '&id=' + id; + item.starred = undefined; + } else { + url = globals.BaseURL() + '/star.view?' + globals.BaseParams() + '&id=' + id; + item.starred = true; + } + $.ajax({ + url: url, + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function() { + notifications.updateMessage('Favorite Updated!', true); + } + }); + }; + + $scope.toTrusted = function(html) { + return $sce.trustAsHtml(html); + }; + + /* Launch on Startup */ + $scope.loadSettings(); + utils.switchTheme(globals.settings.Theme); + if ($scope.loggedIn()) { + $scope.ping(); + $scope.getMusicFolders(); + if (globals.settings.SaveTrackPosition) { + player.loadTrackPosition(); + player.startSaveTrackPosition(); + } } - } - /* End Startup */ -}); \ No newline at end of file + /* End Startup */ + }); diff --git a/js/controllers/partial.js b/js/controllers/partial.js deleted file mode 100644 index 9485f88..0000000 --- a/js/controllers/partial.js +++ /dev/null @@ -1,52 +0,0 @@ -JamStash.controller('PartialCtrl', -function PartialCtrl($scope, $rootScope, $location, $window, $routeParams, utils, globals) { - //$("#SubsonicAlbums").layout($scope.layoutThreeCol); - - $scope.song = []; - $scope.itemType = 'ss'; - $scope.index = []; - $scope.shortcut = []; - $scope.album = []; - $scope.Server = globals.settings.Server; - - $scope.getSongs = function (id) { - var url = globals.BaseURL() + '/getMusicDirectory.view?' + globals.BaseParams() + '&id=' + id; - $.ajax({ - url: url, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - var items = []; - if (typeof data["subsonic-response"].directory.child != 'undefined') { - if (data["subsonic-response"].directory.child.length > 0) { - items = data["subsonic-response"].directory.child; - } else { - items[0] = data["subsonic-response"].directory.child; - } - $scope.song = []; - var albums = []; - angular.forEach(items, function (item, key) { - if (item.isDir) { - //albums.push($scope.mapAlbum(item)); - } else { - $rootScope.song.push(utils.mapSong(item)); - } - }); - //$location.path('/library/0/' + id); - $scope.$apply(); - } else { - notifications.updateMessage('No Songs Returned :(', true); - } - } - }); - }; - - - - /* Launch on Startup */ - if ($routeParams.albumId) { - $scope.getSongs($routeParams.albumId); - } - /* End Startup */ -}); diff --git a/js/controllers/playlists.js b/js/controllers/playlists.js index 45dae5d..2fc8453 100644 --- a/js/controllers/playlists.js +++ b/js/controllers/playlists.js @@ -1,231 +1,244 @@ JamStash.controller('PlaylistCtrl', -function PlaylistCtrl($scope, $rootScope, $location, utils, globals, model, notifications) { - //$("#left-component").layout($scope.layoutTwoCol); + function PlaylistCtrl($scope, $rootScope, $location, utils, globals, model, notifications) { - $rootScope.song = []; - $scope.itemType = 'pl'; - $scope.playlists = []; - $scope.playlistsPublic = []; - $scope.playlistsGenre = globals.SavedGenres; - $scope.selectedGenre; - $scope.$watch("selectedGenre", function (newValue, oldValue) { - if (newValue !== oldValue) { - globals.SavedGenres.push(newValue); - //$scope.playlistsGenre.push(); - utils.setValue('SavedGenres', globals.SavedGenres.join(), false); - } - }); - $scope.getPlaylists = function (refresh) { - if (globals.settings.Debug) { console.log("LOAD PLAYLISTS"); } - $.ajax({ - url: globals.BaseURL() + '/getPlaylists.view?' + globals.BaseParams(), - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - if (data["subsonic-response"].playlists.playlist !== undefined) { - var items = []; - if (data["subsonic-response"].playlists.playlist.length > 0) { - items = data["subsonic-response"].playlists.playlist; - } else { - items[0] = data["subsonic-response"].playlists.playlist; - } - angular.forEach(items, function (item, key) { - if (item.owner == globals.settings.Username) { - $scope.playlists.push(item); - } else if (item.public) { - $scope.playlistsPublic.push(item); - } - }); - $scope.$apply(); - } + $rootScope.song = []; + $scope.itemType = 'pl'; + $scope.playlists = []; + $scope.playlistsPublic = []; + $scope.playlistsGenre = globals.SavedGenres; + $scope.selectedGenre = null; + + $scope.$watch("selectedGenre", function(newValue, oldValue) { + if (newValue !== oldValue) { + globals.SavedGenres.push(newValue); + //$scope.playlistsGenre.push(); + utils.setValue('SavedGenres', globals.SavedGenres.join(), false); } }); - } - $scope.getPlaylist = function (id, action) { - $rootScope.selectedAutoPlaylist = null; - $rootScope.selectedPlaylist = id; - $.ajax({ - url: globals.BaseURL() + '/getPlaylist.view?' + globals.BaseParams() + '&id=' + id, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - if (typeof data["subsonic-response"].playlist.entry != 'undefined') { - var items = []; - var playlist = data["subsonic-response"].playlist; - if (playlist.entry.length > 0) { - items = playlist.entry; - } else { - items[0] = playlist.entry; - } - if (action == 'add') { - angular.forEach(items, function (item, key) { - $rootScope.queue.push(utils.mapSong(item)); - }); - $scope.$apply(); - $rootScope.showQueue(); - notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); - } else if (action == 'play') { - $rootScope.queue = []; - angular.forEach(items, function (item, key) { - $rootScope.queue.push(utils.mapSong(item)); - }); - var next = $rootScope.queue[0]; - $scope.$apply(function () { - $rootScope.playSong(false, next); - }); - $rootScope.showQueue(); - notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); - } else { - $scope.album = []; - $rootScope.song = []; - angular.forEach(items, function (item, key) { - $rootScope.song.push(utils.mapSong(item)); - }); - $scope.$apply(); - } - } else { - $rootScope.song = []; - } + + $scope.getPlaylists = function(refresh) { + if (globals.settings.Debug) { + console.log("LOAD PLAYLISTS"); } - }); - } - $scope.getStarred = function (action, type) { - var size = globals.settings.AutoPlaylistSize; - $rootScope.selectedPlaylist = null; - $rootScope.selectedAutoPlaylist = 'starred'; - $.ajax({ - url: globals.BaseURL() + '/getStarred.view?' + globals.BaseParams() + '&size=' + size, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - if (typeof data["subsonic-response"].starred !== 'undefined') { - var items = []; - switch (type) { - case 'artist': - if (typeof data["subsonic-response"].starred.artist !== 'undefined') { - if (data["subsonic-response"].starred.artist.length > 0) { - items = data["subsonic-response"].starred.artist; - } else { - items[0] = data["subsonic-response"].starred.artist; - } - } - break; - case 'album': - if (typeof data["subsonic-response"].starred.album !== 'undefined') { - if (data["subsonic-response"].starred.album.length > 0) { - items = data["subsonic-response"].starred.album; - } else { - items[0] = data["subsonic-response"].starred.album; - } - } - break; - case 'song': - if (typeof data["subsonic-response"].starred.song !== 'undefined') { - if (data["subsonic-response"].starred.song.length > 0) { - items = data["subsonic-response"].starred.song; - } else { - items[0] = data["subsonic-response"].starred.song; - } - if (action == 'add') { - angular.forEach(items, function (item, key) { - $rootScope.queue.push(utils.mapSong(item)); - }); - $scope.$apply(); - $rootScope.showQueue(); - notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); - } else if (action == 'play') { - $rootScope.queue = []; - angular.forEach(items, function (item, key) { - $rootScope.queue.push(utils.mapSong(item)); - }); - var next = $rootScope.queue[0]; - $scope.$apply(function () { - $rootScope.playSong(false, next); - }); - $rootScope.showQueue(); - notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); - } else { - $rootScope.song = []; - angular.forEach(items, function (item, key) { - $rootScope.song.push(utils.mapSong(item)); - }); - $scope.$apply(); - } - } - break; - default: - break; - } - } - } - }); - } - $scope.newPlaylist = function (data, event) { - var reply = prompt("Choose a name for your new playlist.", ""); - if (reply != 'null' && reply != null && reply != '') { $.ajax({ - url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams() + '&name=' + reply, + url: globals.BaseURL() + '/getPlaylists.view?' + globals.BaseParams(), method: 'GET', dataType: globals.settings.Protocol, timeout: globals.settings.Timeout, - success: function (data) { - loadPlaylists(true); + success: function(data) { + if (data["subsonic-response"].playlists.playlist !== undefined) { + var items = []; + if (data["subsonic-response"].playlists.playlist.length > 0) { + items = data["subsonic-response"].playlists.playlist; + } else { + items[0] = data["subsonic-response"].playlists.playlist; + } + angular.forEach(items, function(item, key) { + if (item.owner == globals.settings.Username) { + $scope.playlists.push(item); + } else if (item.public) { + $scope.playlistsPublic.push(item); + } + }); + $scope.$apply(); + } } }); - } - } - $scope.deletePlaylist = function () { - if ($rootScope.selectedPlaylist != null) { - var id = $rootScope.selectedPlaylist; - if (utils.confirmDelete('Are you sure you want to delete the selected playlist?')) { + }; + + $scope.getPlaylist = function(id, action) { + $rootScope.selectedAutoPlaylist = null; + $rootScope.selectedPlaylist = id; + $.ajax({ + url: globals.BaseURL() + '/getPlaylist.view?' + globals.BaseParams() + '&id=' + id, + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + if (typeof data["subsonic-response"].playlist.entry != 'undefined') { + var items = []; + var playlist = data["subsonic-response"].playlist; + if (playlist.entry.length > 0) { + items = playlist.entry; + } else { + items[0] = playlist.entry; + } + if (action == 'add') { + angular.forEach(items, function(item, key) { + $rootScope.queue.push(utils.mapSong(item)); + }); + $scope.$apply(); + $rootScope.showQueue(); + notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); + } else if (action == 'play') { + $rootScope.queue = []; + angular.forEach(items, function(item, key) { + $rootScope.queue.push(utils.mapSong(item)); + }); + var next = $rootScope.queue[0]; + $scope.$apply(function() { + $rootScope.playSong(false, next); + }); + $rootScope.showQueue(); + notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); + } else { + $scope.album = []; + $rootScope.song = []; + angular.forEach(items, function(item, key) { + $rootScope.song.push(utils.mapSong(item)); + }); + $scope.$apply(); + } + } else { + $rootScope.song = []; + } + } + }); + }; + + $scope.getStarred = function(action, type) { + var size = globals.settings.AutoPlaylistSize; + $rootScope.selectedPlaylist = null; + $rootScope.selectedAutoPlaylist = 'starred'; + $.ajax({ + url: globals.BaseURL() + '/getStarred.view?' + globals.BaseParams() + '&size=' + size, + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + if (typeof data["subsonic-response"].starred !== 'undefined') { + var items = []; + switch (type) { + case 'artist': + if (typeof data["subsonic-response"].starred.artist !== 'undefined') { + if (data["subsonic-response"].starred.artist.length > 0) { + items = data["subsonic-response"].starred.artist; + } else { + items[0] = data["subsonic-response"].starred.artist; + } + } + break; + case 'album': + if (typeof data["subsonic-response"].starred.album !== 'undefined') { + if (data["subsonic-response"].starred.album.length > 0) { + items = data["subsonic-response"].starred.album; + } else { + items[0] = data["subsonic-response"].starred.album; + } + } + break; + case 'song': + if (typeof data["subsonic-response"].starred.song !== 'undefined') { + if (data["subsonic-response"].starred.song.length > 0) { + items = data["subsonic-response"].starred.song; + } else { + items[0] = data["subsonic-response"].starred.song; + } + if (action == 'add') { + angular.forEach(items, function(item, key) { + $rootScope.queue.push(utils.mapSong(item)); + }); + $scope.$apply(); + $rootScope.showQueue(); + notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); + } else if (action == 'play') { + $rootScope.queue = []; + angular.forEach(items, function(item, key) { + $rootScope.queue.push(utils.mapSong(item)); + }); + var next = $rootScope.queue[0]; + $scope.$apply(function() { + $rootScope.playSong(false, next); + }); + $rootScope.showQueue(); + notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); + } else { + $rootScope.song = []; + angular.forEach(items, function(item, key) { + $rootScope.song.push(utils.mapSong(item)); + }); + $scope.$apply(); + } + } + break; + default: + break; + } + } + } + }); + }; + + $scope.newPlaylist = function(data, event) { + var reply = prompt("Choose a name for your new playlist.", ""); + if (reply !== 'null' && reply !== null && reply !== '') { $.ajax({ - url: globals.BaseURL() + '/deletePlaylist.view?' + globals.BaseParams() + '&id=' + id, + url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams() + '&name=' + reply, method: 'GET', dataType: globals.settings.Protocol, timeout: globals.settings.Timeout, - success: function (data) { - $scope.getPlaylists(); + success: function(data) { + loadPlaylists(true); } }); } - } - } - $scope.savePlaylist = function () { - if ($rootScope.selectedPlaylist() != null) { - var id = $rootScope.selectedPlaylist().id(); - var songs = []; - ko.utils.arrayForEach($rootScope.song(), function (item) { - songs.push(item.id); - }); - if (songs.length > 0) { - $.ajax({ - type: 'GET', - url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams(), - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - data: { playlistId: id, songId: songs }, - success: function () { - $scope.getPlaylist(id); - notifications.updateMessage('Playlist Updated!', true); - }, - traditional: true // Fixes POST with an array in JQuery 1.4 - }); - } - } - } - $scope.removeSelectedSongs = function (data, event) { - ko.utils.arrayForEach($scope.selectedSongs(), function (item) { - $rootScope.song.remove(item); - }); - } - /* End Playlists */ + }; - /* Launch on Startup */ - $scope.getPlaylists(); - //$scope.getMusicFolders(); - $scope.getGenres(); - /* End Startup */ -}); \ No newline at end of file + $scope.deletePlaylist = function() { + if ($rootScope.selectedPlaylist !== null) { + var id = $rootScope.selectedPlaylist; + if (utils.confirmDelete('Are you sure you want to delete the selected playlist?')) { + $.ajax({ + url: globals.BaseURL() + '/deletePlaylist.view?' + globals.BaseParams() + '&id=' + id, + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + $scope.getPlaylists(); + } + }); + } + } + }; + + $scope.savePlaylist = function() { + if ($rootScope.selectedPlaylist() !== null) { + var id = $rootScope.selectedPlaylist().id(); + var songs = []; + ko.utils.arrayForEach($rootScope.song(), function(item) { + songs.push(item.id); + }); + if (songs.length > 0) { + $.ajax({ + type: 'GET', + url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams(), + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + data: { + playlistId: id, + songId: songs + }, + success: function() { + $scope.getPlaylist(id); + notifications.updateMessage('Playlist Updated!', true); + }, + traditional: true // Fixes POST with an array in JQuery 1.4 + }); + } + } + }; + + $scope.removeSelectedSongs = function(data, event) { + ko.utils.arrayForEach($scope.selectedSongs(), function(item) { + $rootScope.song.remove(item); + }); + }; + + /* End Playlists */ + + /* Launch on Startup */ + $scope.getPlaylists(); + //$scope.getMusicFolders(); + $scope.getGenres(); + /* End Startup */ + }); diff --git a/js/controllers/podcasts.js b/js/controllers/podcasts.js index 568fc92..8244aad 100644 --- a/js/controllers/podcasts.js +++ b/js/controllers/podcasts.js @@ -1,112 +1,142 @@ JamStash.controller('PodcastCtrl', -function PodcastCtrl($scope, $rootScope, $location, utils, globals, model, notifications) { - //$("#left-component").layout($scope.layoutTwoCol); + function PodcastCtrl($scope, $rootScope, $location, utils, globals, model, notifications) { - $rootScope.song = []; - $scope.podcasts = []; - $scope.selectedPodcast; - $scope.getPodcasts = function (refresh) { - if (globals.settings.Debug) { console.log("LOAD PODCASTS"); } - $.ajax({ - url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(), - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - if (data["subsonic-response"].podcasts.channel !== undefined) { - var items = []; - if (data["subsonic-response"].podcasts.channel.length > 0) { - items = data["subsonic-response"].podcasts.channel; - } else { - items[0] = data["subsonic-response"].podcasts.channel; - } - $scope.podcasts = items; - $scope.$apply(); - } - } - }); - } - $scope.getPodcast = function (id, action) { - $scope.selectedPodcast = id; - var map = function (data) { - var song = data; - var url, track, rating, starred, contenttype, suffix, description; - var specs = '', coverartthumb = '', coverartfull = ''; - if (typeof song.coverArt != 'undefined') { - coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=60&id=' + song.coverArt; - coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + song.coverArt; - } - if (typeof song.description == 'undefined') { description = ''; } else { description = song.description; } - if (typeof song.track == 'undefined') { track = ' '; } else { track = song.track; } - if (typeof song.starred !== 'undefined') { starred = true; } else { starred = false; } - if (song.bitRate !== undefined) { specs += song.bitRate + ' Kbps'; } - if (song.transcodedSuffix !== undefined) { specs += ', transcoding:' + song.suffix + ' > ' + song.transcodedSuffix; } else { specs += ', ' + song.suffix; } - if (song.transcodedSuffix !== undefined) { suffix = song.transcodedSuffix; } else { suffix = song.suffix; } - if (suffix == 'ogg') { suffix = 'oga'; } - var salt = Math.floor(Math.random() * 100000); - url = globals.BaseURL() + '/stream.view?' + globals.BaseParams() + '&id=' + song.streamId + '&salt=' + salt; - return new model.Song(song.streamId, song.parent, track, song.title, song.artist, song.artistId, song.album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description); - } - $.ajax({ - url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(), - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - if (data["subsonic-response"].podcasts.channel !== undefined) { - var podcasts = []; - if (data["subsonic-response"].podcasts.channel.length > 0) { - podcasts = data["subsonic-response"].podcasts.channel; - } else { - podcasts[0] = data["subsonic-response"].podcasts.channel; - } - var items = []; - $.each(podcasts, function (i, item) { - if (item.id == id) { - items = item.episode; - } - }); + $rootScope.song = []; + $scope.podcasts = []; + $scope.selectedPodcast = null; - if (typeof items != 'undefined') { - if (action == 'add') { - angular.forEach(items, function (item, key) { - if (item.status != "skipped") { - $rootScope.queue.push(map(item)); - } - }); - $scope.$apply(); - $rootScope.showQueue(); - notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); - } else if (action == 'play') { - $rootScope.queue = []; - angular.forEach(items, function (item, key) { - if (item.status != "skipped") { - $rootScope.queue.push(map(item)); - } - }); - var next = $rootScope.queue[0]; - $scope.$apply(function () { - $rootScope.playSong(false, next); - }); - $rootScope.showQueue(); - notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); + $scope.getPodcasts = function(refresh) { + if (globals.settings.Debug) { + console.log("LOAD PODCASTS"); + } + $.ajax({ + url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(), + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + if (data["subsonic-response"].podcasts.channel !== undefined) { + var items = []; + if (data["subsonic-response"].podcasts.channel.length > 0) { + items = data["subsonic-response"].podcasts.channel; } else { - $scope.album = []; - $rootScope.song = []; - angular.forEach(items, function (item, key) { - if (item.status != "skipped") { - $rootScope.song.push(map(item)); - } - }); - $scope.$apply(); + items[0] = data["subsonic-response"].podcasts.channel; + } + $scope.podcasts = items; + $scope.$apply(); + } + } + }); + }; + + $scope.getPodcast = function(id, action) { + $scope.selectedPodcast = id; + var map = function(data) { + var song = data; + var url, track, rating, starred, contenttype, suffix, description; + var specs = '', + coverartthumb = '', + coverartfull = ''; + if (typeof song.coverArt != 'undefined') { + coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=60&id=' + song.coverArt; + coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + song.coverArt; + } + if (typeof song.description == 'undefined') { + description = ''; + } else { + description = song.description; + } + if (typeof song.track == 'undefined') { + track = ' '; + } else { + track = song.track; + } + if (typeof song.starred !== 'undefined') { + starred = true; + } else { + starred = false; + } + if (song.bitRate !== undefined) { + specs += song.bitRate + ' Kbps'; + } + if (song.transcodedSuffix !== undefined) { + specs += ', transcoding:' + song.suffix + ' > ' + song.transcodedSuffix; + } else { + specs += ', ' + song.suffix; + } + if (song.transcodedSuffix !== undefined) { + suffix = song.transcodedSuffix; + } else { + suffix = song.suffix; + } + if (suffix == 'ogg') { + suffix = 'oga'; + } + var salt = Math.floor(Math.random() * 100000); + url = globals.BaseURL() + '/stream.view?' + globals.BaseParams() + '&id=' + song.streamId + '&salt=' + salt; + return new model.Song(song.streamId, song.parent, track, song.title, song.artist, song.artistId, song.album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description); + }; + + $.ajax({ + url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(), + method: 'GET', + dataType: globals.settings.Protocol, + timeout: globals.settings.Timeout, + success: function(data) { + if (data["subsonic-response"].podcasts.channel !== undefined) { + var podcasts = []; + if (data["subsonic-response"].podcasts.channel.length > 0) { + podcasts = data["subsonic-response"].podcasts.channel; + } else { + podcasts[0] = data["subsonic-response"].podcasts.channel; + } + var items = []; + $.each(podcasts, function(i, item) { + if (item.id == id) { + items = item.episode; + } + }); + + if (typeof items != 'undefined') { + if (action == 'add') { + angular.forEach(items, function(item, key) { + if (item.status != "skipped") { + $rootScope.queue.push(map(item)); + } + }); + $scope.$apply(); + $rootScope.showQueue(); + notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); + } else if (action == 'play') { + $rootScope.queue = []; + angular.forEach(items, function(item, key) { + if (item.status != "skipped") { + $rootScope.queue.push(map(item)); + } + }); + var next = $rootScope.queue[0]; + $scope.$apply(function() { + $rootScope.playSong(false, next); + }); + $rootScope.showQueue(); + notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); + } else { + $scope.album = []; + $rootScope.song = []; + angular.forEach(items, function(item, key) { + if (item.status != "skipped") { + $rootScope.song.push(map(item)); + } + }); + $scope.$apply(); + } } } } - } - }); - } + }); + }; - /* Launch on Startup */ - $scope.getPodcasts(); - /* End Startup */ -}); \ No newline at end of file + /* Launch on Startup */ + $scope.getPodcasts(); + /* End Startup */ + }); diff --git a/js/controllers/queue.js b/js/controllers/queue.js index ad6d0be..0d3f7de 100644 --- a/js/controllers/queue.js +++ b/js/controllers/queue.js @@ -1,8 +1,8 @@ JamStash.controller('QueueCtrl', -function QueueCtrl($scope, $rootScope, $routeParams, $location, utils, globals, json, notifications) { - $scope.settings = globals.settings; - //$scope.song = $rootScope.queue; - //angular.copy($rootScope.queue, $scope.song); + function QueueCtrl($scope, $rootScope, $routeParams, $location, utils, globals, json, notifications) { + $scope.settings = globals.settings; + //$scope.song = $rootScope.queue; + //angular.copy($rootScope.queue, $scope.song); - $scope.song = $rootScope.queue; -}); + $scope.song = $rootScope.queue; + }); diff --git a/js/controllers/settings.js b/js/controllers/settings.js index 8ca6c0e..b6c00c1 100644 --- a/js/controllers/settings.js +++ b/js/controllers/settings.js @@ -1,83 +1,107 @@ JamStash.controller('SettingsCtrl', -function SettingsCtrl($scope, $routeParams, $location, utils, globals, json, notifications) { - $scope.settings = globals.settings; - $scope.Timeouts = [ - { id: 10000, name: 10 }, - { id: 20000, name: 20 }, - { id: 30000, name: 30 }, - { id: 40000, name: 40 }, - { id: 50000, name: 50 }, - { id: 60000, name: 60 }, - { id: 90000, name: 90 }, - { id: 120000, name: 120 } - ]; - $scope.Protocols = ["json", "jsonp"]; - $scope.Themes = ["Default", "Dark"]; - $scope.SearchTypes = globals.SearchTypes; - $scope.Layouts = globals.Layouts; + function SettingsCtrl($scope, $routeParams, $location, utils, globals, json, notifications) { + $scope.settings = globals.settings; - $scope.$watch('settings.HideAZ', function () { - if (globals.settings.HideAZ) { - $('#AZIndex').hide(); - } else { - $('#AZIndex').show(); - } - }); - $scope.reset = function () { - utils.setValue('Settings', null, true); - $scope.loadSettings(); - } - $scope.save = function () { - if ($scope.settings.Password != '' && globals.settings.Password.substring(0, 4) != 'enc:') { $scope.settings.Password = 'enc:' + utils.HexEncode($scope.settings.Password); } - if (globals.settings.NotificationSong) { - notifications.requestPermissionIfRequired(); - if (!notifications.hasNotificationPermission()) { - alert('HTML5 Notifications are not available for your current browser, Sorry :('); + $scope.Timeouts = [{ + id: 10000, + name: 10 + }, { + id: 20000, + name: 20 + }, { + id: 30000, + name: 30 + }, { + id: 40000, + name: 40 + }, { + id: 50000, + name: 50 + }, { + id: 60000, + name: 60 + }, { + id: 90000, + name: 90 + }, { + id: 120000, + name: 120 + }]; + + $scope.Protocols = ["json", "jsonp"]; + $scope.Themes = ["Default", "Dark"]; + $scope.SearchTypes = globals.SearchTypes; + $scope.Layouts = globals.Layouts; + + $scope.$watch('settings.HideAZ', function() { + if (globals.settings.HideAZ) { + $('#AZIndex').hide(); + } else { + $('#AZIndex').show(); } - } - if (globals.settings.NotificationNowPlaying) { - notifications.requestPermissionIfRequired(); - if (!notifications.hasNotificationPermission()) { - alert('HTML5 Notifications are not available for your current browser, Sorry :('); - } - } - if (globals.settings.SaveTrackPosition) { - //saveTrackPosition(); - } else { - //deleteCurrentPlaylist(); - } - if (globals.settings.Theme) { - utils.switchTheme(globals.settings.Theme); - } - utils.setValue('Settings', $scope.settings, true); - notifications.updateMessage('Settings Updated!', true); - $scope.loadSettings(); - if (globals.settings.Server != '' && globals.settings.Username != '' && globals.settings.Password != '') { - $scope.ping(); - } - }; - json.getChangeLog(function (data) { - $scope.changeLog = data.slice(0, 10); - }); - $scope.changeLogShowMore = function () { - json.getChangeLog(function (data) { - $scope.changeLog = data; }); - } - $scope.setupDemo = function () { - var Username = "android-guest"; - var Password = "guest"; - var Server = "http://subsonic.org/demo"; - var Tab = "tabLibrary"; - if (utils.confirmDelete("Do you want to connect to the Subsonic Demo server?")) { - globals.settings.Username = Username; - globals.settings.Password = Password; - globals.settings.Server = Server; - //$scope.save(); - $location.url('/library'); - } - } - /* Load on Startup */ - /* End Startup */ -}); + $scope.reset = function() { + utils.setValue('Settings', null, true); + $scope.loadSettings(); + }; + + $scope.save = function() { + if ($scope.settings.Password !== '' && globals.settings.Password.substring(0, 4) != 'enc:') { + $scope.settings.Password = 'enc:' + utils.HexEncode($scope.settings.Password); + } + if (globals.settings.NotificationSong) { + notifications.requestPermissionIfRequired(); + if (!notifications.hasNotificationPermission()) { + alert('HTML5 Notifications are not available for your current browser, Sorry :('); + } + } + if (globals.settings.NotificationNowPlaying) { + notifications.requestPermissionIfRequired(); + if (!notifications.hasNotificationPermission()) { + alert('HTML5 Notifications are not available for your current browser, Sorry :('); + } + } + if (globals.settings.SaveTrackPosition) { + //saveTrackPosition(); + } else { + //deleteCurrentPlaylist(); + } + if (globals.settings.Theme) { + utils.switchTheme(globals.settings.Theme); + } + utils.setValue('Settings', $scope.settings, true); + notifications.updateMessage('Settings Updated!', true); + $scope.loadSettings(); + if (globals.settings.Server !== '' && globals.settings.Username !== '' && globals.settings.Password !== '') { + $scope.ping(); + } + }; + + json.getChangeLog(function(data) { + $scope.changeLog = data.slice(0, 10); + }); + + $scope.changeLogShowMore = function() { + json.getChangeLog(function(data) { + $scope.changeLog = data; + }); + }; + + $scope.setupDemo = function() { + var Username = "android-guest"; + var Password = "guest"; + var Server = "http://subsonic.org/demo"; + var Tab = "tabLibrary"; + if (utils.confirmDelete("Do you want to connect to the Subsonic Demo server?")) { + globals.settings.Username = Username; + globals.settings.Password = Password; + globals.settings.Server = Server; + //$scope.save(); + $location.url('/library'); + } + }; + + /* Load on Startup */ + /* End Startup */ + }); diff --git a/js/player.js b/js/player.js index 8d1d8ea..9a3faf8 100644 --- a/js/player.js +++ b/js/player.js @@ -1,31 +1,36 @@ -JamStash.service('player', function ($rootScope, $window, utils, globals, model, notifications) { +JamStash.service('player', function($rootScope, $window, utils, globals, model, notifications) { var player1 = '#playdeck_1'; var player2 = '#playdeck_2'; var scrobbled = false; var timerid = 0; - $rootScope.defaultPlay = function (data, event) { + $rootScope.defaultPlay = function(data, event) { if (typeof $(player1).data("jPlayer") == 'undefined') { $rootScope.nextTrack(); } - } - $rootScope.nextTrack = function () { + }; + + $rootScope.nextTrack = function() { var next = getNextSong(); if (next) { $rootScope.playSong(false, next); } //$(player1).jPlayer("stop"); //$(player2).jPlayer("play"); - } - $rootScope.previousTrack = function () { + }; + + $rootScope.previousTrack = function() { var next = getNextSong(true); if (next) { $rootScope.playSong(false, next); } - } - getNextSong = function (previous) { + }; + + getNextSong = function(previous) { var song; - if (globals.settings.Debug) { console.log('Getting Next Song > ' + 'Queue length: ' + $rootScope.queue.length); } + if (globals.settings.Debug) { + console.log('Getting Next Song > ' + 'Queue length: ' + $rootScope.queue.length); + } if ($rootScope.queue.length > 0) { angular.forEach($rootScope.queue, function(item, key) { if (item.playing === true) { @@ -40,7 +45,9 @@ next = $rootScope.queue[index + 1]; } if (typeof next != 'undefined') { - if (globals.settings.Debug) { console.log('Next Song: ' + next.id); } + if (globals.settings.Debug) { + console.log('Next Song: ' + next.id); + } return next; } else { return false; @@ -48,24 +55,26 @@ } else { return false; } - } - this.startSaveTrackPosition = function () { + }; + + this.startSaveTrackPosition = function() { if (globals.settings.SaveTrackPosition) { - if (timerid != 0) { + if (timerid !== 0) { clearInterval(timerid); } - timerid = $window.setInterval(function () { + timerid = $window.setInterval(function() { if (globals.settings.SaveTrackPosition) { saveTrackPosition(); } }, 30000); } - } - saveTrackPosition = function () { + }; + + saveTrackPosition = function() { //var audio = typeof $(player1).data("jPlayer") != 'undefined' ? true : false; var audio = $(player1).data("jPlayer"); if (typeof audio != 'undefined') { - if (audio.status.currentTime > 0 && audio.status.paused == false) { + if (audio.status.currentTime > 0 && audio.status.paused === false) { var song; angular.forEach($rootScope.queue, function(item, key) { if (item.playing === true) { @@ -74,7 +83,7 @@ }); if (song) { var position = audio.status.currentTime; - if (position != null) { + if (position !== null) { $('#action_SaveProgress').fadeTo("slow", 0).delay(500).fadeTo("slow", 1).delay(500).fadeTo("slow", 0).delay(500).fadeTo("slow", 1); song.position = position; // Save Queue @@ -82,13 +91,17 @@ try { var songStr = angular.toJson(song); localStorage.setItem('CurrentSong', songStr); - if (globals.settings.Debug) { console.log('Saving Current Position: ' + songStr); } + if (globals.settings.Debug) { + console.log('Saving Current Position: ' + songStr); + } var html = localStorage.getItem('CurrentQueue'); if ($rootScope.queue.length > 0) { var current = $rootScope.queue; if (current != html) { localStorage.setItem('CurrentQueue', angular.toJson(current)); - if (globals.settings.Debug) { console.log('Saving Queue: ' + current.length + ' characters'); } + if (globals.settings.Debug) { + console.log('Saving Queue: ' + current.length + ' characters'); + } } } } catch (e) { @@ -97,14 +110,17 @@ } } } else { - if (globals.settings.Debug) { console.log('HTML5::loadStorage not supported on your browser'); } + if (globals.settings.Debug) { + console.log('HTML5::loadStorage not supported on your browser'); + } } } } } } - } - this.loadTrackPosition = function () { + }; + + this.loadTrackPosition = function() { if (utils.browserStorageCheck()) { // Load Saved Song var song = angular.fromJson(localStorage.getItem('CurrentSong')); @@ -118,26 +134,38 @@ if ($rootScope.queue.length > 0) { notifications.updateMessage($rootScope.queue.length + ' Saved Song(s)', true); } - if (globals.settings.Debug) { console.log('Play Queue Loaded From localStorage: ' + $rootScope.queue.length + ' song(s)'); } + if (globals.settings.Debug) { + console.log('Play Queue Loaded From localStorage: ' + $rootScope.queue.length + ' song(s)'); + } } } } else { - if (globals.settings.Debug) { console.log('HTML5::loadStorage not supported on your browser'); } + if (globals.settings.Debug) { + console.log('HTML5::loadStorage not supported on your browser'); + } } - } - deleteCurrentQueue = function (data) { + }; + + deleteCurrentQueue = function(data) { if (utils.browserStorageCheck()) { localStorage.removeItem('CurrentQueue'); utils.setValue('CurrentSong', null, false); - if (globals.settings.Debug) { console.log('Removing Play Queue'); } + if (globals.settings.Debug) { + console.log('Removing Play Queue'); + } } else { - if (globals.settings.Debug) { console.log('HTML5::loadStorage not supported on your browser, ' + html.length + ' characters'); } + if (globals.settings.Debug) { + console.log('HTML5::loadStorage not supported on your browser, ' + html.length + ' characters'); + } + } + }; + + $rootScope.playSong = function(loadonly, data) { + if (globals.settings.Debug) { + console.log('Play: ' + JSON.stringify(data, null, 2)); } - } - $rootScope.playSong = function (loadonly, data) { - if (globals.settings.Debug) { console.log('Play: ' + JSON.stringify(data, null, 2)); } angular.forEach($rootScope.queue, function(item, key) { - item.playing = false; + item.playing = false; }); data.playing = true; data.selected = false; @@ -166,7 +194,8 @@ artist: artist, favorite: false, albumArt: coverartfull - } + }; + if ($rootScope.unity) { $rootScope.unity.sendState(playerState); } @@ -177,13 +206,13 @@ $rootScope.showQueue(); } var spechtml = ''; - var data = $(player1).data().jPlayer; + data = $(player1).data().jPlayer; for (i = 0; i < data.solutions.length; i++) { var solution = data.solutions[i]; if (data[solution].used) { spechtml += "" + solution + " is"; spechtml += " currently being used with"; - for (format in data[solution].support) { + for (var format in data[solution].support) { if (data[solution].support[format]) { spechtml += " " + format + ""; } @@ -198,17 +227,18 @@ notifications.showNotification(coverartthumb, utils.toHTML.un(title), utils.toHTML.un(artist + ' - ' + album), 'text', '#NextTrack'); } if (globals.settings.ScrollTitle) { - var title = utils.toHTML.un(artist) + ' - ' + utils.toHTML.un(title); + title = utils.toHTML.un(artist) + ' - ' + utils.toHTML.un(title); utils.scrollTitle(title); } else { utils.setTitle(utils.toHTML.un(artist) + ' - ' + utils.toHTML.un(title)); } //utils.safeApply(); - if(!$rootScope.$root.$$phase) { + if (!$rootScope.$root.$$phase) { $rootScope.$apply(); } }; - $rootScope.loadjPlayer = function (el, url, suffix, loadonly, position) { + + $rootScope.loadjPlayer = function(el, url, suffix, loadonly, position) { // jPlayer Setup var volume = 1; if (utils.getValue('Volume')) { @@ -221,7 +251,7 @@ //var salt = Math.floor(Math.random() * 100000); //url += '&salt=' + salt; $(el).jPlayer("destroy"); - $.jPlayer.timeFormat.showHour = true; + $.jPlayer.timeFormat.showHour = true; $(el).jPlayer({ swfPath: "js/plugins/jplayer", wmode: "window", @@ -242,7 +272,7 @@ currentTime: "#played", duration: "#duration" }, - ready: function () { + ready: function() { console.log("File Suffix: " + suffix); if (suffix == 'oga') { $(this).jPlayer("setMedia", { @@ -269,12 +299,14 @@ console.log('[jPlayer Options Info]'); utils.logObjectProperties($(el).data("jPlayer").options); } - }, + }, timeupdate: function(event) { // Scrobble song once percentage is reached var p = event.jPlayer.status.currentPercentAbsolute; if (!scrobbled && p > 30) { - if (globals.settings.Debug) { console.log('LAST.FM SCROBBLE - Percent Played: ' + p); } + if (globals.settings.Debug) { + console.log('LAST.FM SCROBBLE - Percent Played: ' + p); + } scrobbleSong(true); } }, @@ -288,7 +320,7 @@ if (!getNextSong()) { // Action if we are at the last song in queue if (globals.settings.LoopQueue) { // Loop to first track in queue if enabled var next = $rootScope.queue[0]; - $rootScope.playSong(false, next); + $rootScope.playSong(false, next); } else if (globals.settings.AutoPlay) { // Load more tracks if enabled $rootScope.getRandomSongs('play', '', ''); notifications.updateMessage('Auto Play Activated...', true); @@ -301,38 +333,43 @@ error: function(event) { var time = $(player1).data("jPlayer").status.currentTime; $(player1).jPlayer("play", time); - if (globals.settings.Debug) { - console.log("Error Type: " + event.jPlayer.error.type); - console.log("Error Context: " + event.jPlayer.error.context); - console.log("Error Message: " + event.jPlayer.error.message); + if (globals.settings.Debug) { + console.log("Error Type: " + event.jPlayer.error.type); + console.log("Error Context: " + event.jPlayer.error.context); + console.log("Error Message: " + event.jPlayer.error.message); console.log("Stream interrupted, retrying from position: " + time); } } }); return; - } - this.playPauseSong = function () { + }; + + this.playPauseSong = function() { if (typeof $(player1).data("jPlayer") != 'undefined') { if ($(player1).data("jPlayer").status.paused) { $(player1).jPlayer("play"); } else { $(player1).jPlayer("pause"); } - } - } - playVideo = function (id, bitrate) { + } + }; + + playVideo = function(id, bitrate) { var w, h; bitrate = parseInt(bitrate); - if (bitrate <= 600) { - w = 320; h = 240; - } else if (bitrate <= 1000) { - w = 480; h = 360; - } else { - w = 640; h = 480; - } + if (bitrate <= 600) { + w = 320; + h = 240; + } else if (bitrate <= 1000) { + w = 480; + h = 360; + } else { + w = 640; + h = 480; + } //$("#jPlayerSelector").jPlayer("option", "fullScreen", true); $("#videodeck").jPlayer({ - ready: function () { + ready: function() { /* $.fancybox({ autoSize: false, @@ -341,41 +378,44 @@ content: $('#videodeck') }); */ - $(this).jPlayer("setMedia", { - m4v: 'https://&id=' + id + '&salt=83132' - }).jPlayer("play"); + $(this).jPlayer("setMedia", { + m4v: 'https://&id=' + id + '&salt=83132' + }).jPlayer("play"); $('#videooverlay').show(); - }, - swfPath: "js/jplayer", - solution: "html, flash", - supplied: "m4v" - }); - } - - scrobbleSong = function (submission) { + }, + swfPath: "js/jplayer", + solution: "html, flash", + supplied: "m4v" + }); + }; + + scrobbleSong = function(submission) { if ($rootScope.loggedIn && submission) { var id = $rootScope.playingSong.id; - if (globals.settings.Debug) { console.log('Scrobble Song: ' + id); } + if (globals.settings.Debug) { + console.log('Scrobble Song: ' + id); + } $.ajax({ url: globals.BaseURL() + '/scrobble.view?' + globals.BaseParams() + '&id=' + id + "&submission=" + submission, method: 'GET', dataType: globals.settings.Protocol, timeout: 10000, - success: function () { + success: function() { scrobbled = true; } }); } - } - rateSong = function (songid, rating) { + }; + + rateSong = function(songid, rating) { $.ajax({ url: baseURL + '/setRating.view?' + baseParams + '&id=' + songid + "&rating=" + rating, method: 'GET', dataType: protocol, timeout: 10000, - success: function () { + success: function() { updateMessage('Rating Updated!', true); } }); - } -}); \ No newline at end of file + }; +}); diff --git a/js/service.js b/js/service.js index 51dbea9..eb858b6 100644 --- a/js/service.js +++ b/js/service.js @@ -1,6 +1,6 @@ -JamStash.service('model', function () { +JamStash.service('model', function() { // Figure out how to move this, circular dependency with utils - secondsToTime = function (secs) { + secondsToTime = function(secs) { // secs = 4729 var times = new Array(3600, 60, 1); var time = ''; @@ -12,12 +12,10 @@ // 2: 49/1 = 49 if (tmp < 1) { tmp = '00'; - } - else if (tmp < 10) { + } else if (tmp < 10) { tmp = '0' + tmp; } - if (i == 0 && tmp == '00') { - } else { + if (i === 0 && tmp == '00') {} else { time += tmp; if (i < 2) { time += ':'; @@ -26,16 +24,19 @@ secs = secs % times[i]; } return time; - } - this.Index = function (name, artist) { + }; + + this.Index = function(name, artist) { this.name = name; this.artist = artist; - } - this.Artist = function (id, name) { + }; + + this.Artist = function(id, name) { this.id = id; this.name = name; - } - this.Album = function (id, parentid, name, artist, artistId, coverartthumb, coverartfull, date, starred, description, url, type) { + }; + + this.Album = function(id, parentid, name, artist, artistId, coverartthumb, coverartfull, date, starred, description, url, type) { this.id = id; this.parentid = parentid; this.name = name; @@ -48,8 +49,9 @@ this.description = description; this.url = url; this.type = type; - } - this.Song = function (id, parentid, track, name, artist, artistId, album, albumId, coverartthumb, coverartfull, duration, rating, starred, suffix, specs, url, position, description) { + }; + + this.Song = function(id, parentid, track, name, artist, artistId, album, albumId, coverartthumb, coverartfull, duration, rating, starred, suffix, specs, url, position, description) { this.id = id; this.parentid = parentid; this.track = track; @@ -61,7 +63,7 @@ this.coverartthumb = coverartthumb; this.coverartfull = coverartfull; this.duration = duration; - this.time = duration == '' ? '00:00' : secondsToTime(duration); + this.time = duration === '' ? '00:00' : secondsToTime(duration); this.rating = rating; this.starred = starred; this.suffix = suffix; @@ -72,33 +74,50 @@ this.playing = false; this.description = description; this.displayName = this.name + " - " + this.album + " - " + this.artist; - } + }; + }); -JamStash.service('globals', function () { - this.SearchTypes = [ - { id: "song", name: "Song" }, - { id: "album", name: "Album" }, - { id: "artist", name: "Artist" }, - ]; - this.Layouts = [ - { id: "grid", name: "Grid" }, - { id: "list", name: "List" } - ]; - this.AlbumSorts = [ - { id: "default", name: "Default Sort" }, - { id: "artist", name: "Artist" }, - { id: "album", name: "Album" }, - { id: "track", name: "Track" }, - { id: "createdate desc", name: "Date Added" }, - ]; +JamStash.service('globals', function() { + + this.SearchTypes = [{ + id: "song", + name: "Song" + }, { + id: "album", + name: "Album" + }, { + id: "artist", + name: "Artist" + }, ]; + + this.Layouts = [{ + id: "grid", + name: "Grid" + }, { + id: "list", + name: "List" + }]; + + this.AlbumSorts = [{ + id: "default", + name: "Default Sort" + }, { + id: "artist", + name: "Artist" + }, { + id: "album", + name: "Album" + }, { + id: "track", + name: "Track" + }, { + id: "createdate desc", + name: "Date Added" + }, ]; + this.settings = { // Subsonic - /* Demo Server - Username: "android-guest"), - Password: "guest"), - Server: "http://subsonic.org/demo"), - */ Url: "http://Jamstash.com/beta/#/archive/", Username: "", Password: "", @@ -127,21 +146,28 @@ JamStash.service('globals', function () { Repeat: false, Debug: false }; + this.SavedCollections = []; this.SavedGenres = []; - this.BaseURL = function () { return this.settings.Server + '/rest'; }; - this.BaseParams = function () { return 'u=' + this.settings.Username + '&p=' + this.settings.Password + '&f=' + this.settings.Protocol + '&v=' + this.settings.ApiVersion + '&c=' + this.settings.ApplicationName; }; + this.BaseURL = function() { + return this.settings.Server + '/rest'; + }; + + this.BaseParams = function() { + return 'u=' + this.settings.Username + '&p=' + this.settings.Password + '&f=' + this.settings.Protocol + '&v=' + this.settings.ApiVersion + '&c=' + this.settings.ApplicationName; + }; }); + // Directives -JamStash.directive('layout', function () { +JamStash.directive('layout', function() { return { - link: function (scope, elm, attrs) { + link: function(scope, elm, attrs) { var pageLayoutOptions = { name: 'pageLayout', // only for debugging - resizeWithWindowDelay: 250, // delay calling resizeAll when window is *still* resizing + resizeWithWindowDelay: 250, // delay calling resizeAll when window is *still* resizing //, resizeWithWindowMaxDelay: 2000 // force resize every XX ms while window is being resized //center__children: {}, //north__paneSelector: "#container", @@ -157,16 +183,16 @@ JamStash.directive('layout', function () { }; var layoutThreeCol = { - east__size: .42, + east__size: 0.42, east__minSize: 400, - east__maxSize: .5, // 50% of layout width + east__maxSize: 0.5, // 50% of layout width east__initClosed: false, east__initHidden: false, //center__size: 'auto', - center__minWidth: .38, + center__minWidth: 0.38, center__initClosed: false, center__initHidden: false, - west__size: .2, + west__size: 0.2, west__minSize: 200, west__initClosed: false, west__initHidden: false, @@ -176,12 +202,12 @@ JamStash.directive('layout', function () { }; var layoutTwoCol = { - center__size: .8, + center__size: 0.8, center__minSize: 400, - center__maxSize: .5, // 50% of layout width + center__maxSize: 0.5, // 50% of layout width center__initClosed: false, center__initHidden: false, - west__size: .2, + west__size: 0.2, west__minSize: 200, west__initClosed: false, west__initHidden: false, @@ -190,17 +216,20 @@ JamStash.directive('layout', function () { //applyDefaultStyles: true }; - scope.$watch(attrs.state, function (state) { + scope.$watch(attrs.state, function(state) { + var layout; + if (state == 1) { - var layout = elm.layout(pageLayoutOptions); + layout = elm.layout(pageLayoutOptions); } + if (state == 2) { - var layout = elm.layout(layoutTwoCol); + layout = elm.layout(layoutTwoCol); //scope.layout.sizePane('east', 120); //scope.layout.show('west'); //scope.layout.show('south'); } else if (state == 3) { - var layout = elm.layout(layoutThreeCol); + layout = elm.layout(layoutThreeCol); //scope.layout.sizePane('east', 60); //scope.layout.hide('west'); //scope.layout.hide('south'); @@ -210,9 +239,10 @@ JamStash.directive('layout', function () { } }; }); -JamStash.directive('sortable', function () { + +JamStash.directive('sortable', function() { return { - link: function (scope, elm, attrs) { + link: function(scope, elm, attrs) { elm.sortable({ start: scope.dragStart, update: scope.dragEnd @@ -221,69 +251,38 @@ JamStash.directive('sortable', function () { } }; }); -JamStash.directive('split', function () { + +JamStash.directive('split', function() { return { - link: function (scope, elm, attrs) { + link: function(scope, elm, attrs) { elm.splitPane(); - /* - //elm.first().resizable({ - $('#SubsonicAlbums > div:first').resizable({ - handles: 'e', - minWidth: '100', - maxWidth: '400', - resize: function () { - alert('foo'); - var remainingSpace = $(this).parent().width() - $(this).outerWidth(); - var divTwo = $(this).next(); - var divTwoWidth = remainingSpace - (divTwo.outerWidth() - divTwo.width()); - divTwo.css('width', divTwoWidth + 'px'); - } - }); - */ - /* - scope.$watch(attrs.state, function (state) { - if (state == 1) { - var layout = elm.layout(pageLayoutOptions); - } - if (state == 2) { - var layout = elm.layout(layoutTwoCol); - //scope.layout.sizePane('east', 120); - //scope.layout.show('west'); - //scope.layout.show('south'); - } else if (state == 3) { - var layout = elm.layout(layoutThreeCol); - //scope.layout.sizePane('east', 60); - //scope.layout.hide('west'); - //scope.layout.hide('south'); - } - scope.layout = layout; - }); - */ } }; }); -JamStash.directive('fancybox', function ($compile) { + +JamStash.directive('fancybox', function($compile) { return { restrict: 'A', replace: false, link: function($scope, element, attrs) { $scope.fancyboxOpen = function() { var el = angular.element(element.html()), - compiled = $compile(el); + compiled = $compile(el); $.fancybox.open(el); compiled($scope); }; - $scope.fancyboxOpenUrl = function () { + $scope.fancyboxOpenUrl = function() { var el = angular.element(element.html()), - compiled = $compile(el); + compiled = $compile(el); $.fancybox.open(el); compiled($scope); }; } }; }); -JamStash.directive('songpreview', function ($compile, subsonic) { + +JamStash.directive('songpreview', function($compile, subsonic) { return { restrict: 'E', templateUrl: 'js/partials/songs.html', @@ -292,8 +291,8 @@ JamStash.directive('songpreview', function ($compile, subsonic) { scope: { song: '@' }, - link: function (scope, element, attrs) { - subsonic.getSongTemplate(function (data) { + link: function(scope, element, attrs) { + subsonic.getSongTemplate(function(data) { scope.song = data; //var el = angular.element(element.html()), //var el = element.html(), @@ -302,23 +301,25 @@ JamStash.directive('songpreview', function ($compile, subsonic) { //compiled($scope); }); } - } -}) -JamStash.directive('stopEvent', function () { + }; +}); + +JamStash.directive('stopEvent', function() { return { restrict: 'A', - link: function (scope, element, attr) { - element.bind(attr.stopEvent, function (e) { + link: function(scope, element, attr) { + element.bind(attr.stopEvent, function(e) { e.stopPropagation(); }); } }; }); -JamStash.directive('ngEnter', function () { - return function (scope, element, attrs) { - element.bind("keydown keypress", function (event) { + +JamStash.directive('ngEnter', function() { + return function(scope, element, attrs) { + element.bind("keydown keypress", function(event) { if (event.which === 13) { - scope.$apply(function () { + scope.$apply(function() { scope.$eval(attrs.ngEnter); }); @@ -327,23 +328,28 @@ JamStash.directive('ngEnter', function () { }); }; }); -JamStash.directive('ngDownload', function ($compile) { + +JamStash.directive('ngDownload', function($compile) { return { restrict: 'E', - scope: { data: '=' }, - link: function (scope, elm, attrs) { + scope: { + data: '=' + }, + link: function(scope, elm, attrs) { function getUrl() { - return URL.createObjectURL(new Blob([JSON.stringify(scope.data)], { type: "application/json" })); + return URL.createObjectURL(new Blob([JSON.stringify(scope.data)], { + type: "application/json" + })); } elm.append($compile( - '' + - 'Download' + - '' + '' + + 'Download' + + '' )(scope)); - scope.$watch(scope.data, function () { + scope.$watch(scope.data, function() { elm.children()[0].href = getUrl(); }); } @@ -351,105 +357,110 @@ JamStash.directive('ngDownload', function ($compile) { }); /* Factory */ -JamStash.factory('json', function ($http) { // Deferred loading +JamStash.factory('json', function($http) { // Deferred loading return { - getCollections: function (callback) { + getCollections: function(callback) { $http.get('js/json_collections.js').success(callback); }, - getChangeLog: function (callback) { + getChangeLog: function(callback) { $http.get('js/json_changelog.js').success(callback); } - } + }; }); -JamStash.factory('template', function ($http, $compile, $http, $templateCache) { // Deferred loading + +JamStash.factory('template', function($compile, $http, $templateCache) { // Deferred loading return { - getCollections: function (callback) { - $http.get('js/json_collections.js', { cache: $templateCache }).success(callback); + getCollections: function(callback) { + $http.get('js/json_collections.js', { + cache: $templateCache + }).success(callback); }, - getChangeLog: function (callback) { - $http.get('js/json_changelog.js', { cache: $templateCache }).success(callback); + getChangeLog: function(callback) { + $http.get('js/json_changelog.js', { + cache: $templateCache + }).success(callback); }, - getSongs: function (callback) { + getSongs: function(callback) { templateUrl = 'js/partials/songs.html'; - $http.get(templateUrl, { cache: $templateCache }).success(callback); + $http.get(templateUrl, { + cache: $templateCache + }).success(callback); } - } + }; }); -JamStash.factory('subsonic', function ($http, globals, utils) { + +JamStash.factory('subsonic', function($http, globals, utils) { return { - getSongTemplate: function (callback) { + getSongTemplate: function(callback) { var id = '16608'; var url = globals.BaseURL() + '/getMusicDirectory.view?' + globals.BaseParams() + '&id=' + id; - /* - $.ajax({ - url: url, - method: 'GET', - dataType: globals.settings.Protocol, - timeout: globals.settings.Timeout, - success: function (data) { - + + $http.get(url).success(function(data) { + var items = []; + var song = []; + if (typeof data["subsonic-response"].directory.child != 'undefined') { + if (data["subsonic-response"].directory.child.length > 0) { + items = data["subsonic-response"].directory.child; + } else { + items[0] = data["subsonic-response"].directory.child; + } + angular.forEach(items, function(item, key) { + if (!item.isDir) { + song.push(utils.mapSong(item)); + } + }); + callback(song); } }); - */ - $http.get(url).success(function (data) { - var items = []; - var song = []; - if (typeof data["subsonic-response"].directory.child != 'undefined') { - if (data["subsonic-response"].directory.child.length > 0) { - items = data["subsonic-response"].directory.child; - } else { - items[0] = data["subsonic-response"].directory.child; - } - angular.forEach(items, function (item, key) { - if (!item.isDir) { - song.push(utils.mapSong(item)); - } - }); - callback(song); - } - }); } - } + }; }); /* Filters */ -JamStash.filter('capitalize', function () { - return function (input, scope) { +JamStash.filter('capitalize', function() { + return function(input, scope) { return input.substring(0, 1).toUpperCase() + input.substring(1); - } + }; }); -JamStash.service('notifications', function ($rootScope, globals) { +JamStash.service('notifications', function($rootScope, globals) { var msgIndex = 1; - this.updateMessage = function (msg, autohide) { - if (msg != '') { + this.updateMessage = function(msg, autohide) { + if (msg !== '') { var id = msgIndex; $('#messages').append('' + msg + ''); $('#messages').fadeIn(); $("#messages").scrollTo('100%'); var el = '#msg_' + id; if (autohide) { - setTimeout(function () { - $(el).fadeOut(function () { $(this).remove(); }); + setTimeout(function() { + $(el).fadeOut(function() { + $(this).remove(); + }); }, globals.settings.NotificationTimeout); } - $(el).click(function () { - $(el).fadeOut(function () { $(this).remove(); }); + $(el).click(function() { + $(el).fadeOut(function() { + $(this).remove(); + }); return false; }); msgIndex++; } - } - this.requestPermissionIfRequired = function () { + }; + + this.requestPermissionIfRequired = function() { if (!this.hasNotificationPermission() && (window.webkitNotifications)) { window.webkitNotifications.requestPermission(); } - } - this.hasNotificationPermission = function () { - return !!(window.webkitNotifications) && (window.webkitNotifications.checkPermission() == 0); - } - var notifications = new Array(); - this.showNotification = function (pic, title, text, type, bind) { + }; + + this.hasNotificationPermission = function() { + return !!(window.webkitNotifications) && (window.webkitNotifications.checkPermission() === 0); + }; + + var notifications = []; + this.showNotification = function(pic, title, text, type, bind) { if (this.hasNotificationPermission()) { //closeAllNotifications() var popup; @@ -458,25 +469,26 @@ JamStash.service('notifications', function ($rootScope, globals) { } else if (type == 'html') { popup = window.webkitNotifications.createHTMLNotification(text); } - if (bind = '#NextTrack') { - popup.addEventListener('click', function (bind) { + if (bind == '#NextTrack') { + popup.addEventListener('click', function(bind) { //$(bind).click(); $rootScope.nextTrack(); this.cancel(); - }) + }); } notifications.push(popup); - setTimeout(function (notWin) { + setTimeout(function(notWin) { notWin.cancel(); }, globals.settings.NotificationTimeout, popup); popup.show(); } else { console.log("showNotification: No Permission"); } - } - this.closeAllNotifications = function () { - for (notification in notifications) { + }; + + this.closeAllNotifications = function() { + for (var notification in notifications) { notifications[notification].cancel(); } - } + }; }); diff --git a/js/subsonic.js b/js/subsonic.js deleted file mode 100644 index 5f28270..0000000 --- a/js/subsonic.js +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/js/utils.js b/js/utils.js index a307eef..3b01ac1 100644 --- a/js/utils.js +++ b/js/utils.js @@ -1,15 +1,17 @@ -JamStash.service('utils', function ($cookieStore, globals, model) { - this.safeApply = function (fn) { +JamStash.service('utils', function($cookieStore, globals, model) { + + this.safeApply = function(fn) { var phase = this.$root.$$phase; if (phase == '$apply' || phase == '$digest') { - if (fn && (typeof (fn) === 'function')) { + if (fn && (typeof(fn) === 'function')) { fn(); } } else { this.$apply(fn); } }; - this.setValue = function (key, value, notify) { + + this.setValue = function(key, value, notify) { /* if (value !== null) { $cookieStore.put(key, value); @@ -22,10 +24,13 @@ JamStash.service('utils', function ($cookieStore, globals, model) { try { localStorage.setItem(key, JSON.stringify(value)); } catch (e) { - if (globals.settings.Debug) { console.log(e); } + if (globals.settings.Debug) { + console.log(e); + } } - } - this.getValue = function (value) { + }; + + this.getValue = function(value) { /* if ($cookieStore.get(value)) { return $cookieStore.get(value); @@ -35,57 +40,93 @@ JamStash.service('utils', function ($cookieStore, globals, model) { */ try { var item = localStorage.getItem(value); - if (item != '' && typeof item != 'undefined') { + if (item !== '' && typeof item != 'undefined') { return JSON.parse(item); } else { return false; } } catch (e) { - if (globals.settings.Debug) { console.log(e); } + if (globals.settings.Debug) { + console.log(e); + } } - } - this.mapSong = function (data) { + }; + + this.mapSong = function(data) { var song = data; var url, title, track, rating, starred, contenttype, suffix, description; - var specs = '', coverartthumb = '', coverartfull = ''; + var specs = '', + coverartthumb = '', + coverartfull = ''; if (typeof song.coverArt != 'undefined') { coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=60&id=' + song.coverArt; coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + song.coverArt; } - if (typeof song.description == 'undefined') { description = ''; } else { description = song.description; } - if (typeof song.title == 'undefined') { title = ' '; } else { title = song.title.toString(); } - if (typeof song.track == 'undefined') { track = ' '; } else { track = song.track.toString(); } - if (typeof song.starred !== 'undefined') { starred = true; } else { starred = false; } - if (song.bitRate !== undefined) { specs += song.bitRate + ' Kbps'; } - if (song.transcodedSuffix !== undefined) { specs += ', transcoding:' + song.suffix + ' > ' + song.transcodedSuffix; } else { specs += ', ' + song.suffix; } - if (song.transcodedSuffix !== undefined) { suffix = song.transcodedSuffix; } else { suffix = song.suffix; } - if (suffix == 'ogg') { suffix = 'oga'; } + if (typeof song.description == 'undefined') { + description = ''; + } else { + description = song.description; + } + if (typeof song.title == 'undefined') { + title = ' '; + } else { + title = song.title.toString(); + } + if (typeof song.track == 'undefined') { + track = ' '; + } else { + track = song.track.toString(); + } + if (typeof song.starred !== 'undefined') { + starred = true; + } else { + starred = false; + } + if (song.bitRate !== undefined) { + specs += song.bitRate + ' Kbps'; + } + if (song.transcodedSuffix !== undefined) { + specs += ', transcoding:' + song.suffix + ' > ' + song.transcodedSuffix; + } else { + specs += ', ' + song.suffix; + } + if (song.transcodedSuffix !== undefined) { + suffix = song.transcodedSuffix; + } else { + suffix = song.suffix; + } + if (suffix == 'ogg') { + suffix = 'oga'; + } var salt = Math.floor(Math.random() * 100000); url = globals.BaseURL() + '/stream.view?' + globals.BaseParams() + '&id=' + song.id + '&salt=' + salt; return new model.Song(song.id, song.parent, track, title, song.artist, song.artistId, song.album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description); - } - this.confirmDelete = function (text) { + }; + + this.confirmDelete = function(text) { var question = confirm(text); if (question) { return true; - } - else { + } else { return false; } - } - this.makeBaseAuth = function (user, password) { + }; + + this.makeBaseAuth = function(user, password) { var tok = user + ':' + password; var hash = $.base64Encode(tok); return "Basic " + hash; - } - this.HexEncode = function (n) { + }; + + this.HexEncode = function(n) { for (var u = "0123456789abcdef", i = [], r = [], t = 0; t < 256; t++) i[t] = u.charAt(t >> 4) + u.charAt(t & 15); for (t = 0; t < n.length; t++) r[t] = i[n.charCodeAt(t)]; - return r.join("") - } - this.switchTheme = function (theme) { + return r.join(""); + }; + + this.switchTheme = function(theme) { switch (theme.toLowerCase()) { case 'dark': $('link[data-name=theme]').attr('href', 'style/Dark.css'); @@ -96,16 +137,18 @@ JamStash.service('utils', function ($cookieStore, globals, model) { default: break; } - } + }; + // HTML5 - this.browserStorageCheck = function () { - if (typeof (localStorage) == 'undefined') { + this.browserStorageCheck = function() { + if (typeof(localStorage) == 'undefined') { return false; } else { return true; } - } - this.timeToSeconds = function (time) { + }; + + this.timeToSeconds = function(time) { var a = time.split(':'); // split it at the colons var seconds; switch (a.length) { @@ -122,8 +165,9 @@ JamStash.service('utils', function ($cookieStore, globals, model) { break; } return seconds; - } - this.secondsToTime = function (secs) { + }; + + this.secondsToTime = function(secs) { // secs = 4729 var times = new Array(3600, 60, 1); var time = ''; @@ -135,12 +179,10 @@ JamStash.service('utils', function ($cookieStore, globals, model) { // 2: 49/1 = 49 if (tmp < 1) { tmp = '00'; - } - else if (tmp < 10) { + } else if (tmp < 10) { tmp = '0' + tmp; } - if (i == 0 && tmp == '00') { - } else { + if (i === 0 && tmp == '00') {} else { time += tmp; if (i < 2) { time += ':'; @@ -149,27 +191,30 @@ JamStash.service('utils', function ($cookieStore, globals, model) { secs = secs % times[i]; } return time; - } - this.arrayObjectIndexOf = function (myArray, searchTerm, property) { + }; + + this.arrayObjectIndexOf = function(myArray, searchTerm, property) { for (var i = 0, len = myArray.length; i < len; i++) { if (myArray[i][property] === searchTerm) return i; } return -1; - } - this.logObjectProperties = function (obj) { - $.each(obj, function (key, value) { + }; + + this.logObjectProperties = function(obj) { + $.each(obj, function(key, value) { var parent = key; if (typeof value === "object") { - $.each(value, function (key, value) { + $.each(value, function(key, value) { console.log(parent + ' > ' + key + ' : ' + value); }); } else { console.log(key + ' : ' + value); } }); - } - this.clickButton = function (el) { - var el = $(el); + }; + + this.clickButton = function(el) { + el = $(el); if (el) { var classes = $(el).attr('class').split(" "); for (var i = 0, l = classes.length; i < l; ++i) { @@ -186,86 +231,143 @@ JamStash.service('utils', function ($cookieStore, globals, model) { } } } - } - this.findKeyForCode = function (code) { - var map = { 'keymap': [ - { 'key': 'a', 'code': 65 }, - { 'key': 'b', 'code': 66 }, - { 'key': 'c', 'code': 67 }, - { 'key': 'd', 'code': 68 }, - { 'key': 'e', 'code': 69 }, - { 'key': 'f', 'code': 70 }, - { 'key': 'g', 'code': 71 }, - { 'key': 'h', 'code': 72 }, - { 'key': 'i', 'code': 73 }, - { 'key': 'j', 'code': 74 }, - { 'key': 'k', 'code': 75 }, - { 'key': 'l', 'code': 76 }, - { 'key': 'm', 'code': 77 }, - { 'key': 'n', 'code': 78 }, - { 'key': 'o', 'code': 79 }, - { 'key': 'p', 'code': 80 }, - { 'key': 'q', 'code': 81 }, - { 'key': 'r', 'code': 82 }, - { 'key': 's', 'code': 83 }, - { 'key': 't', 'code': 84 }, - { 'key': 'u', 'code': 85 }, - { 'key': 'v', 'code': 86 }, - { 'key': 'w', 'code': 87 }, - { 'key': 'x', 'code': 88 }, - { 'key': 'y', 'code': 89 }, - { 'key': 'z', 'code': 90 } - ] + }; + + this.findKeyForCode = function(code) { + var map = { + 'keymap': [{ + 'key': 'a', + 'code': 65 + }, { + 'key': 'b', + 'code': 66 + }, { + 'key': 'c', + 'code': 67 + }, { + 'key': 'd', + 'code': 68 + }, { + 'key': 'e', + 'code': 69 + }, { + 'key': 'f', + 'code': 70 + }, { + 'key': 'g', + 'code': 71 + }, { + 'key': 'h', + 'code': 72 + }, { + 'key': 'i', + 'code': 73 + }, { + 'key': 'j', + 'code': 74 + }, { + 'key': 'k', + 'code': 75 + }, { + 'key': 'l', + 'code': 76 + }, { + 'key': 'm', + 'code': 77 + }, { + 'key': 'n', + 'code': 78 + }, { + 'key': 'o', + 'code': 79 + }, { + 'key': 'p', + 'code': 80 + }, { + 'key': 'q', + 'code': 81 + }, { + 'key': 'r', + 'code': 82 + }, { + 'key': 's', + 'code': 83 + }, { + 'key': 't', + 'code': 84 + }, { + 'key': 'u', + 'code': 85 + }, { + 'key': 'v', + 'code': 86 + }, { + 'key': 'w', + 'code': 87 + }, { + 'key': 'x', + 'code': 88 + }, { + 'key': 'y', + 'code': 89 + }, { + 'key': 'z', + 'code': 90 + }] }; var keyFound = 0; - $.each(map.keymap, function (i, mapping) { + $.each(map.keymap, function(i, mapping) { if (mapping.code === code) { keyFound = mapping.key; } }); return keyFound; - } + }; + this.toHTML = { - on: function (str) { + on: function(str) { var a = [], - i = 0; - for (; i < str.length; ) a[i] = str.charCodeAt(i++); - return "&#" + a.join(";&#") + ";" + i = 0; + for (; i < str.length;) a[i] = str.charCodeAt(i++); + return "&#" + a.join(";&#") + ";"; }, - un: function (str) { + un: function(str) { return str.replace(/&#(x)?([^;]{1,5});?/g, - function (a, b, c) { - return String.fromCharCode(parseInt(c, b ? 16 : 10)) - }) + function(a, b, c) { + return String.fromCharCode(parseInt(c, b ? 16 : 10)); + }); } }; - this.getParameterByName = function (name) { + this.getParameterByName = function(name) { name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS); var results = regex.exec(window.location.search); - if (results == null) + if (results === null) return ""; else return decodeURIComponent(results[1].replace(/\+/g, " ")); - } - this.getPathFromUrl = function (url) { + }; + + this.getPathFromUrl = function(url) { var strurl = url.toString(); var u = strurl.substring(0, strurl.indexOf('?')); - return u - } - this.setTitle = function (text) { - if (text != "") { + return u; + }; + + this.setTitle = function(text) { + if (text !== "") { document.title = text; } - } + }; + var timer = 0; - this.scrollTitle = function (text) { + this.scrollTitle = function(text) { var shift = { - "left": function (a) { + "left": function(a) { a.push(a.shift()); }, - "right": function (a) { + "right": function(a) { a.unshift(a.pop()); } }; @@ -281,23 +383,19 @@ JamStash.service('utils', function ($cookieStore, globals, model) { } t.push(" "); clearInterval(timer); - timer = setInterval(function () { + timer = setInterval(function() { var f = shift[opts.dir]; if (f) { f(t); document.title = t.join(""); } }, opts.speed); - /* - $.marqueeTitle({ - text: text, - dir: "left", - speed: 1200 - }); - */ - } - this.parseVersionString = function (str) { - if (typeof (str) != 'string') { return false; } + }; + + this.parseVersionString = function(str) { + if (typeof(str) != 'string') { + return false; + } var x = str.split('.'); // parse from string or default to 0 if can't parse var maj = parseInt(x[0]) || 0; @@ -307,9 +405,10 @@ JamStash.service('utils', function ($cookieStore, globals, model) { major: maj, minor: min, patch: pat - } - } - this.checkVersion = function (runningVersion, minimumVersion) { + }; + }; + + this.checkVersion = function(runningVersion, minimumVersion) { if (runningVersion.major >= minimumVersion.major) { if (runningVersion.minor >= minimumVersion.minor) { if (runningVersion.patch >= minimumVersion.patch) { @@ -323,8 +422,9 @@ JamStash.service('utils', function ($cookieStore, globals, model) { } else { return false; } - } - this.checkVersionNewer = function (runningVersion, newVersion) { + }; + + this.checkVersionNewer = function(runningVersion, newVersion) { if (runningVersion.major < newVersion.major) { return true; } else { @@ -338,14 +438,14 @@ JamStash.service('utils', function ($cookieStore, globals, model) { } } } - } - this.parseDate = function (date) { + }; + + this.parseDate = function(date) { // input: "2012-09-23 20:00:00.0" var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; var parts = date.split(" "); var dateParts = parts[0].split("-"); var month = parseInt(dateParts[1], 10) - 1; - var date = months[month] + " " + dateParts[2] + ", " + dateParts[0]; - return date; - } -}); \ No newline at end of file + return months[month] + " " + dateParts[2] + ", " + dateParts[0]; + }; +});