Blame view
sources/settings/js/apps.js
14 KB
|
03e52840d
|
1 2 3 4 5 6 7 8 9 10 |
/**
* 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 || {
loadApp:function(app) {
|
|
6d9380f96
|
11 |
var page = $('#app-content');
|
|
03e52840d
|
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
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('span.score').html(app.score);
page.find('p.description').text(app.description);
page.find('img.preview').attr('src', app.preview);
if (app.preview && app.preview.length) {
page.find('img.preview').show();
} else {
page.find('img.preview').hide();
}
page.find('small.externalapp').attr('style', 'visibility:visible');
page.find('span.author').text(app.author);
|
|
03e52840d
|
30 |
|
|
31b7f2792
|
31 32 33 34 35 36 37 38 |
// FIXME licenses of downloaded apps go into app.licence, licenses of not-downloaded apps into app.license
var appLicense = '';
if (typeof(app.licence) !== 'undefined') {
appLicense = app.licence;
} else if (typeof(app.license) !== 'undefined') {
appLicense = app.license;
}
page.find('span.licence').text(appLicense);
|
|
a293d369c
|
39 40 41 42 43 44 45 46 |
var userDocumentation = false;
var adminDocumentation = false;
if (typeof(app.documentation) !== 'undefined') {
if (typeof(app.documentation.user) !== 'undefined') {
userDocumentation = true;
page.find('span.userDocumentation').html("<a id='userDocumentation' href='" + app.documentation.user + "'>" + t('settings', 'User Documentation') + "</a>");
page.find('p.documentation').show();
}
|
|
6d9380f96
|
47 48 49 50 |
else {
page.find('span.userDocumentation').empty();
userDocumentation = false;
}
|
|
a293d369c
|
51 52 53 54 55 |
if (typeof(app.documentation.admin) !== 'undefined') {
adminDocumentation = true;
page.find('span.adminDocumentation').html("<a id='adminDocumentation' href='" + app.documentation.admin + "'>" + t('settings', 'Admin Documentation') + "</a>");
page.find('p.documentation').show();
}
|
|
6d9380f96
|
56 57 58 59 |
else {
page.find('span.adminDocumentation').empty();
adminDocumentation = false;
}
|
|
a293d369c
|
60 61 |
if(userDocumentation && adminDocumentation) {
|
|
6d9380f96
|
62 63 64 65 66 |
page.find('span.comma').remove();
page.find('span.userDocumentation').after('<span class="comma">, </span>');
}
else {
page.find('span.comma').remove();
|
|
a293d369c
|
67 68 |
} } |
|
6d9380f96
|
69 70 71 |
else {
page.find('p.documentation').hide();
}
|
|
a293d369c
|
72 73 74 75 76 |
if (typeof(app.website) !== 'undefined') {
page.find('p.website').show();
page.find('a#websitelink').attr('href', app.website);
}
|
|
31b7f2792
|
77 |
if (app.update !== false) {
|
|
03e52840d
|
78 79 80 81 82 83 |
page.find('input.update').show();
page.find('input.update').data('appid', app.id);
page.find('input.update').attr('value',t('settings', 'Update to {appversion}', {appversion:app.update}));
} else {
page.find('input.update').hide();
}
|
|
6d9380f96
|
84 85 86 87 88 89 90 |
if (app.removable !== false && app.active === false) {
page.find('a.uninstall').show();
page.find('a.uninstall').data('appid', app.id);
page.find('a.uninstall').attr('value', t('settings', 'Uninstall App'));
} else {
page.find('a.uninstall').hide();
}
|
|
03e52840d
|
91 92 93 94 |
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);
|
|
31b7f2792
|
95 |
if (app.internal === false) {
|
|
03e52840d
|
96 |
page.find('span.score').show();
|
|
a293d369c
|
97 98 |
page.find('p.appstore').show();
page.find('a#appstorelink').attr('href', 'http://apps.owncloud.com/content/show.php?content=' + app.id);
|
|
03e52840d
|
99 100 101 102 103 |
page.find('small.externalapp').hide();
} else {
page.find('p.appslink').hide();
page.find('span.score').hide();
}
|
|
6d9380f96
|
104 |
if (typeof($('#app-navigation ul li[data-id="'+app.id+'"]').data('errormsg')) !== "undefined") {
|
|
31b7f2792
|
105 |
page.find(".warning").show();
|
|
6d9380f96
|
106 |
page.find(".warning").text($('#app-navigation ul li[data-id="'+app.id+'"]').data('errormsg'));
|
|
31b7f2792
|
107 108 109 |
} else {
page.find(".warning").hide();
}
|
|
6d9380f96
|
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
page.find("div.multiselect").parent().remove();
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')) {
page.find("#groups_enable").hide();
page.find("label[for='groups_enable']").hide();
page.find("#groups_enable").attr('checked', null);
} else {
$('#group_select > option').each(function (i, el) {
if (app.groups.length === 0 || app.groups.indexOf(el.value) >= 0) {
$(el).attr('selected', 'selected');
} else {
$(el).attr('selected', null);
}
});
if (app.active) {
if (app.groups.length) {
$('#group_select').multiSelect();
page.find("#groups_enable").attr('checked','checked');
} else {
page.find("#groups_enable").attr('checked', null);
}
page.find("#groups_enable").show();
page.find("label[for='groups_enable']").show();
} else {
page.find("#groups_enable").hide();
page.find("label[for='groups_enable']").hide();
}
}
|
|
03e52840d
|
139 |
}, |
|
6d9380f96
|
140 141 142 |
enableApp:function(appid, active, element, groups) {
groups = groups || [];
var appitem=$('#app-navigation ul li[data-id="'+appid+'"]');
|
|
03e52840d
|
143 |
element.val(t('settings','Please wait....'));
|
|
6d9380f96
|
144 |
if(active && !groups.length) {
|
|
03e52840d
|
145 |
$.post(OC.filePath('settings','ajax','disableapp.php'),{appid:appid},function(result) {
|
|
31b7f2792
|
146 147 148 149 150 151 152 153 154 155 |
if(!result || result.status !== 'success') {
if (result.data && result.data.message) {
OC.Settings.Apps.showErrorMessage(result.data.message);
appitem.data('errormsg', result.data.message);
} else {
OC.Settings.Apps.showErrorMessage(t('settings', 'Error while disabling app'));
appitem.data('errormsg', t('settings', 'Error while disabling app'));
}
element.val(t('settings','Disable'));
appitem.addClass('appwarning');
|
|
03e52840d
|
156 157 |
}
else {
|
|
31b7f2792
|
158 |
appitem.data('active',false);
|
|
6d9380f96
|
159 |
appitem.data('groups', '');
|
|
03e52840d
|
160 161 |
element.data('active',false);
OC.Settings.Apps.removeNavigation(appid);
|
|
31b7f2792
|
162 |
appitem.removeClass('active');
|
|
03e52840d
|
163 |
element.val(t('settings','Enable'));
|
|
6d9380f96
|
164 165 166 167 |
element.parent().find("#groups_enable").hide();
element.parent().find("label[for='groups_enable']").hide();
var app = OC.get('appData_' + appid);
app.active = false;
|
|
03e52840d
|
168 169 |
} },'json'); |
|
03e52840d
|
170 |
} else {
|
|
6d9380f96
|
171 |
$.post(OC.filePath('settings','ajax','enableapp.php'),{appid: appid, groups: groups},function(result) {
|
|
31b7f2792
|
172 173 174 175 176 177 178 179 180 181 182 |
if(!result || result.status !== 'success') {
if (result.data && result.data.message) {
OC.Settings.Apps.showErrorMessage(result.data.message);
appitem.data('errormsg', result.data.message);
} else {
OC.Settings.Apps.showErrorMessage(t('settings', 'Error while enabling app'));
appitem.data('errormsg', t('settings', 'Error while disabling app'));
}
element.val(t('settings','Enable'));
appitem.addClass('appwarning');
} else {
|
|
03e52840d
|
183 |
OC.Settings.Apps.addNavigation(appid); |
|
31b7f2792
|
184 |
appitem.data('active',true);
|
|
03e52840d
|
185 |
element.data('active',true);
|
|
31b7f2792
|
186 |
appitem.addClass('active');
|
|
03e52840d
|
187 |
element.val(t('settings','Disable'));
|
|
6d9380f96
|
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
var app = OC.get('appData_' + appid);
app.active = true;
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')) {
element.parent().find("#groups_enable").hide();
element.parent().find("label[for='groups_enable']").hide();
} else {
element.parent().find("#groups_enable").show();
element.parent().find("label[for='groups_enable']").show();
if (groups) {
appitem.data('groups', JSON.stringify(groups));
} else {
appitem.data('groups', '');
}
}
|
|
03e52840d
|
203 204 |
} },'json') |
|
a293d369c
|
205 |
.fail(function() {
|
|
31b7f2792
|
206 207 208 209 |
OC.Settings.Apps.showErrorMessage(t('settings', 'Error while enabling app'));
appitem.data('errormsg', t('settings', 'Error while enabling app'));
appitem.data('active',false);
appitem.addClass('appwarning');
|
|
03e52840d
|
210 211 212 |
OC.Settings.Apps.removeNavigation(appid);
element.val(t('settings','Enable'));
});
|
|
03e52840d
|
213 214 215 |
}
},
updateApp:function(appid, element) {
|
|
03e52840d
|
216 217 |
element.val(t('settings','Updating....'));
$.post(OC.filePath('settings','ajax','updateapp.php'),{appid:appid},function(result) {
|
|
31b7f2792
|
218 219 220 |
if(!result || result.status !== 'success') {
OC.Settings.Apps.showErrorMessage(t('settings','Error while updating app'),t('settings','Error'));
element.val(t('settings','Update'));
|
|
03e52840d
|
221 222 223 224 225 226 227 |
}
else {
element.val(t('settings','Updated'));
element.hide();
}
},'json');
},
|
|
6d9380f96
|
228 229 230 231 232 233 234 235 236 237 238 239 |
uninstallApp:function(appid, element) {
element.val(t('settings','Uninstalling ....'));
$.post(OC.filePath('settings','ajax','uninstallapp.php'),{appid:appid},function(result) {
if(!result || result.status !== 'success') {
OC.Settings.Apps.showErrorMessage(t('settings','Error while uninstalling app'),t('settings','Error'));
element.val(t('settings','Uninstall'));
} else {
OC.Settings.Apps.removeNavigation(appid);
appitem.removeClass('active');
}
},'json');
},
|
|
03e52840d
|
240 241 |
insertApp:function(appdata) {
|
|
6d9380f96
|
242 |
var applist = $('#app-navigation ul li');
|
|
03e52840d
|
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
var app =
$('<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;
},
removeNavigation: function(appid){
$.getJSON(OC.filePath('settings', 'ajax', 'navigationdetect.php'), {app: appid}).done(function(response){
if(response.status === 'success'){
var navIds=response.nav_ids;
for(var i=0; i< navIds.length; i++){
|
|
6d9380f96
|
266 |
$('#apps ul').children('li[data-id="'+navIds[i]+'"]').remove();
|
|
03e52840d
|
267 268 269 270 271 272 273 274 275 276 |
}
}
});
},
addNavigation: function(appid){
$.getJSON(OC.filePath('settings', 'ajax', 'navigationdetect.php'), {app: appid}).done(function(response){
if(response.status === 'success'){
var navEntries=response.nav_entries;
for(var i=0; i< navEntries.length; i++){
var entry = navEntries[i];
|
|
6d9380f96
|
277 |
var container = $('#apps ul');
|
|
03e52840d
|
278 279 280 281 |
if(container.children('li[data-id="'+entry.id+'"]').length === 0){
var li=$('<li></li>');
li.attr('data-id', entry.id);
|
|
f7d878ff1
|
282 |
var img= $('<img class="app-icon"/>').attr({ src: entry.icon});
|
|
03e52840d
|
283 284 285 286 287 288 |
var a=$('<a></a>').attr('href', entry.href);
var filename=$('<span></span>');
filename.text(entry.name);
a.prepend(filename);
a.prepend(img);
li.append(a);
|
|
6d9380f96
|
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
// append the new app as last item in the list
// which is the "add apps" entry with the id
// #apps-management
$('#apps-management').before(li);
// 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
$('#header .menutoggle')
.animate({opacity: 0.5})
.animate({opacity: 1})
.animate({opacity: 0.5})
.animate({opacity: 1})
.animate({opacity: 0.75});
|
|
31b7f2792
|
309 |
|
|
03e52840d
|
310 311 312 313 314 315 316 317 |
if (!SVGSupport() && entry.icon.match(/\.svg$/i)) {
$(img).addClass('svg');
replaceSVG();
}
}
}
}
});
|
|
31b7f2792
|
318 319 320 321 |
},
showErrorMessage: function(message) {
$('.appinfo .warning').show();
$('.appinfo .warning').text(message);
|
|
6d9380f96
|
322 323 324 |
},
isType: function(app, type){
return app.types && app.types.indexOf(type) !== -1;
|
|
03e52840d
|
325 326 327 328 |
}
};
$(document).ready(function(){
|
|
6d9380f96
|
329 |
$('#app-navigation ul li').each(function(index,li){
|
|
03e52840d
|
330 |
var app = OC.get('appData_'+$(li).data('id'));
|
|
6d9380f96
|
331 332 333 |
if (app) {
app.groups= $(li).data('groups') || [];
}
|
|
03e52840d
|
334 335 336 |
$(li).data('app',app);
$(this).find('span.hidden').remove();
});
|
|
6d9380f96
|
337 |
$('#app-navigation ul li').keydown(function(event) {
|
|
31b7f2792
|
338 |
if (event.which === 13 || event.which === 32) {
|
|
03e52840d
|
339 340 341 342 |
$(event.target).click(); } return false; }); |
|
6d9380f96
|
343 |
$(document).on('click', '#app-navigation', function(event){
|
|
03e52840d
|
344 345 346 347 348 |
var tgt = $(event.target);
if (tgt.is('li') || tgt.is('a')) {
var item = tgt.is('li') ? $(tgt) : $(tgt).parent();
var app = item.data('app');
OC.Settings.Apps.loadApp(app);
|
|
6d9380f96
|
349 350 |
$('#app-navigation .selected').removeClass('selected');
item.addClass('selected');
|
|
03e52840d
|
351 352 353 |
} return false; }); |
|
6d9380f96
|
354 |
$('#app-content input.enable').click(function(){
|
|
03e52840d
|
355 356 357 358 359 360 361 |
var element = $(this);
var appid=$(this).data('appid');
var active=$(this).data('active');
if(appid) {
OC.Settings.Apps.enableApp(appid, active, element);
}
});
|
|
6d9380f96
|
362 |
$('#app-content input.update').click(function(){
|
|
03e52840d
|
363 364 365 366 367 368 |
var element = $(this);
var appid=$(this).data('appid');
if(appid) {
OC.Settings.Apps.updateApp(appid, element);
}
});
|
|
6d9380f96
|
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
$('#app-content a.uninstall').click(function(){
var element = $(this);
var appid=$(this).data('appid');
if(appid) {
OC.Settings.Apps.uninstallApp(appid, element);
}
});
$('#group_select').change(function() {
var element = $('#app-content input.enable');
var groups = $(this).val();
var appid = element.data('appid');
if (appid) {
OC.Settings.Apps.enableApp(appid, false, element, groups);
var li = $('[data-id="'+appid+'"]');
var app = OC.get('appData_' + $(li).data('id'));
app.groups = groups;
li.data('groups', groups);
li.attr('data-groups', JSON.stringify(groups));
}
});
|
|
03e52840d
|
390 391 |
if(appid) {
|
|
6d9380f96
|
392 |
var item = $('#app-navigation ul li[data-id="'+appid+'"]');
|
|
03e52840d
|
393 394 395 |
if(item) {
item.trigger('click');
item.addClass('active');
|
|
6d9380f96
|
396 |
$('#app-navigation').animate({scrollTop: item.offset().top-70}, 'slow','swing');
|
|
03e52840d
|
397 398 |
} } |
|
6d9380f96
|
399 400 401 402 403 404 405 406 407 408 409 410 |
$("#groups_enable").change(function() {
if (this.checked) {
$("div.multiselect").parent().remove();
$('#group_select').multiSelect();
} else {
$('#group_select').hide().val(null);
$("div.multiselect").parent().remove();
}
$('#group_select').change();
});
|
|
03e52840d
|
411 |
}); |