/* global define */
define(["qlik","encoder"],function(a,e){var o={splitToStringNum:function(t,e){for(var r=t.split(e),n=0;n<r.length;n++)isNaN(r[n])||(r[n]=Number(r[n]));return r},fixUrl:function(t){return e.encodeForHref(t)},isEmpty:function(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0},get:function(t,e){return t.reduce(function(t,e){return t&&t[e]?t[e]:null},e)},getAppList:function(){var e=a.Promise;return a.getGlobal().getAppList(function(t){e.resolve(t.map(function(t){return{value:t.qDocId,label:t.qTitle}}))}),e},getFirstSheet:function(t){var r=a.Promise.defer();return(t=t||a.currApp()).getAppObjectList(function(t){var e=t.qAppObjectList.qItems.sort(function(t,e){return t.qData.rank-e.qData.rank});0<e.length&&r.resolve({id:e[0].qInfo.qId,title:e[0].qMeta.title})}),r.promise},getLastSheet:function(t){var r=a.Promise.defer();return(t=t||a.currApp()).getAppObjectList(function(t){var e=t.qAppObjectList.qItems.sort(function(t,e){return e.qData.rank-t.qData.rank});0<e.length&&r.resolve({id:e[0].qInfo.qId,title:e[0].qMeta.title})}),r.promise},getBookmarkList:function(t){var e=a.Promise.defer(),r=o.get(["app"],t);return(r=r||a.currApp()).getList("BookmarkList",function(t){e.resolve(t.qBookmarkList.qItems.map(function(t){return{value:t.qInfo.qId,label:50<t.qData.title.length?t.qData.title.slice(0,50)+"...":t.qData.title}}))}),e.promise},getFieldList:function(t){var e=a.Promise.defer(),r=o.get(["app"],t);return(r=r||a.currApp()).getList("FieldList",function(t){e.resolve(t.qFieldList.qItems.map(function(t){return{value:t.qName,label:50<t.qName.length?t.qName.slice(0,50)+"...":t.qName}}))}),e.promise},getPPList:function(n){var i=a.Promise.defer(),t=o.get(["app"],n);return(t=t||a.currApp()).getList(o.get(["listType"],n),function(t){var e=[],r=o.get(["sortBy"],n)||"rank";return t&&t.qAppObjectList&&t.qAppObjectList.qItems?(t.qAppObjectList.qItems.sort(function(t,e){return t.qData[r]-e.qData[r]}).forEach(function(t){e.push({value:t.qInfo.qId,label:50<t.qMeta.title.length?t.qMeta.title.slice(0,50)+"...":t.qMeta.title})}),i.resolve(e)):i.reject("qItems is undefined (listType: "+o.get(["listType"],n)+")")}),i.promise}};return o});