@ -33,13 +33,75 @@ define('admin/extend/plugins', function() {
pluginsList . on ( 'click' , 'button[data-action="toggleInstall"]' , function ( ) {
pluginID = $ ( this ) . parents ( 'li' ) . attr ( 'data-plugin-id' ) ;
Plugins . suggest ( pluginID , function ( err , payload ) {
if ( ! err ) {
Plugins . toggleInstall ( pluginID , payload . version ) ;
} else {
bootbox . confirm ( '<p>NodeBB could not reach the package manager, proceed with installation of latest version?</p><div class="alert alert-danger"><strong>Server returned (' + err . status + ')</strong>: ' + err . responseText + '</div>' , function ( confirm ) {
if ( confirm ) {
Plugins . toggleInstall ( pluginID , 'latest' ) ;
}
} ) ;
}
} ) ;
} ) ;
pluginsList . on ( 'click' , 'button[data-action="upgrade"]' , function ( ) {
var btn = $ ( this ) ;
var parent = btn . parents ( 'li' ) ;
pluginID = parent . attr ( 'data-plugin-id' ) ;
Plugins . suggest ( pluginID , function ( err , payload ) {
if ( ! err ) {
require ( [ 'semver' ] , function ( semver ) {
if ( semver . gt ( payload . version , parent . find ( '.currentVersion' ) . text ( ) ) ) {
btn . attr ( 'disabled' , true ) . find ( 'i' ) . attr ( 'class' , 'fa fa-refresh fa-spin' ) ;
socket . emit ( 'admin.plugins.upgrade' , {
id : pluginID ,
version : payload . version
} , function ( err ) {
if ( err ) {
return app . alertError ( err . message ) ;
}
parent . find ( '.fa-exclamation-triangle' ) . remove ( ) ;
parent . find ( '.currentVersion' ) . text ( payload . version ) ;
btn . remove ( ) ;
} ) ;
} else {
bootbox . alert ( '<p>Your version of NodeBB (v' + app . config . version + ') is only cleared to upgrade to v' + payload . version + ' of this plugin. Please update your NodeBB if you wish to install a newer version of this plugin.' ) ;
}
} ) ;
} else {
bootbox . alert ( '<p>NodeBB could not reach the package manager, an upgrade is not suggested at this time.</p>' ) ;
}
} ) ;
} ) ;
$ ( '#plugin-search' ) . on ( 'input propertychange' , function ( ) {
var term = $ ( this ) . val ( ) ;
$ ( '.plugins li' ) . each ( function ( ) {
var pluginId = $ ( this ) . attr ( 'data-plugin-id' ) ;
$ ( this ) . toggleClass ( 'hide' , pluginId && pluginId . indexOf ( term ) === - 1 ) ;
} ) ;
} ) ;
} else {
pluginsList . append ( '<li><p><i>No plugins found.</i></p></li>' ) ;
}
} ,
toggleInstall : function ( pluginID , version , callback ) {
var btn = $ ( 'li[data-plugin-id="' + pluginID + '"] button[data-action="toggleInstall"]' ) ;
var activateBtn = btn . siblings ( '[data-action="toggleActive"]' ) ;
btn . html ( btn . html ( ) + 'ing' )
. attr ( 'disabled' , true )
. find ( 'i' ) . attr ( 'class' , 'fa fa-refresh fa-spin' ) ;
socket . emit ( 'admin.plugins.toggleInstall' , pluginID , function ( err , status ) {
socket . emit ( 'admin.plugins.toggleInstall' , {
id : pluginID ,
version : version
} , function ( err , status ) {
if ( err ) {
return app . alertError ( err . message ) ;
}
@ -62,38 +124,24 @@ define('admin/extend/plugins', function() {
type : 'info' ,
timeout : 5000
} ) ;
} ) ;
} ) ;
pluginsList . on ( 'click' , 'button[data-action="upgrade"]' , function ( ) {
var btn = $ ( this ) ;
var parent = btn . parents ( 'li' ) ;
pluginID = parent . attr ( 'data-plugin-id' ) ;
btn . attr ( 'disabled' , true ) . find ( 'i' ) . attr ( 'class' , 'fa fa-refresh fa-spin' ) ;
socket . emit ( 'admin.plugins.upgrade' , pluginID , function ( err ) {
if ( err ) {
return app . alertError ( err . message ) ;
if ( typeof callback === 'function' ) {
callback . apply ( this , arguments ) ;
}
parent . find ( '.fa-exclamation-triangle' ) . remove ( ) ;
parent . find ( '.currentVersion' ) . text ( parent . find ( '.latestVersion' ) . text ( ) ) ;
btn . remove ( ) ;
} ) ;
} ) ;
$ ( '#plugin-search' ) . on ( 'input propertychange' , function ( ) {
var term = $ ( this ) . val ( ) ;
$ ( '.plugins li' ) . each ( function ( ) {
var pluginId = $ ( this ) . attr ( 'data-plugin-id' ) ;
$ ( this ) . toggleClass ( 'hide' , pluginId && pluginId . indexOf ( term ) === - 1 ) ;
} ) ;
} ) ;
} else {
pluginsList . append ( '<li><p><i>No plugins found.</i></p></li>' ) ;
}
} ,
suggest : function ( pluginId , callback ) {
var nbbVersion = app . config . version ;
$ . ajax ( 'https://packages.nodebb.org/api/v1/suggest' , {
type : 'GET' ,
data : {
package : pluginId ,
version : nbbVersion
} ,
dataType : 'json'
} ) . done ( function ( payload ) {
callback ( undefined , payload ) ;
} ) . fail ( callback ) ;
}
} ;