summaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
Diffstat (limited to 'core/js')
-rw-r--r--core/js/js.js179
-rw-r--r--core/js/share.js40
2 files changed, 163 insertions, 56 deletions
diff --git a/core/js/js.js b/core/js/js.js
index cf4e72324dc..c2b81ae3272 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -1,6 +1,6 @@
/**
* Disable console output unless DEBUG mode is enabled.
- * Add
+ * Add
* define('DEBUG', true);
* To the end of config/config.php to enable debug mode.
* The undefined checks fix the broken ie8 console
@@ -24,60 +24,121 @@ if (oc_debug !== true || typeof console === "undefined" || typeof console.log ==
}
}
-/**
- * translate a string
- * @param app the id of the app for which to translate the string
- * @param text the string to translate
- * @return string
- */
-function t(app,text, vars){
- if( !( t.cache[app] )){
- $.ajax(OC.filePath('core','ajax','translations.php'),{
- async:false,//todo a proper sollution for this without sync ajax calls
- data:{'app': app},
- type:'POST',
- success:function(jsondata){
+function initL10N(app) {
+ if (!( t.cache[app] )) {
+ $.ajax(OC.filePath('core', 'ajax', 'translations.php'), {
+ async: false,//todo a proper solution for this without sync ajax calls
+ data: {'app': app},
+ type: 'POST',
+ success: function (jsondata) {
t.cache[app] = jsondata.data;
+ t.plural_form = jsondata.plural_form;
}
});
// Bad answer ...
- if( !( t.cache[app] )){
+ if (!( t.cache[app] )) {
t.cache[app] = [];
}
}
- var _build = function (text, vars) {
- return text.replace(/{([^{}]*)}/g,
+ if (typeof t.plural_function == 'undefined') {
+ t.plural_function = function (n) {
+ var p = (n != 1) ? 1 : 0;
+ return { 'nplural' : 2, 'plural' : p };
+ };
+
+ /**
+ * code below has been taken from jsgettext - which is LGPL licensed
+ * https://developer.berlios.de/projects/jsgettext/
+ * http://cvs.berlios.de/cgi-bin/viewcvs.cgi/jsgettext/jsgettext/lib/Gettext.js
+ */
+ var pf_re = new RegExp('^(\\s*nplurals\\s*=\\s*[0-9]+\\s*;\\s*plural\\s*=\\s*(?:\\s|[-\\?\\|&=!<>+*/%:;a-zA-Z0-9_\(\)])+)', 'm');
+ if (pf_re.test(t.plural_form)) {
+ //ex english: "Plural-Forms: nplurals=2; plural=(n != 1);\n"
+ //pf = "nplurals=2; plural=(n != 1);";
+ //ex russian: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10< =4 && (n%100<10 or n%100>=20) ? 1 : 2)
+ //pf = "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)";
+ var pf = t.plural_form;
+ if (! /;\s*$/.test(pf)) pf = pf.concat(';');
+ /* We used to use eval, but it seems IE has issues with it.
+ * We now use "new Function", though it carries a slightly
+ * bigger performance hit.
+ var code = 'function (n) { var plural; var nplurals; '+pf+' return { "nplural" : nplurals, "plural" : (plural === true ? 1 : plural ? plural : 0) }; };';
+ Gettext._locale_data[domain].head.plural_func = eval("("+code+")");
+ */
+ var code = 'var plural; var nplurals; '+pf+' return { "nplural" : nplurals, "plural" : (plural === true ? 1 : plural ? plural : 0) };';
+ t.plural_function = new Function("n", code);
+ } else {
+ console.log("Syntax error in language file. Plural-Forms header is invalid ["+plural_forms+"]");
+ }
+ }
+}
+/**
+ * translate a string
+ * @param app the id of the app for which to translate the string
+ * @param text the string to translate
+ * @param vars (optional) FIXME
+ * @param count (optional) number to replace %n with
+ * @return string
+ */
+function t(app, text, vars, count){
+ initL10N(app);
+ var _build = function (text, vars, count) {
+ return text.replace(/%n/g, count).replace(/{([^{}]*)}/g,
function (a, b) {
var r = vars[b];
return typeof r === 'string' || typeof r === 'number' ? r : a;
}
);
};
+ var translation = text;
if( typeof( t.cache[app][text] ) !== 'undefined' ){
- if(typeof vars === 'object') {
- return _build(t.cache[app][text], vars);
- } else {
- return t.cache[app][text];
+ translation = t.cache[app][text];
+ }
+
+ if(typeof vars === 'object' || count !== undefined ) {
+ return _build(translation, vars, count);
+ } else {
+ return translation;
+ }
+}
+t.cache = {};
+
+/**
+ * translate a string
+ * @param app the id of the app for which to translate the string
+ * @param text_singular the string to translate for exactly one object
+ * @param text_plural the string to translate for n objects
+ * @param count number to determine whether to use singular or plural
+ * @param vars (optional) FIXME
+ * @return string
+ */
+function n(app, text_singular, text_plural, count, vars) {
+ initL10N(app);
+ var identifier = '_' + text_singular + '__' + text_plural + '_';
+ if( typeof( t.cache[app][identifier] ) !== 'undefined' ){
+ var translation = t.cache[app][identifier];
+ if ($.isArray(translation)) {
+ var plural = t.plural_function(count);
+ return t(app, translation[plural.plural], vars, count);
}
}
+
+ if(count === 1) {
+ return t(app, text_singular, vars, count);
+ }
else{
- if(typeof vars === 'object') {
- return _build(text, vars);
- } else {
- return text;
- }
+ return t(app, text_plural, vars, count);
}
}
-t.cache={};
-/*
+/**
* Sanitizes a HTML string
-* @param string
+* @param s string
* @return Sanitized string
*/
function escapeHTML(s) {
- return s.toString().split('&').join('&amp;').split('<').join('&lt;').split('"').join('&quot;');
+ return s.toString().split('&').join('&amp;').split('<').join('&lt;').split('"').join('&quot;');
}
/**
@@ -96,6 +157,7 @@ var OC={
PERMISSION_UPDATE:2,
PERMISSION_DELETE:8,
PERMISSION_SHARE:16,
+ PERMISSION_ALL:31,
webroot:oc_webroot,
appswebroots:(typeof oc_appswebroots !== 'undefined') ? oc_appswebroots:false,
currentUser:(typeof oc_current_user!=='undefined')?oc_current_user:false,
@@ -370,6 +432,44 @@ OC.Notification={
OC.Breadcrumb={
container:null,
crumbs:[],
+ show:function(dir, leafname, leaflink){
+ OC.Breadcrumb.clear();
+
+ // show home + path in subdirectories
+ if (dir && dir !== '/') {
+ //add home
+ var link = OC.linkTo('files','index.php');
+
+ var crumb=$('<div/>');
+ crumb.addClass('crumb');
+
+ var crumbLink=$('<a/>');
+ crumbLink.attr('href',link);
+
+ var crumbImg=$('<img/>');
+ crumbImg.attr('src',OC.imagePath('core','places/home'));
+ crumbLink.append(crumbImg);
+ crumb.append(crumbLink);
+ OC.Breadcrumb.container.prepend(crumb);
+ OC.Breadcrumb.crumbs.push(crumb);
+
+ //add path parts
+ var segments = dir.split('/');
+ var pathurl = '';
+ jQuery.each(segments, function(i,name) {
+ if (name !== '') {
+ pathurl = pathurl+'/'+name;
+ var link = OC.linkTo('files','index.php')+'?dir='+encodeURIComponent(pathurl);
+ OC.Breadcrumb.push(name, link);
+ }
+ });
+ }
+
+ //add leafname
+ if (leafname && leaflink) {
+ OC.Breadcrumb.push(leafname, leaflink);
+ }
+ },
push:function(name, link){
if(!OC.Breadcrumb.container){//default
OC.Breadcrumb.container=$('#controls');
@@ -387,7 +487,7 @@ OC.Breadcrumb={
existing.removeClass('last');
existing.last().after(crumb);
}else{
- OC.Breadcrumb.container.append(crumb);
+ OC.Breadcrumb.container.prepend(crumb);
}
OC.Breadcrumb.crumbs.push(crumb);
return crumb;
@@ -658,13 +758,10 @@ $(document).ready(function(){
});
// all the tipsy stuff needs to be here (in reverse order) to work
- $('.jp-controls .jp-previous').tipsy({gravity:'nw', fade:true, live:true});
- $('.jp-controls .jp-next').tipsy({gravity:'n', fade:true, live:true});
$('.displayName .action').tipsy({gravity:'se', fade:true, live:true});
$('.password .action').tipsy({gravity:'se', fade:true, live:true});
$('#upload').tipsy({gravity:'w', fade:true});
$('.selectedActions a').tipsy({gravity:'s', fade:true, live:true});
- $('a.delete').tipsy({gravity: 'e', fade:true, live:true});
$('a.action').tipsy({gravity:'s', fade:true, live:true});
$('td .modified').tipsy({gravity:'s', fade:true, live:true});
@@ -713,15 +810,13 @@ function relative_modified_date(timestamp) {
var diffdays = Math.round(diffhours/24);
var diffmonths = Math.round(diffdays/31);
if(timediff < 60) { return t('core','seconds ago'); }
- else if(timediff < 120) { return t('core','1 minute ago'); }
- else if(timediff < 3600) { return t('core','{minutes} minutes ago',{minutes: diffminutes}); }
- else if(timediff < 7200) { return t('core','1 hour ago'); }
- else if(timediff < 86400) { return t('core','{hours} hours ago',{hours: diffhours}); }
+ else if(timediff < 3600) { return n('core','%n minute ago', '%n minutes ago', diffminutes); }
+ else if(timediff < 86400) { return n('core', '%n hour ago', '%n hours ago', diffhours); }
else if(timediff < 86400) { return t('core','today'); }
else if(timediff < 172800) { return t('core','yesterday'); }
- else if(timediff < 2678400) { return t('core','{days} days ago',{days: diffdays}); }
+ else if(timediff < 2678400) { return n('core', '%n day ago', '%n days ago', diffdays); }
else if(timediff < 5184000) { return t('core','last month'); }
- else if(timediff < 31556926) { return t('core','{months} months ago',{months: diffmonths}); }
+ else if(timediff < 31556926) { return n('core', '%n month ago', '%n months ago', diffmonths); }
//else if(timediff < 31556926) { return t('core','months ago'); }
else if(timediff < 63113852) { return t('core','last year'); }
else { return t('core','years ago'); }
@@ -735,7 +830,7 @@ OC.get=function(name) {
var namespaces = name.split(".");
var tail = namespaces.pop();
var context=window;
-
+
for(var i = 0; i < namespaces.length; i++) {
context = context[namespaces[i]];
if(!context){
@@ -754,7 +849,7 @@ OC.set=function(name, value) {
var namespaces = name.split(".");
var tail = namespaces.pop();
var context=window;
-
+
for(var i = 0; i < namespaces.length; i++) {
if(!context[namespaces[i]]){
context[namespaces[i]]={};
diff --git a/core/js/share.js b/core/js/share.js
index e59669cbc2b..e7fb26d0ed8 100644
--- a/core/js/share.js
+++ b/core/js/share.js
@@ -22,9 +22,9 @@ OC.Share={
if (itemType != 'file' && itemType != 'folder') {
$('a.share[data-item="'+item+'"]').css('background', 'url('+image+') no-repeat center');
} else {
- var file = $('tr').filterAttr('data-id', item);
+ var file = $('tr[data-id="'+item+'"]');
if (file.length > 0) {
- var action = $(file).find('.fileactions .action').filterAttr('data-action', 'Share');
+ var action = $(file).find('.fileactions .action[data-action="Share"]');
var img = action.find('img').attr('src', image);
action.addClass('permanent');
action.html(' '+t('core', 'Shared')).prepend(img);
@@ -36,7 +36,7 @@ OC.Share={
// Search for possible parent folders that are shared
while (path != last) {
if (path == data['path']) {
- var actions = $('.fileactions .action').filterAttr('data-action', 'Share');
+ var actions = $('.fileactions .action[data-action="Share"]');
$.each(actions, function(index, action) {
var img = $(action).find('img');
if (img.attr('src') != OC.imagePath('core', 'actions/public')) {
@@ -256,8 +256,8 @@ OC.Share={
var shareType = selected.item.value.shareType;
var shareWith = selected.item.value.shareWith;
$(this).val(shareWith);
- // Default permissions are Read and Share
- var permissions = OC.PERMISSION_READ | OC.PERMISSION_SHARE;
+ // Default permissions are Edit (CRUD) and Share
+ var permissions = OC.PERMISSION_ALL;
OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, function() {
OC.Share.addShareWith(shareType, shareWith, selected.item.label, permissions, possiblePermissions);
$('#shareWith').val('');
@@ -592,8 +592,7 @@ $(document).ready(function() {
}
// Update the share information
- OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', permissions, function(data) {
- return;
+ OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', permissions, function(data) {
});
});
@@ -609,13 +608,26 @@ $(document).ready(function() {
});
$(document).on('focusout keyup', '#dropdown #linkPassText', function(event) {
- if ( $('#linkPassText').val() != '' && (event.type == 'focusout' || event.keyCode == 13) ) {
- var itemType = $('#dropdown').data('item-type');
- var itemSource = $('#dropdown').data('item-source');
- OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $('#linkPassText').val(), OC.PERMISSION_READ, function() {
- console.log("password set to: '" + $('#linkPassText').val() +"' by event: " + event.type);
- $('#linkPassText').val('');
- $('#linkPassText').attr('placeholder', t('core', 'Password protected'));
+ var linkPassText = $('#linkPassText');
+ if ( linkPassText.val() != '' && (event.type == 'focusout' || event.keyCode == 13) ) {
+
+ var allowPublicUpload = $('#sharingDialogAllowPublicUpload').is(':checked');
+ var dropDown = $('#dropdown');
+ var itemType = dropDown.data('item-type');
+ var itemSource = dropDown.data('item-source');
+ var permissions = 0;
+
+ // Calculate permissions
+ if (allowPublicUpload) {
+ permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ;
+ } else {
+ permissions = OC.PERMISSION_READ;
+ }
+
+ OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $('#linkPassText').val(), permissions, function() {
+ console.log("password set to: '" + linkPassText.val() +"' by event: " + event.type);
+ linkPassText.val('');
+ linkPassText.attr('placeholder', t('core', 'Password protected'));
});
}
});