server/settings/js/apps.js

143 lines
4.5 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
* Copyright (c) 2012, Thomas Tanghus <thomas@tanghus.net>
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file.
*/
OC.Settings = OC.Settings || {};
OC.Settings.Apps = OC.Settings.Apps || {
loadOCS:function() {
$.getJSON(OC.filePath('settings', 'ajax', 'apps/ocs.php'), function(jsondata) {
if(jsondata.status == 'success'){
var apps = jsondata.data;
$.each(apps, function(b, appdata) {
OC.Settings.Apps.insertApp(appdata);
});
} else {
OC.dialogs.alert(jsondata.data.message, t('core', 'Error'));
}
});
},
2012-08-04 21:48:09 +00:00
loadApp:function(app) {
var page = $('#rightcontent');
page.find('p.license').show();
page.find('span.name').text(app.name);
page.find('small.externalapp').text(app.internallabel);
if (app.version) {
page.find('span.version').text(app.version);
} else {
page.find('span.version').text('');
}
page.find('p.description').text(app.description);
page.find('img.preview').attr('src', app.preview);
page.find('small.externalapp').attr('style', 'visibility:visible');
page.find('span.author').text(app.author);
page.find('span.licence').text(app.licence);
page.find('input.enable').show();
page.find('input.enable').val((app.active) ? t('settings', 'Disable') : t('settings', 'Enable'));
page.find('input.enable').data('appid', app.id);
page.find('input.enable').data('active', app.active);
if (app.internal == false) {
page.find('p.appslink').show();
page.find('a').attr('href', 'http://apps.owncloud.com/content/show.php?content=' + app.id);
} else {
page.find('p.appslink').hide();
}
},
enableApp:function(appid, active, element) {
console.log('enableApp:', appid, active, element);
var appitem=$('#leftcontent li[data-id="'+appid+'"]');
appData = appitem.data('app');
appData.active = !active;
appitem.data('app', appData);
if(active) {
$.post(OC.filePath('settings','ajax','disableapp.php'),{appid:appid},function(result) {
if(!result || result.status!='success') {
OC.dialogs.alert('Error while disabling app','Error');
}
else {
element.data('active',false);
element.val(t('settings','Enable'));
}
},'json');
$('#leftcontent li[data-id="'+appid+'"]').removeClass('active');
} else {
$.post(OC.filePath('settings','ajax','enableapp.php'),{appid:appid},function(result) {
if(!result || result.status!='success') {
OC.dialogs.alert('Error while enabling app','Error');
}
else {
element.data('active',true);
element.val(t('settings','Disable'));
}
},'json');
$('#leftcontent li[data-id="'+appid+'"]').addClass('active');
}
},
insertApp:function(appdata) {
var applist = $('#leftcontent li');
var app =
2012-08-04 21:48:09 +00:00
$('<li data-id="' + appdata.id + '" data-type="external" data-installed="0">'
+ '<a class="app externalapp" href="' + OC.filePath('settings', 'apps', 'index.php') + '&appid=' + appdata.id+'">'
+ appdata.name+'</a><small class="externalapp list">3rd party</small></li>');
app.data('app', appdata);
var added = false;
applist.each(function() {
if(!parseInt($(this).data('installed')) && $(this).find('a').text().toLowerCase() > appdata.name.toLowerCase()) {
$(this).before(app);
added = true;
return false; // dang, remember this to get out of loop
}
});
if(!added) {
applist.last().after(app);
}
return app;
}
}
2011-08-10 10:20:43 +00:00
$(document).ready(function(){
$('#leftcontent li').each(function(index,li){
var app = $.parseJSON($(this).children('span').text());
2011-08-10 10:20:43 +00:00
$(li).data('app',app);
$(this).find('span.hidden').remove();
2011-08-10 10:20:43 +00:00
});
$('#leftcontent li').keydown(function(event) {
if (event.which == 13 || event.which == 32) {
$(event.target).click()
}
return false;
});
$(document).on('click', '#leftcontent', function(event){
var tgt = $(event.target);
if (tgt.is('li') || tgt.is('a')) {
var item = tgt.is('li') ? $(tgt) : $(tgt).parent();
var app = item.data('app');
2012-08-04 21:48:09 +00:00
OC.Settings.Apps.loadApp(app);
}
return false;
2011-08-10 10:20:43 +00:00
});
$('#rightcontent input.enable').click(function(){
var element = $(this);
2012-08-04 21:48:09 +00:00
var appid=$(this).data('appid');
2011-08-10 10:20:43 +00:00
var active=$(this).data('active');
2012-08-04 21:48:09 +00:00
if(appid) {
OC.Settings.Apps.enableApp(appid, active, element);
2011-08-10 10:20:43 +00:00
}
});
2012-06-25 03:02:01 +00:00
if(appid) {
var item = $('#leftcontent li[data-id="'+appid+'"]');
if(item) {
item.trigger('click');
item.addClass('active');
$('#leftcontent').animate({scrollTop: $(item).offset().top-70}, 'slow','swing');
}
}
OC.Settings.Apps.loadOCS();
2011-08-10 10:20:43 +00:00
});