2011-08-23 03:40:13 +04:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
|
2012-08-04 22:12:18 +04:00
|
|
|
* Copyright (c) 2012, Thomas Tanghus <thomas@tanghus.net>
|
2011-08-23 03:40:13 +04:00
|
|
|
* This file is licensed under the Affero General Public License version 3 or later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2012-08-04 22:12:18 +04:00
|
|
|
OC.Settings = OC.Settings || {};
|
|
|
|
OC.Settings.Apps = OC.Settings.Apps || {
|
2012-08-05 01:48:09 +04: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('');
|
|
|
|
}
|
2012-10-08 17:49:48 +04:00
|
|
|
page.find('span.score').html(app.score);
|
2013-03-04 03:19:07 +04:00
|
|
|
page.find('p.description').text(app.description);
|
2012-08-05 01:48:09 +04:00
|
|
|
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);
|
|
|
|
|
2013-01-21 23:40:23 +04:00
|
|
|
if (app.update != false) {
|
|
|
|
page.find('input.update').show();
|
|
|
|
page.find('input.update').data('appid', app.id);
|
2013-01-31 17:11:31 +04:00
|
|
|
page.find('input.update').attr('value',t('settings', 'Update to {appversion}', {appversion:app.update}));
|
2013-01-21 23:40:23 +04:00
|
|
|
} else {
|
|
|
|
page.find('input.update').hide();
|
|
|
|
}
|
|
|
|
|
2012-08-05 01:48:09 +04:00
|
|
|
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) {
|
2012-10-08 17:49:48 +04:00
|
|
|
page.find('span.score').show();
|
2012-08-05 01:48:09 +04:00
|
|
|
page.find('p.appslink').show();
|
|
|
|
page.find('a').attr('href', 'http://apps.owncloud.com/content/show.php?content=' + app.id);
|
2012-10-08 15:33:52 +04:00
|
|
|
page.find('small.externalapp').hide();
|
2012-08-05 01:48:09 +04:00
|
|
|
} else {
|
|
|
|
page.find('p.appslink').hide();
|
2012-10-08 17:49:48 +04:00
|
|
|
page.find('span.score').hide();
|
2012-08-05 01:48:09 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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);
|
2013-01-21 23:40:23 +04:00
|
|
|
element.val(t('settings','Please wait....'));
|
2012-08-05 01:48:09 +04:00
|
|
|
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);
|
2012-10-26 22:12:14 +04:00
|
|
|
OC.Settings.Apps.removeNavigation(appid);
|
2012-08-05 01:48:09 +04:00
|
|
|
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 {
|
2012-10-26 22:12:14 +04:00
|
|
|
OC.Settings.Apps.addNavigation(appid);
|
2012-08-05 01:48:09 +04:00
|
|
|
element.data('active',true);
|
|
|
|
element.val(t('settings','Disable'));
|
|
|
|
}
|
2013-03-23 15:19:43 +04:00
|
|
|
},'json')
|
|
|
|
.fail(function() {
|
|
|
|
OC.dialogs.alert('Error while enabling app','Error');
|
|
|
|
element.data('active',false);
|
|
|
|
OC.Settings.Apps.removeNavigation(appid);
|
|
|
|
element.val(t('settings','Enable'));
|
|
|
|
});
|
2012-08-05 01:48:09 +04:00
|
|
|
$('#leftcontent li[data-id="'+appid+'"]').addClass('active');
|
|
|
|
}
|
|
|
|
},
|
2013-01-21 23:40:23 +04:00
|
|
|
updateApp:function(appid, element) {
|
|
|
|
console.log('updateApp:', appid, element);
|
2013-02-01 03:51:00 +04:00
|
|
|
element.val(t('settings','Updating....'));
|
2013-01-21 23:40:23 +04:00
|
|
|
$.post(OC.filePath('settings','ajax','updateapp.php'),{appid:appid},function(result) {
|
|
|
|
if(!result || result.status!='success') {
|
2013-01-31 13:43:59 +04:00
|
|
|
OC.dialogs.alert(t('settings','Error while updating app'),t('settings','Error'));
|
2013-01-21 23:40:23 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
element.val(t('settings','Updated'));
|
|
|
|
element.hide();
|
|
|
|
}
|
|
|
|
},'json');
|
|
|
|
},
|
|
|
|
|
2012-08-04 22:12:18 +04:00
|
|
|
insertApp:function(appdata) {
|
|
|
|
var applist = $('#leftcontent li');
|
|
|
|
var app =
|
2012-08-05 01:48:09 +04: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+'">'
|
2012-08-04 22:12:18 +04:00
|
|
|
+ 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;
|
2012-10-26 22:12:14 +04:00
|
|
|
},
|
|
|
|
removeNavigation: function(appid){
|
2012-10-28 21:52:18 +04:00
|
|
|
$.getJSON(OC.filePath('settings', 'ajax', 'navigationdetect.php'), {app: appid}).done(function(response){
|
2012-10-26 22:12:14 +04:00
|
|
|
if(response.status === 'success'){
|
|
|
|
var navIds=response.nav_ids;
|
|
|
|
for(var i=0; i< navIds.length; i++){
|
|
|
|
$('#apps').children('li[data-id="'+navIds[i]+'"]').remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
addNavigation: function(appid){
|
2012-10-28 21:52:18 +04:00
|
|
|
$.getJSON(OC.filePath('settings', 'ajax', 'navigationdetect.php'), {app: appid}).done(function(response){
|
2012-10-26 22:12:14 +04:00
|
|
|
if(response.status === 'success'){
|
|
|
|
var navEntries=response.nav_entries;
|
|
|
|
for(var i=0; i< navEntries.length; i++){
|
|
|
|
var entry = navEntries[i];
|
|
|
|
var container = $('#apps');
|
|
|
|
|
|
|
|
if(container.children('li[data-id="'+entry.id+'"]').length === 0){
|
2013-02-05 14:30:18 +04:00
|
|
|
var li=$('<li></li>');
|
2012-10-26 22:12:14 +04:00
|
|
|
li.attr('data-id', entry.id);
|
2013-02-14 18:47:48 +04:00
|
|
|
var img= $('<img class="icon"/>').attr({ src: entry.icon});
|
2013-01-31 10:22:56 +04:00
|
|
|
var a=$('<a></a>').attr('href', entry.href);
|
2012-10-26 22:12:14 +04:00
|
|
|
a.text(entry.name);
|
2013-02-03 19:02:25 +04:00
|
|
|
a.prepend(img);
|
2012-10-26 22:12:14 +04:00
|
|
|
li.append(a);
|
|
|
|
container.append(li);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2012-08-04 22:12:18 +04:00
|
|
|
}
|
2012-09-06 00:17:33 +04:00
|
|
|
};
|
2012-08-04 22:12:18 +04:00
|
|
|
|
2011-08-10 14:20:43 +04:00
|
|
|
$(document).ready(function(){
|
|
|
|
$('#leftcontent li').each(function(index,li){
|
2012-08-31 00:17:54 +04:00
|
|
|
var app = OC.get('appData_'+$(li).data('id'));
|
2011-08-10 14:20:43 +04:00
|
|
|
$(li).data('app',app);
|
2012-08-04 22:12:18 +04:00
|
|
|
$(this).find('span.hidden').remove();
|
2011-08-10 14:20:43 +04:00
|
|
|
});
|
2012-05-04 19:54:52 +04:00
|
|
|
$('#leftcontent li').keydown(function(event) {
|
|
|
|
if (event.which == 13 || event.which == 32) {
|
2012-09-06 00:17:33 +04:00
|
|
|
$(event.target).click();
|
2012-05-04 19:54:52 +04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2012-08-04 22:12:18 +04:00
|
|
|
|
|
|
|
$(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-05 01:48:09 +04:00
|
|
|
OC.Settings.Apps.loadApp(app);
|
2012-06-04 01:48:59 +04:00
|
|
|
}
|
2012-05-04 19:54:52 +04:00
|
|
|
return false;
|
2011-08-10 14:20:43 +04:00
|
|
|
});
|
|
|
|
$('#rightcontent input.enable').click(function(){
|
2012-05-15 01:52:40 +04:00
|
|
|
var element = $(this);
|
2012-08-05 01:48:09 +04:00
|
|
|
var appid=$(this).data('appid');
|
2011-08-10 14:20:43 +04:00
|
|
|
var active=$(this).data('active');
|
2012-08-05 01:48:09 +04:00
|
|
|
if(appid) {
|
|
|
|
OC.Settings.Apps.enableApp(appid, active, element);
|
2011-08-10 14:20:43 +04:00
|
|
|
}
|
|
|
|
});
|
2013-01-21 23:40:23 +04:00
|
|
|
$('#rightcontent input.update').click(function(){
|
|
|
|
var element = $(this);
|
|
|
|
var appid=$(this).data('appid');
|
|
|
|
if(appid) {
|
|
|
|
OC.Settings.Apps.updateApp(appid, element);
|
|
|
|
}
|
|
|
|
});
|
2012-08-04 22:12:18 +04:00
|
|
|
|
2012-06-25 07:02:01 +04: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');
|
|
|
|
}
|
|
|
|
}
|
2011-08-10 14:20:43 +04:00
|
|
|
});
|