2014-08-14 13:48:38 +00:00
/* global Handlebars */
Handlebars . registerHelper ( 'score' , function ( ) {
if ( this . score ) {
var score = Math . round ( this . score / 10 ) ;
var imageName = 'rating/s' + score + '.png' ;
return new Handlebars . SafeString ( '<img src="' + OC . imagePath ( 'core' , imageName ) + '">' ) ;
}
return new Handlebars . SafeString ( '' ) ;
} ) ;
2015-03-30 13:58:20 +00:00
Handlebars . registerHelper ( 'level' , function ( ) {
if ( typeof this . level !== 'undefined' ) {
if ( this . level === 200 ) {
2015-05-30 11:39:12 +00:00
return new Handlebars . SafeString ( '<span class="official icon-checkmark">' + t ( 'settings' , 'Official' ) + '</span>' ) ;
2015-03-30 13:58:20 +00:00
} else if ( this . level === 100 ) {
2015-05-30 11:39:12 +00:00
return new Handlebars . SafeString ( '<span class="approved">' + t ( 'settings' , 'Approved' ) + '</span>' ) ;
2015-03-30 13:58:20 +00:00
} else {
2015-05-30 11:39:12 +00:00
return new Handlebars . SafeString ( '<span class="experimental">' + t ( 'settings' , 'Experimental' ) + '</span>' ) ;
2015-03-30 13:58:20 +00:00
}
}
} ) ;
2011-08-22 23:40:13 +00:00
2012-08-04 18:12:18 +00:00
OC . Settings = OC . Settings || { } ;
OC . Settings . Apps = OC . Settings . Apps || {
2014-08-14 13:48:38 +00:00
setupGroupsSelect : function ( $elements ) {
OC . Settings . setupGroupsSelect ( $elements , {
2014-09-09 16:00:53 +00:00
placeholder : t ( 'core' , 'All' )
} ) ;
} ,
2014-01-17 13:05:39 +00:00
2014-08-14 13:48:38 +00:00
State : {
currentCategory : null ,
apps : null
} ,
loadCategories : function ( ) {
2015-01-16 11:23:02 +00:00
if ( this . _loadCategoriesCall ) {
this . _loadCategoriesCall . abort ( ) ;
}
2014-08-14 13:48:38 +00:00
var categories = [
2015-10-15 14:15:42 +00:00
{ displayName : t ( 'settings' , 'Enabled' ) , id : '0' } ,
{ displayName : t ( 'settings' , 'Not enabled' ) , id : '1' }
2014-08-14 13:48:38 +00:00
] ;
var source = $ ( "#categories-template" ) . html ( ) ;
var template = Handlebars . compile ( source ) ;
var html = template ( categories ) ;
$ ( '#apps-categories' ) . html ( html ) ;
2015-10-15 14:15:42 +00:00
OC . Settings . Apps . loadCategory ( parseInt ( $ ( '#app-navigation' ) . attr ( 'data-category' ) , 10 ) ) ;
2014-08-14 13:48:38 +00:00
2015-01-16 11:23:02 +00:00
this . _loadCategoriesCall = $ . ajax ( OC . generateUrl ( 'settings/apps/categories' ) , {
2014-08-14 13:48:38 +00:00
data : { } ,
type : 'GET' ,
success : function ( jsondata ) {
var html = template ( jsondata ) ;
$ ( '#apps-categories' ) . html ( html ) ;
$ ( '#app-category-' + OC . Settings . Apps . State . currentCategory ) . addClass ( 'active' ) ;
} ,
complete : function ( ) {
$ ( '#app-navigation' ) . removeClass ( 'icon-loading' ) ;
2014-05-25 20:14:46 +00:00
}
2014-08-14 13:48:38 +00:00
} ) ;
2014-01-17 13:05:39 +00:00
2014-08-14 13:48:38 +00:00
} ,
2014-01-17 13:05:39 +00:00
2014-08-14 13:48:38 +00:00
loadCategory : function ( categoryId ) {
if ( OC . Settings . Apps . State . currentCategory === categoryId ) {
return ;
2013-01-21 19:40:23 +00:00
}
2015-01-16 11:23:02 +00:00
if ( this . _loadCategoryCall ) {
this . _loadCategoryCall . abort ( ) ;
}
2014-08-14 13:48:38 +00:00
$ ( '#apps-list' )
. addClass ( 'icon-loading' )
2015-03-24 09:27:00 +00:00
. removeClass ( 'hidden' )
2014-08-14 13:48:38 +00:00
. html ( '' ) ;
2015-03-24 09:27:00 +00:00
$ ( '#apps-list-empty' ) . addClass ( 'hidden' ) ;
2014-08-14 13:48:38 +00:00
$ ( '#app-category-' + OC . Settings . Apps . State . currentCategory ) . removeClass ( 'active' ) ;
$ ( '#app-category-' + categoryId ) . addClass ( 'active' ) ;
OC . Settings . Apps . State . currentCategory = categoryId ;
2013-01-21 19:40:23 +00:00
2015-06-10 10:01:54 +00:00
this . _loadCategoryCall = $ . ajax ( OC . generateUrl ( 'settings/apps/list?category={categoryId}&includeUpdateInfo=0' , {
2014-08-14 13:48:38 +00:00
categoryId : categoryId
} ) , {
type : 'GET' ,
2015-03-24 09:27:00 +00:00
success : function ( apps ) {
2015-07-02 15:15:14 +00:00
var appListWithIndex = _ . indexBy ( apps . apps , 'id' ) ;
OC . Settings . Apps . State . apps = appListWithIndex ;
var appList = _ . map ( appListWithIndex , function ( app ) {
2015-05-20 11:43:20 +00:00
// default values for missing fields
return _ . extend ( { level : 0 } , app ) ;
} ) ;
2014-08-14 13:48:38 +00:00
var source = $ ( "#app-template" ) . html ( ) ;
var template = Handlebars . compile ( source ) ;
2015-05-20 11:43:20 +00:00
if ( appList . length ) {
appList . sort ( function ( a , b ) {
var levelDiff = b . level - a . level ;
if ( levelDiff === 0 ) {
return OC . Util . naturalSortCompare ( a . name , b . name ) ;
}
return levelDiff ;
2015-03-30 13:58:20 +00:00
} ) ;
var firstExperimental = false ;
2015-05-20 11:43:20 +00:00
_ . each ( appList , function ( app ) {
2015-03-30 13:58:20 +00:00
if ( app . level === 0 && firstExperimental === false ) {
firstExperimental = true ;
OC . Settings . Apps . renderApp ( app , template , null , true ) ;
} else {
OC . Settings . Apps . renderApp ( app , template , null , false ) ;
}
2015-03-24 09:27:00 +00:00
} ) ;
} else {
$ ( '#apps-list' ) . addClass ( 'hidden' ) ;
2015-10-20 08:58:07 +00:00
$ ( '#apps-list-empty' ) . removeClass ( 'hidden' ) . find ( 'h2' ) . text ( t ( 'settings' , 'No apps found for your version' ) ) ;
2015-03-24 09:27:00 +00:00
}
2015-03-30 13:58:20 +00:00
2015-05-30 11:39:12 +00:00
$ ( '.app-level .official' ) . tipsy ( { fallback : t ( 'settings' , 'Official apps are developed by and within the ownCloud community. They offer functionality central to ownCloud and are ready for production use.' ) } ) ;
$ ( '.app-level .approved' ) . tipsy ( { fallback : t ( 'settings' , 'Approved apps are developed by trusted developers and have passed a cursory security check. They are actively maintained in an open code repository and their maintainers deem them to be stable for casual to normal use.' ) } ) ;
2015-06-23 08:59:15 +00:00
$ ( '.app-level .experimental' ) . tipsy ( { fallback : t ( 'settings' , 'This app is not checked for security issues and is new or known to be unstable. Install at your own risk.' ) } ) ;
2014-08-14 13:48:38 +00:00
} ,
complete : function ( ) {
$ ( '#apps-list' ) . removeClass ( 'icon-loading' ) ;
2015-06-10 10:01:54 +00:00
$ . ajax ( OC . generateUrl ( 'settings/apps/list?category={categoryId}&includeUpdateInfo=1' , {
categoryId : categoryId
} ) , {
type : 'GET' ,
success : function ( apps ) {
_ . each ( apps . apps , function ( app ) {
if ( app . update ) {
var $update = $ ( '#app-' + app . id + ' .update' ) ;
$update . removeClass ( 'hidden' ) ;
$update . val ( t ( 'settings' , 'Update to %s' ) . replace ( /%s/g , app . update ) ) ;
}
} )
}
} ) ;
2014-08-14 13:48:38 +00:00
}
} ) ;
} ,
2015-03-30 13:58:20 +00:00
renderApp : function ( app , template , selector , firstExperimental ) {
2014-08-14 13:48:38 +00:00
if ( ! template ) {
var source = $ ( "#app-template" ) . html ( ) ;
template = Handlebars . compile ( source ) ;
}
if ( typeof app === 'string' ) {
app = OC . Settings . Apps . State . apps [ app ] ;
2014-05-31 15:50:39 +00:00
}
2015-03-30 13:58:20 +00:00
app . firstExperimental = firstExperimental ;
2014-05-31 15:50:39 +00:00
2014-08-14 13:48:38 +00:00
var html = template ( app ) ;
if ( selector ) {
selector . html ( html ) ;
2012-08-04 21:48:09 +00:00
} else {
2014-08-14 13:48:38 +00:00
$ ( '#apps-list' ) . append ( html ) ;
2012-08-04 21:48:09 +00:00
}
2014-08-14 13:48:38 +00:00
var page = $ ( '#app-' + app . id ) ;
2015-10-21 08:50:06 +00:00
// image loading kung-fu (IE doesn't properly scale SVGs, so disable app icons)
if ( app . preview && ! OC . Util . isIE ( ) ) {
2014-08-14 13:48:38 +00:00
var currentImage = new Image ( ) ;
currentImage . src = app . preview ;
currentImage . onload = function ( ) {
page . find ( '.app-image' )
. append ( this )
. fadeIn ( ) ;
} ;
2013-08-18 11:49:34 +00:00
}
2014-04-18 12:29:45 +00:00
2014-08-14 13:48:38 +00:00
// set group select properly
2014-04-28 11:27:32 +00:00
if ( OC . Settings . Apps . isType ( app , 'filesystem' ) || OC . Settings . Apps . isType ( app , 'prelogin' ) ||
OC . Settings . Apps . isType ( app , 'authentication' ) || OC . Settings . Apps . isType ( app , 'logging' ) ) {
2014-08-14 13:48:38 +00:00
page . find ( ".groups-enable" ) . hide ( ) ;
page . find ( "label[for='groups_enable-" + app . id + "']" ) . hide ( ) ;
page . find ( ".groups-enable" ) . attr ( 'checked' , null ) ;
2014-04-28 11:27:32 +00:00
} else {
2015-04-02 13:47:48 +00:00
page . find ( '#group_select' ) . val ( ( app . groups || [ ] ) . join ( '|' ) ) ;
2014-04-28 11:27:32 +00:00
if ( app . active ) {
if ( app . groups . length ) {
2014-08-14 13:48:38 +00:00
OC . Settings . Apps . setupGroupsSelect ( page . find ( '#group_select' ) ) ;
page . find ( ".groups-enable" ) . attr ( 'checked' , 'checked' ) ;
2014-04-28 11:27:32 +00:00
} else {
2014-08-14 13:48:38 +00:00
page . find ( ".groups-enable" ) . attr ( 'checked' , null ) ;
2014-04-28 11:27:32 +00:00
}
2014-08-14 13:48:38 +00:00
page . find ( ".groups-enable" ) . show ( ) ;
page . find ( "label[for='groups_enable-" + app . id + "']" ) . show ( ) ;
2014-04-28 11:27:32 +00:00
} else {
2014-08-14 13:48:38 +00:00
page . find ( ".groups-enable" ) . hide ( ) ;
page . find ( "label[for='groups_enable-" + app . id + "']" ) . hide ( ) ;
2014-04-28 11:27:32 +00:00
}
2014-04-18 12:29:45 +00:00
}
2012-08-04 21:48:09 +00:00
} ,
2014-08-14 13:48:38 +00:00
isType : function ( app , type ) {
return app . types && app . types . indexOf ( type ) !== - 1 ;
} ,
enableApp : function ( appId , active , element , groups ) {
OC . Settings . Apps . hideErrorMessage ( appId ) ;
2014-04-18 12:29:45 +00:00
groups = groups || [ ] ;
2014-08-14 13:48:38 +00:00
var appItem = $ ( 'div#app-' + appId + '' ) ;
2013-01-21 19:40:23 +00:00
element . val ( t ( 'settings' , 'Please wait....' ) ) ;
2014-04-18 12:29:45 +00:00
if ( active && ! groups . length ) {
2014-08-14 13:48:38 +00:00
$ . post ( OC . filePath ( 'settings' , 'ajax' , 'disableapp.php' ) , { appid : appId } , function ( result ) {
2013-04-17 13:32:03 +00:00
if ( ! result || result . status !== 'success' ) {
2013-08-06 15:19:18 +00:00
if ( result . data && result . data . message ) {
2014-08-14 13:48:38 +00:00
OC . Settings . Apps . showErrorMessage ( appId , result . data . message ) ;
appItem . data ( 'errormsg' , result . data . message ) ;
2013-08-06 15:19:18 +00:00
} else {
2014-08-14 13:48:38 +00:00
OC . Settings . Apps . showErrorMessage ( appId , t ( 'settings' , 'Error while disabling app' ) ) ;
appItem . data ( 'errormsg' , t ( 'settings' , 'Error while disabling app' ) ) ;
2013-08-06 15:19:18 +00:00
}
2013-08-18 11:49:34 +00:00
element . val ( t ( 'settings' , 'Disable' ) ) ;
2014-08-14 13:48:38 +00:00
appItem . addClass ( 'appwarning' ) ;
} else {
2015-09-05 01:24:18 +00:00
OC . Settings . Apps . rebuildNavigation ( ) ;
2014-08-14 13:48:38 +00:00
appItem . data ( 'active' , false ) ;
appItem . data ( 'groups' , '' ) ;
2013-09-20 18:29:15 +00:00
element . data ( 'active' , false ) ;
2014-08-14 13:48:38 +00:00
appItem . removeClass ( 'active' ) ;
2012-08-04 21:48:09 +00:00
element . val ( t ( 'settings' , 'Enable' ) ) ;
2014-08-14 13:48:38 +00:00
element . parent ( ) . find ( ".groups-enable" ) . hide ( ) ;
element . parent ( ) . find ( "#groups_enable-" + appId ) . hide ( ) ;
element . parent ( ) . find ( "label[for='groups_enable-" + appId + "']" ) . hide ( ) ;
element . parent ( ) . find ( '#group_select' ) . hide ( ) . val ( null ) ;
OC . Settings . Apps . State . apps [ appId ] . active = false ;
2012-08-04 21:48:09 +00:00
}
} , 'json' ) ;
} else {
2014-08-14 13:48:38 +00:00
$ . post ( OC . filePath ( 'settings' , 'ajax' , 'enableapp.php' ) , { appid : appId , groups : groups } , function ( result ) {
2013-04-17 13:32:03 +00:00
if ( ! result || result . status !== 'success' ) {
2013-08-06 15:19:18 +00:00
if ( result . data && result . data . message ) {
2014-08-14 13:48:38 +00:00
OC . Settings . Apps . showErrorMessage ( appId , result . data . message ) ;
appItem . data ( 'errormsg' , result . data . message ) ;
2013-08-06 15:19:18 +00:00
} else {
2014-08-14 13:48:38 +00:00
OC . Settings . Apps . showErrorMessage ( appId , t ( 'settings' , 'Error while enabling app' ) ) ;
appItem . data ( 'errormsg' , t ( 'settings' , 'Error while disabling app' ) ) ;
2013-08-06 15:19:18 +00:00
}
element . val ( t ( 'settings' , 'Enable' ) ) ;
2014-08-14 13:48:38 +00:00
appItem . addClass ( 'appwarning' ) ;
2013-08-06 15:19:18 +00:00
} else {
2015-10-02 10:15:07 +00:00
if ( result . data . update _required ) {
2015-10-02 12:12:29 +00:00
OC . Settings . Apps . showReloadMessage ( ) ;
2015-10-02 10:15:07 +00:00
setTimeout ( function ( ) {
location . reload ( ) ;
} , 5000 ) ;
}
2015-09-05 01:24:18 +00:00
OC . Settings . Apps . rebuildNavigation ( ) ;
2014-08-14 13:48:38 +00:00
appItem . data ( 'active' , true ) ;
2013-09-20 18:29:15 +00:00
element . data ( 'active' , true ) ;
2014-08-14 13:48:38 +00:00
appItem . addClass ( 'active' ) ;
2012-08-04 21:48:09 +00:00
element . val ( t ( 'settings' , 'Disable' ) ) ;
2014-08-14 13:48:38 +00:00
var app = OC . Settings . Apps . State . apps [ appId ] ;
2014-05-06 10:41:06 +00:00
app . active = true ;
2014-08-14 13:48:38 +00:00
2014-05-06 10:41:06 +00:00
if ( OC . Settings . Apps . isType ( app , 'filesystem' ) || OC . Settings . Apps . isType ( app , 'prelogin' ) ||
OC . Settings . Apps . isType ( app , 'authentication' ) || OC . Settings . Apps . isType ( app , 'logging' ) ) {
2014-08-14 13:48:38 +00:00
element . parent ( ) . find ( ".groups-enable" ) . attr ( 'checked' , null ) ;
element . parent ( ) . find ( "#groups_enable-" + appId ) . hide ( ) ;
element . parent ( ) . find ( "label[for='groups_enable-" + appId + "']" ) . hide ( ) ;
element . parent ( ) . find ( ".groups-enable" ) . hide ( ) ;
element . parent ( ) . find ( "#groups_enable-" + appId ) . hide ( ) ;
element . parent ( ) . find ( "label[for='groups_enable-" + appId + "']" ) . hide ( ) ;
element . parent ( ) . find ( '#group_select' ) . hide ( ) . val ( null ) ;
2014-04-18 12:29:45 +00:00
} else {
2014-08-14 13:48:38 +00:00
element . parent ( ) . find ( "#groups_enable-" + appId ) . show ( ) ;
element . parent ( ) . find ( "label[for='groups_enable-" + appId + "']" ) . show ( ) ;
2014-05-06 10:41:06 +00:00
if ( groups ) {
2014-08-14 13:48:38 +00:00
appItem . data ( 'groups' , JSON . stringify ( groups ) ) ;
2014-05-06 10:41:06 +00:00
} else {
2014-08-14 13:48:38 +00:00
appItem . data ( 'groups' , '' ) ;
2014-05-06 10:41:06 +00:00
}
2014-04-18 12:29:45 +00:00
}
2012-08-04 21:48:09 +00:00
}
2013-03-23 11:19:43 +00:00
} , 'json' )
2014-08-14 13:48:38 +00:00
. fail ( function ( ) {
OC . Settings . Apps . showErrorMessage ( appId , t ( 'settings' , 'Error while enabling app' ) ) ;
appItem . data ( 'errormsg' , t ( 'settings' , 'Error while enabling app' ) ) ;
appItem . data ( 'active' , false ) ;
appItem . addClass ( 'appwarning' ) ;
element . val ( t ( 'settings' , 'Enable' ) ) ;
} ) ;
2012-08-04 21:48:09 +00:00
}
} ,
2014-08-14 13:48:38 +00:00
updateApp : function ( appId , element ) {
var oldButtonText = element . val ( ) ;
2013-01-31 23:51:00 +00:00
element . val ( t ( 'settings' , 'Updating....' ) ) ;
2014-08-14 13:48:38 +00:00
OC . Settings . Apps . hideErrorMessage ( appId ) ;
$ . post ( OC . filePath ( 'settings' , 'ajax' , 'updateapp.php' ) , { appid : appId } , function ( result ) {
2013-04-17 13:32:03 +00:00
if ( ! result || result . status !== 'success' ) {
2015-03-11 08:59:56 +00:00
if ( result . data && result . data . message ) {
OC . Settings . Apps . showErrorMessage ( appId , result . data . message ) ;
} else {
OC . Settings . Apps . showErrorMessage ( appId , t ( 'settings' , 'Error while updating app' ) ) ;
}
2014-08-14 13:48:38 +00:00
element . val ( oldButtonText ) ;
2013-01-21 19:40:23 +00:00
}
else {
element . val ( t ( 'settings' , 'Updated' ) ) ;
element . hide ( ) ;
}
} , 'json' ) ;
} ,
2014-08-14 13:48:38 +00:00
uninstallApp : function ( appId , element ) {
OC . Settings . Apps . hideErrorMessage ( appId ) ;
2014-05-31 15:50:39 +00:00
element . val ( t ( 'settings' , 'Uninstalling ....' ) ) ;
2014-08-14 13:48:38 +00:00
$ . post ( OC . filePath ( 'settings' , 'ajax' , 'uninstallapp.php' ) , { appid : appId } , function ( result ) {
2014-05-31 15:50:39 +00:00
if ( ! result || result . status !== 'success' ) {
2014-08-14 13:48:38 +00:00
OC . Settings . Apps . showErrorMessage ( appId , t ( 'settings' , 'Error while uninstalling app' ) ) ;
2014-05-31 15:50:39 +00:00
element . val ( t ( 'settings' , 'Uninstall' ) ) ;
} else {
2015-09-05 01:24:18 +00:00
OC . Settings . Apps . rebuildNavigation ( ) ;
2014-08-14 13:48:38 +00:00
element . parent ( ) . fadeOut ( function ( ) {
element . remove ( ) ;
} ) ;
2014-05-31 15:50:39 +00:00
}
} , 'json' ) ;
} ,
2013-01-21 19:40:23 +00:00
2015-09-05 01:24:18 +00:00
rebuildNavigation : function ( ) {
$ . getJSON ( OC . filePath ( 'settings' , 'ajax' , 'navigationdetect.php' ) ) . done ( function ( response ) {
2012-10-26 18:12:14 +00:00
if ( response . status === 'success' ) {
2015-09-05 01:24:18 +00:00
var idsToKeep = { } ;
2012-10-26 18:12:14 +00:00
var navEntries = response . nav _entries ;
2015-09-05 01:24:18 +00:00
var container = $ ( '#apps ul' ) ;
2012-10-26 18:12:14 +00:00
for ( var i = 0 ; i < navEntries . length ; i ++ ) {
var entry = navEntries [ i ] ;
2015-09-05 01:24:18 +00:00
idsToKeep [ entry . id ] = true ;
2012-10-26 18:12:14 +00:00
if ( container . children ( 'li[data-id="' + entry . id + '"]' ) . length === 0 ) {
2013-02-05 10:30:18 +00:00
var li = $ ( '<li></li>' ) ;
2012-10-26 18:12:14 +00:00
li . attr ( 'data-id' , entry . id ) ;
2014-08-05 12:23:25 +00:00
var img = $ ( '<img class="app-icon"/>' ) . attr ( { src : entry . icon } ) ;
2013-01-31 06:22:56 +00:00
var a = $ ( '<a></a>' ) . attr ( 'href' , entry . href ) ;
2013-06-28 20:10:40 +00:00
var filename = $ ( '<span></span>' ) ;
2015-04-23 19:39:59 +00:00
var loading = $ ( '<div class="icon-loading-dark"></div>' ) . css ( 'display' , 'none' ) ;
2013-04-12 12:45:59 +00:00
filename . text ( entry . name ) ;
a . prepend ( filename ) ;
2015-04-23 19:39:59 +00:00
a . prepend ( loading ) ;
2013-02-03 15:02:25 +00:00
a . prepend ( img ) ;
2012-10-26 18:12:14 +00:00
li . append ( a ) ;
2014-02-26 09:34:38 +00:00
// append the new app as last item in the list
2014-06-04 16:22:40 +00:00
// which is the "add apps" entry with the id
// #apps-management
$ ( '#apps-management' ) . before ( li ) ;
2014-02-26 09:34:38 +00:00
// scroll the app navigation down
// so the newly added app is seen
$ ( '#navigation' ) . animate ( {
scrollTop : $ ( '#navigation' ) . height ( )
} , 'slow' ) ;
// draw attention to the newly added app entry
// by flashing it twice
2014-06-04 16:22:40 +00:00
$ ( '#header .menutoggle' )
2014-06-05 08:52:06 +00:00
. animate ( { opacity : 0.5 } )
2014-02-26 09:34:38 +00:00
. animate ( { opacity : 1 } )
2014-06-05 08:52:06 +00:00
. animate ( { opacity : 0.5 } )
2014-06-04 16:22:40 +00:00
. animate ( { opacity : 1 } )
2014-06-05 08:52:06 +00:00
. animate ( { opacity : 0.75 } ) ;
2013-08-07 19:54:28 +00:00
2014-08-14 13:48:38 +00:00
if ( ! OC . Util . hasSVGSupport ( ) && entry . icon . match ( /\.svg$/i ) ) {
2013-06-28 20:10:40 +00:00
$ ( img ) . addClass ( 'svg' ) ;
2014-08-14 13:48:38 +00:00
OC . Util . replaceSVG ( ) ;
2013-06-28 20:10:40 +00:00
}
2012-10-26 18:12:14 +00:00
}
}
2015-09-05 01:24:18 +00:00
container . children ( 'li[data-id]' ) . each ( function ( index , el ) {
if ( ! idsToKeep [ $ ( el ) . data ( 'id' ) ] ) {
$ ( el ) . remove ( ) ;
}
} ) ;
2012-10-26 18:12:14 +00:00
}
} ) ;
2013-08-18 11:49:34 +00:00
} ,
2014-08-14 13:48:38 +00:00
showErrorMessage : function ( appId , message ) {
$ ( 'div#app-' + appId + ' .warning' )
. show ( )
. text ( message ) ;
2014-04-28 11:27:32 +00:00
} ,
2014-08-14 13:48:38 +00:00
hideErrorMessage : function ( appId ) {
$ ( 'div#app-' + appId + ' .warning' )
. hide ( )
. text ( '' ) ;
2015-01-18 13:52:19 +00:00
} ,
2015-10-15 14:15:42 +00:00
showReloadMessage : function ( ) {
2015-10-02 12:12:29 +00:00
OC . dialogs . info (
t (
'settings' ,
2015-10-06 09:34:06 +00:00
'The app has been enabled but needs to be updated. You will be redirected to the update page in 5 seconds.'
2015-10-02 12:12:29 +00:00
) ,
t ( 'settings' , 'App update' ) ,
2015-10-15 14:15:42 +00:00
function ( ) {
2015-10-02 12:12:29 +00:00
window . location . reload ( ) ;
} ,
true
) ;
} ,
2015-01-18 13:52:19 +00:00
filter : function ( query ) {
2015-10-15 15:00:00 +00:00
var $appList = $ ( '#apps-list' ) ,
$emptyList = $ ( '#apps-list-empty' ) ;
2015-10-20 08:58:07 +00:00
$appList . removeClass ( 'hidden' ) ;
$appList . find ( '.section' ) . removeClass ( 'hidden' ) ;
$emptyList . addClass ( 'hidden' ) ;
2015-10-15 14:31:28 +00:00
if ( query === '' ) {
return ;
}
2015-10-20 08:58:07 +00:00
2015-01-18 13:52:19 +00:00
query = query . toLowerCase ( ) ;
2015-10-15 14:31:28 +00:00
$appList . find ( '.section' ) . addClass ( 'hidden' ) ;
2015-01-18 13:52:19 +00:00
2015-10-15 14:31:28 +00:00
// App Name
2015-01-18 13:52:19 +00:00
var apps = _ . filter ( OC . Settings . Apps . State . apps , function ( app ) {
return app . name . toLowerCase ( ) . indexOf ( query ) !== - 1 ;
} ) ;
2015-10-15 14:31:28 +00:00
// App Description
2015-01-18 13:52:19 +00:00
apps = apps . concat ( _ . filter ( OC . Settings . Apps . State . apps , function ( app ) {
return app . description . toLowerCase ( ) . indexOf ( query ) !== - 1 ;
} ) ) ;
2015-10-15 14:31:28 +00:00
// Author Name
apps = apps . concat ( _ . filter ( OC . Settings . Apps . State . apps , function ( app ) {
return app . author . toLowerCase ( ) . indexOf ( query ) !== - 1 ;
} ) ) ;
// App status
if ( t ( 'settings' , 'Official' ) . toLowerCase ( ) . indexOf ( query ) !== - 1 ) {
apps = apps . concat ( _ . filter ( OC . Settings . Apps . State . apps , function ( app ) {
return app . level === 200 ;
} ) ) ;
}
if ( t ( 'settings' , 'Approved' ) . toLowerCase ( ) . indexOf ( query ) !== - 1 ) {
apps = apps . concat ( _ . filter ( OC . Settings . Apps . State . apps , function ( app ) {
return app . level === 100 ;
} ) ) ;
}
if ( t ( 'settings' , 'Experimental' ) . toLowerCase ( ) . indexOf ( query ) !== - 1 ) {
apps = apps . concat ( _ . filter ( OC . Settings . Apps . State . apps , function ( app ) {
return app . level !== 100 && app . level !== 200 ;
} ) ) ;
}
2015-01-18 13:52:19 +00:00
apps = _ . uniq ( apps , function ( app ) { return app . id ; } ) ;
2015-10-15 15:00:00 +00:00
if ( apps . length === 0 ) {
$appList . addClass ( 'hidden' ) ;
$emptyList . removeClass ( 'hidden' ) ;
2015-10-20 08:58:07 +00:00
$emptyList . removeClass ( 'hidden' ) . find ( 'h2' ) . text ( t ( 'settings' , 'No apps found for "{query}"' , {
query : query
} ) ) ;
2015-10-15 15:00:00 +00:00
} else {
_ . each ( apps , function ( app ) {
$ ( '#app-' + app . id ) . removeClass ( 'hidden' ) ;
} ) ;
2015-01-18 13:52:19 +00:00
2015-10-15 15:00:00 +00:00
$ ( '#searchresults' ) . hide ( ) ;
}
2015-02-23 14:29:25 +00:00
} ,
2014-08-14 13:48:38 +00:00
2015-02-23 14:29:25 +00:00
/ * *
* Initializes the apps list
* /
initialize : function ( $el ) {
OC . Plugins . register ( 'OCA.Search' , OC . Settings . Apps . Search ) ;
OC . Settings . Apps . loadCategories ( ) ;
2012-08-04 18:12:18 +00:00
2015-02-23 14:29:25 +00:00
$ ( document ) . on ( 'click' , 'ul#apps-categories li' , function ( ) {
var categoryId = $ ( this ) . data ( 'categoryId' ) ;
OC . Settings . Apps . loadCategory ( categoryId ) ;
2015-10-15 14:15:42 +00:00
OC . Util . History . pushState ( 'category=' + categoryId ) ;
2015-10-15 14:50:31 +00:00
$ ( '#searchbox' ) . val ( '' ) ;
2015-02-23 14:29:25 +00:00
} ) ;
2012-08-04 18:12:18 +00:00
2015-03-06 15:28:38 +00:00
$ ( document ) . on ( 'click' , '.app-description-toggle-show' , function ( ) {
$ ( this ) . addClass ( 'hidden' ) ;
$ ( this ) . siblings ( '.app-description-toggle-hide' ) . removeClass ( 'hidden' ) ;
$ ( this ) . siblings ( '.app-description-container' ) . slideDown ( ) ;
} ) ;
$ ( document ) . on ( 'click' , '.app-description-toggle-hide' , function ( ) {
$ ( this ) . addClass ( 'hidden' ) ;
$ ( this ) . siblings ( '.app-description-toggle-show' ) . removeClass ( 'hidden' ) ;
$ ( this ) . siblings ( '.app-description-container' ) . slideUp ( ) ;
} ) ;
2015-02-23 14:29:25 +00:00
$ ( document ) . on ( 'click' , '#apps-list input.enable' , function ( ) {
var appId = $ ( this ) . data ( 'appid' ) ;
var element = $ ( this ) ;
var active = $ ( this ) . data ( 'active' ) ;
2014-08-14 13:48:38 +00:00
2015-02-23 14:29:25 +00:00
OC . Settings . Apps . enableApp ( appId , active , element ) ;
} ) ;
2014-08-14 13:48:38 +00:00
2015-02-23 14:29:25 +00:00
$ ( document ) . on ( 'click' , '#apps-list input.uninstall' , function ( ) {
var appId = $ ( this ) . data ( 'appid' ) ;
var element = $ ( this ) ;
2014-08-14 13:48:38 +00:00
2015-02-23 14:29:25 +00:00
OC . Settings . Apps . uninstallApp ( appId , element ) ;
} ) ;
2014-08-14 13:48:38 +00:00
2015-02-23 14:29:25 +00:00
$ ( document ) . on ( 'click' , '#apps-list input.update' , function ( ) {
var appId = $ ( this ) . data ( 'appid' ) ;
var element = $ ( this ) ;
2014-08-14 13:48:38 +00:00
2015-02-23 14:29:25 +00:00
OC . Settings . Apps . updateApp ( appId , element ) ;
} ) ;
2014-08-14 13:48:38 +00:00
2015-02-23 14:29:25 +00:00
$ ( document ) . on ( 'change' , '#group_select' , function ( ) {
var element = $ ( this ) . parent ( ) . find ( 'input.enable' ) ;
var groups = $ ( this ) . val ( ) ;
if ( groups && groups !== '' ) {
2015-03-24 11:56:42 +00:00
groups = groups . split ( '|' ) ;
2015-02-23 14:29:25 +00:00
} else {
groups = [ ] ;
}
2012-08-04 18:12:18 +00:00
2015-02-23 14:29:25 +00:00
var appId = element . data ( 'appid' ) ;
if ( appId ) {
OC . Settings . Apps . enableApp ( appId , false , element , groups ) ;
OC . Settings . Apps . State . apps [ appId ] . groups = groups ;
}
} ) ;
2014-04-18 12:29:45 +00:00
2015-02-23 14:29:25 +00:00
$ ( document ) . on ( 'change' , ".groups-enable" , function ( ) {
var $select = $ ( this ) . parent ( ) . find ( '#group_select' ) ;
$select . val ( '' ) ;
2014-04-18 12:29:45 +00:00
2015-02-23 14:29:25 +00:00
if ( this . checked ) {
OC . Settings . Apps . setupGroupsSelect ( $select ) ;
} else {
$select . select2 ( 'destroy' ) ;
}
2014-08-14 13:48:38 +00:00
2015-02-23 14:29:25 +00:00
$select . change ( ) ;
} ) ;
2014-08-14 13:48:38 +00:00
2015-03-30 13:58:20 +00:00
$ ( document ) . on ( 'click' , '#enable-experimental-apps' , function ( ) {
2015-10-15 14:15:42 +00:00
var state = $ ( this ) . prop ( 'checked' ) ;
2015-03-30 13:58:20 +00:00
$ . ajax ( OC . generateUrl ( 'settings/apps/experimental' ) , {
data : { state : state } ,
type : 'POST' ,
success : function ( ) {
location . reload ( ) ;
}
} ) ;
} ) ;
2015-02-23 14:29:25 +00:00
}
} ;
2014-08-14 13:48:38 +00:00
2015-02-23 14:29:25 +00:00
OC . Settings . Apps . Search = {
attach : function ( search ) {
search . setFilter ( 'settings' , OC . Settings . Apps . filter ) ;
}
} ;
$ ( document ) . ready ( function ( ) {
// HACK: FIXME: use plugin approach
if ( ! window . TESTING ) {
OC . Settings . Apps . initialize ( $ ( '#apps-list' ) ) ;
}
2011-08-10 10:20:43 +00:00
} ) ;