2013-02-20 18:33:05 -07:00
var PluginsPage = {
onPageShow : function ( ) {
PluginsPage . reloadList ( ) ;
} ,
reloadList : function ( ) {
Dashboard . showLoadingMsg ( ) ;
var promise1 = ApiClient . getInstalledPlugins ( ) ;
var promise2 = $ . getJSON ( "configurationpages?pageType=PluginConfiguration" ) ;
$ . when ( promise1 , promise2 ) . done ( function ( response1 , response2 ) {
PluginsPage . populateList ( response1 [ 0 ] , response2 [ 0 ] ) ;
} ) ;
} ,
populateList : function ( plugins , pluginConfigurationPages ) {
var page = $ ( $ . mobile . activePage ) ;
plugins = plugins . sort ( function ( plugin1 , plugin2 ) {
2013-03-04 21:29:43 -07:00
return ( plugin1 . Name ) > ( plugin2 . Name ) ? 1 : - 1 ;
2013-02-20 18:33:05 -07:00
} ) ;
var html = "" ;
for ( var i = 0 , length = plugins . length ; i < length ; i ++ ) {
var plugin = plugins [ i ] ;
var configPage = $ . grep ( pluginConfigurationPages , function ( pluginConfigurationPage ) {
2013-03-17 09:52:32 -07:00
return pluginConfigurationPage . PluginId == plugin . Id ;
2013-02-20 18:33:05 -07:00
} ) [ 0 ] ;
html += "<li>" ;
var href = configPage ? Dashboard . getConfigurationPageUrl ( configPage . Name ) : "#" ;
html += "<a href='" + href + "'>" ;
html += "<h3>" + plugin . Name + "</h3>" ;
html += "<p><strong>" + plugin . Version + "</strong></p>" ;
html += "</a>" ;
2013-03-04 21:29:43 -07:00
html += "<a data-id='" + plugin . Id + "' data-pluginname='" + plugin . Name + "' onclick='PluginsPage.deletePlugin(this);' href='#'>Delete</a>" ;
2013-02-20 18:33:05 -07:00
html += "</li>" ;
}
2013-04-06 09:59:18 -07:00
2013-04-06 09:46:39 -07:00
if ( plugins . length == 0 || ! plugins . length ) {
2013-04-06 09:59:18 -07:00
html += '<li style="padding:5px;">You have no plugins installed. Browse our <a href="plugincatalog.html">plugin catalog</a> to view available plugins.</li>' ;
$ ( '#ulInstalledPlugins' , page ) . html ( html ) ;
} else {
$ ( '#ulInstalledPlugins' , page ) . html ( html ) . listview ( 'refresh' ) ;
}
2013-02-20 18:33:05 -07:00
Dashboard . hideLoadingMsg ( ) ;
} ,
deletePlugin : function ( link ) {
var name = link . getAttribute ( 'data-pluginname' ) ;
2013-02-21 23:28:57 -07:00
var uniqueid = link . getAttribute ( 'data-id' ) ;
2013-02-20 18:33:05 -07:00
var msg = "Are you sure you wish to uninstall " + name + "?" ;
Dashboard . confirm ( msg , "Uninstall Plugin" , function ( result ) {
if ( result ) {
Dashboard . showLoadingMsg ( ) ;
ApiClient . uninstallPlugin ( uniqueid ) . done ( function ( ) {
PluginsPage . reloadList ( ) ;
} ) ;
}
} ) ;
}
} ;
$ ( document ) . on ( 'pageshow' , "#pluginsPage" , PluginsPage . onPageShow ) ;