summaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-09-28 15:38:49 +0200
committerBart Visscher <bartv@thisnet.nl>2012-09-28 15:38:49 +0200
commitbf1057143cdff8ec289d9d766ab100d64d7ea45d (patch)
tree6c35d0d99a72f27a981a07c93f0ecbf600764cd4 /core/js
parent3efe1d3b24e65ed76d521c24b0cfe4e0ff2e7af5 (diff)
parent5144d26088b98685a37c73c776a9a47203efa68a (diff)
downloadnextcloud-server-bf1057143cdff8ec289d9d766ab100d64d7ea45d.tar.gz
nextcloud-server-bf1057143cdff8ec289d9d766ab100d64d7ea45d.zip
Merge branch 'master' into routing
Conflicts: apps/files/js/filelist.js core/js/js.js lib/ocs.php
Diffstat (limited to 'core/js')
-rw-r--r--core/js/js.js172
-rw-r--r--core/js/oc-dialogs.js14
-rw-r--r--core/js/share.js223
3 files changed, 270 insertions, 139 deletions
diff --git a/core/js/js.js b/core/js/js.js
index c392991d456..39a58a24599 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -4,21 +4,20 @@
* @param text the string to translate
* @return string
*/
-var OC;
function t(app,text){
- if( !( app in t.cache )){
+ 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){
t.cache[app] = jsondata.data;
- },
+ }
});
// Bad answer ...
- if( !( app in t.cache )){
+ if( !( t.cache[app] )){
t.cache[app] = [];
}
}
@@ -41,7 +40,7 @@ function fileDownloadPath(dir, file) {
return OC.filePath('files', 'ajax', 'download.php')+encodeURIComponent('?files='+encodeURIComponent(file)+'&dir='+encodeURIComponent(dir));
}
-OC={
+var OC={
PERMISSION_CREATE:4,
PERMISSION_READ:1,
PERMISSION_UPDATE:2,
@@ -68,9 +67,9 @@ OC={
* @return string
*/
filePath:function(app,type,file){
- var isCore=OC.coreApps.indexOf(app)!=-1;
- var link=OC.webroot;
- if((file.substring(file.length-3) == 'php' || file.substring(file.length-3) == 'css') && !isCore){
+ var isCore=OC.coreApps.indexOf(app)!==-1,
+ link=OC.webroot;
+ if((file.substring(file.length-3) === 'php' || file.substring(file.length-3) === 'css') && !isCore){
link+='/index.php/apps/' + app;
if (file != 'index.php') {
link+='/';
@@ -79,20 +78,21 @@ OC={
}
link+= file;
}
- }else if(file.substring(file.length-3) != 'php' && !isCore){
+ }else if(file.substring(file.length-3) !== 'php' && !isCore){
link=OC.appswebroots[app];
if(type){
link+= '/'+type+'/';
}
- if(link.substring(link.length-1) != '/')
+ if(link.substring(link.length-1) !== '/'){
link+='/';
+ }
link+=file;
}else{
link+='/';
if(!isCore){
link+='apps/';
}
- if (app != '') {
+ if (app !== '') {
app+='/';
link+=app;
}
@@ -126,12 +126,12 @@ OC={
* if the script is already loaded, the event handeler will be called directly
*/
addScript:function(app,script,ready){
- var path=OC.filePath(app,'js',script+'.js');
+ var deferred, path=OC.filePath(app,'js',script+'.js');
if(!OC.addScript.loaded[path]){
if(ready){
- var deferred=$.getScript(path,ready);
+ deferred=$.getScript(path,ready);
}else{
- var deferred=$.getScript(path);
+ deferred=$.getScript(path);
}
OC.addScript.loaded[path]=deferred;
}else{
@@ -148,12 +148,18 @@ OC={
*/
addStyle:function(app,style){
var path=OC.filePath(app,'css',style+'.css');
- if(OC.addStyle.loaded.indexOf(path)==-1){
+ if(OC.addStyle.loaded.indexOf(path)===-1){
OC.addStyle.loaded.push(path);
- var style=$('<link rel="stylesheet" type="text/css" href="'+path+'"/>');
+ style=$('<link rel="stylesheet" type="text/css" href="'+path+'"/>');
$('head').append(style);
}
},
+ basename: function(path) {
+ return path.replace(/\\/g,'/').replace( /.*\//, '' );
+ },
+ dirname: function(path) {
+ return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
+ },
/**
* do a search query and display the results
* @param query the search query
@@ -169,10 +175,9 @@ OC={
},
dialogs:OCdialogs,
mtime2date:function(mtime) {
- mtime = parseInt(mtime);
+ mtime = parseInt(mtime,10);
var date = new Date(1000*mtime);
- var ret = date.getDate()+'.'+(date.getMonth()+1)+'.'+date.getFullYear()+', '+date.getHours()+':'+date.getMinutes();
- return ret;
+ return date.getDate()+'.'+(date.getMonth()+1)+'.'+date.getFullYear()+', '+date.getHours()+':'+date.getMinutes();
},
/**
* Opens a popup with the setting for an app.
@@ -238,31 +243,74 @@ OC.search.lastResults={};
OC.addStyle.loaded=[];
OC.addScript.loaded=[];
-if(typeof localStorage !='undefined' && localStorage != null){
- //user and instance awere localstorage
+OC.Breadcrumb={
+ container:null,
+ crumbs:[],
+ push:function(name, link){
+ if(!OC.Breadcrumb.container){//default
+ OC.Breadcrumb.container=$('#controls');
+ }
+ var crumb=$('<div/>');
+ crumb.addClass('crumb').addClass('last');
+ crumb.attr('style','background-image:url("'+OC.imagePath('core','breadcrumb')+'")');
+
+ var crumbLink=$('<a/>');
+ crumbLink.attr('href',link);
+ crumbLink.text(name);
+ crumb.append(crumbLink);
+
+ var existing=OC.Breadcrumb.container.find('div.crumb');
+ if(existing.length){
+ existing.removeClass('last');
+ existing.last().after(crumb);
+ }else{
+ OC.Breadcrumb.container.append(crumb);
+ }
+ OC.Breadcrumb.crumbs.push(crumb);
+ return crumb;
+ },
+ pop:function(){
+ if(!OC.Breadcrumb.container){//default
+ OC.Breadcrumb.container=$('#controls');
+ }
+ OC.Breadcrumb.container.find('div.crumb').last().remove();
+ OC.Breadcrumb.container.find('div.crumb').last().addClass('last');
+ OC.Breadcrumb.crumbs.pop();
+ },
+ clear:function(){
+ if(!OC.Breadcrumb.container){//default
+ OC.Breadcrumb.container=$('#controls');
+ }
+ OC.Breadcrumb.container.find('div.crumb').remove();
+ OC.Breadcrumb.crumbs=[];
+ }
+};
+
+if(typeof localStorage !=='undefined' && localStorage !== null){
+ //user and instance aware localstorage
OC.localStorage={
namespace:'oc_'+OC.currentUser+'_'+OC.webroot+'_',
hasItem:function(name){
- return OC.localStorage.getItem(name)!=null;
+ return OC.localStorage.getItem(name)!==null;
},
setItem:function(name,item){
return localStorage.setItem(OC.localStorage.namespace+name,JSON.stringify(item));
},
getItem:function(name){
- if(localStorage.getItem(OC.localStorage.namespace+name)==null){return null;}
+ if(localStorage.getItem(OC.localStorage.namespace+name)===null){return null;}
return JSON.parse(localStorage.getItem(OC.localStorage.namespace+name));
}
};
}else{
//dummy localstorage
OC.localStorage={
- hasItem:function(name){
+ hasItem:function(){
return false;
},
- setItem:function(name,item){
+ setItem:function(){
return false;
},
- getItem:function(name){
+ getItem:function(){
return null;
}
};
@@ -274,8 +322,9 @@ if(typeof localStorage !='undefined' && localStorage != null){
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun /*, thisp*/) {
var len = this.length >>> 0;
- if (typeof fun != "function")
+ if (typeof fun !== "function"){
throw new TypeError();
+ }
var res = [];
var thisp = arguments[1];
@@ -298,17 +347,16 @@ if (!Array.prototype.indexOf){
var len = this.length;
var from = Number(arguments[1]) || 0;
- from = (from < 0)
- ? Math.ceil(from)
- : Math.floor(from);
- if (from < 0)
+ from = (from < 0) ? Math.ceil(from) : Math.floor(from);
+ if (from < 0){
from += len;
+ }
for (; from < len; from++)
{
- if (from in this &&
- this[from] === elt)
+ if (from in this && this[from] === elt){
return from;
+ }
}
return -1;
};
@@ -329,16 +377,16 @@ SVGSupport.checkMimeType=function(){
$.each(headerParts,function(i,text){
if(text){
var parts=text.split(':',2);
- if(parts.length==2){
+ if(parts.length===2){
var value=parts[1].trim();
- if(value[0]=='"'){
+ if(value[0]==='"'){
value=value.substr(1,value.length-2);
}
headers[parts[0]]=value;
}
}
});
- if(headers["Content-Type"]!='image/svg+xml'){
+ if(headers["Content-Type"]!=='image/svg+xml'){
replaceSVG();
SVGSupport.checkMimeType.correct=false;
}
@@ -395,27 +443,29 @@ function object(o) {
* Fills height of window. (more precise than height: 100%;)
*/
function fillHeight(selector) {
- if (selector.length == 0) {
+ if (selector.length === 0) {
return;
}
var height = parseFloat($(window).height())-selector.offset().top;
selector.css('height', height + 'px');
- if(selector.outerHeight() > selector.height())
+ if(selector.outerHeight() > selector.height()){
selector.css('height', height-(selector.outerHeight()-selector.height()) + 'px');
+ }
}
/**
* Fills height and width of window. (more precise than height: 100%; or width: 100%;)
*/
function fillWindow(selector) {
- if (selector.length == 0) {
+ if (selector.length === 0) {
return;
}
fillHeight(selector);
var width = parseFloat($(window).width())-selector.offset().left;
selector.css('width', width + 'px');
- if(selector.outerWidth() > selector.width())
+ if(selector.outerWidth() > selector.width()){
selector.css('width', width-(selector.outerWidth()-selector.width()) + 'px');
+ }
}
$(document).ready(function(){
@@ -436,26 +486,26 @@ $(document).ready(function(){
event.preventDefault();
});
$('#searchbox').keyup(function(event){
- if(event.keyCode==13){//enter
+ if(event.keyCode===13){//enter
if(OC.search.currentResult>-1){
var result=$('#searchresults tr.result a')[OC.search.currentResult];
window.location = $(result).attr('href');
}
- }else if(event.keyCode==38){//up
+ }else if(event.keyCode===38){//up
if(OC.search.currentResult>0){
OC.search.currentResult--;
OC.search.renderCurrent();
}
- }else if(event.keyCode==40){//down
+ }else if(event.keyCode===40){//down
if(OC.search.lastResults.length>OC.search.currentResult+1){
OC.search.currentResult++;
OC.search.renderCurrent();
}
- }else if(event.keyCode==27){//esc
+ }else if(event.keyCode===27){//esc
OC.search.hide();
}else{
var query=$('#searchbox').val();
- if(OC.search.lastQuery!=query){
+ if(OC.search.lastQuery!==query){
OC.search.lastQuery=query;
OC.search.currentResult=-1;
if(query.length>2){
@@ -475,10 +525,10 @@ $(document).ready(function(){
//use infield labels
$("label.infield").inFieldLabels();
- checkShowCredentials = function() {
+ var checkShowCredentials = function() {
var empty = false;
$('input#user, input#password').each(function() {
- if ($(this).val() == '') {
+ if ($(this).val() === '') {
empty = true;
}
});
@@ -491,14 +541,14 @@ $(document).ready(function(){
$('#remember_login').show();
$('#remember_login+label').fadeIn();
}
- }
+ };
// hide log in button etc. when form fields not filled
// commented out due to some browsers having issues with it
// checkShowCredentials();
// $('input#user, input#password').keyup(checkShowCredentials);
$('#settings #expand').keydown(function(event) {
- if (event.which == 13 || event.which == 32) {
+ if (event.which === 13 || event.which === 32) {
$('#expand').click()
}
});
@@ -509,8 +559,8 @@ $(document).ready(function(){
$('#settings #expanddiv').click(function(event){
event.stopPropagation();
});
- $(window).click(function(){//hide the settings menu when clicking oustide it
- if($('body').attr("id")=="body-user"){
+ $(window).click(function(){//hide the settings menu when clicking outside it
+ if($('body').attr("id")==="body-user"){
$('#settings #expanddiv').slideUp();
}
});
@@ -537,13 +587,15 @@ if (!Array.prototype.map){
Array.prototype.map = function(fun /*, thisp */){
"use strict";
- if (this === void 0 || this === null)
+ if (this === void 0 || this === null){
throw new TypeError();
+ }
var t = Object(this);
var len = t.length >>> 0;
- if (typeof fun !== "function")
+ if (typeof fun !== "function"){
throw new TypeError();
+ }
var res = new Array(len);
var thisp = arguments[1];
@@ -565,13 +617,13 @@ $.fn.filterAttr = function(attr_name, attr_value) {
};
function humanFileSize(size) {
- humanList = ['B', 'kB', 'MB', 'GB', 'TB'];
+ var humanList = ['B', 'kB', 'MB', 'GB', 'TB'];
// Calculate Log with base 1024: size = 1024 ** order
- order = Math.floor(Math.log(size) / Math.log(1024));
+ var order = Math.floor(Math.log(size) / Math.log(1024));
// Stay in range of the byte sizes that are defined
order = Math.min(humanList.length - 1, order);
- readableFormat = humanList[order];
- relativeSize = (size / Math.pow(1024, order)).toFixed(1);
+ var readableFormat = humanList[order];
+ var relativeSize = (size / Math.pow(1024, order)).toFixed(1);
if(relativeSize.substr(relativeSize.length-2,2)=='.0'){
relativeSize=relativeSize.substr(0,relativeSize.length-2);
}
@@ -579,7 +631,7 @@ function humanFileSize(size) {
}
function simpleFileSize(bytes) {
- mbytes = Math.round(bytes/(1024*1024/10))/10;
+ var mbytes = Math.round(bytes/(1024*1024/10))/10;
if(bytes == 0) { return '0'; }
else if(mbytes < 0.1) { return '< 0.1'; }
else if(mbytes > 1000) { return '> 1000'; }
@@ -611,7 +663,7 @@ OC.get=function(name) {
}
}
return context[tail];
-}
+};
/**
* set a variable by name
@@ -630,4 +682,4 @@ OC.set=function(name, value) {
context = context[namespaces[i]];
}
context[tail]=value;
-}
+};
diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js
index 4dd3c89c14d..2467af61121 100644
--- a/core/js/oc-dialogs.js
+++ b/core/js/oc-dialogs.js
@@ -106,7 +106,7 @@ var OCdialogs = {
var c_name = 'oc-dialog-'+OCdialogs.dialogs_counter+'-content';
var c_id = '#'+c_name;
var d = '<div id="'+c_name+'" title="'+title+'"><select id="dirtree"><option value="0">'+OC.currentUser+'</option></select><div id="filelist"></div><div class="filepicker_loader"><img src="'+OC.filePath('gallery','img','loading.gif')+'"></div></div>';
- if (!modal) modal = false; // Huh..?
+ if (!modal) modal = false; // Huh..
if (!multiselect) multiselect = false;
$('body').append(d);
$(c_id + ' #dirtree').focus(function() {
@@ -120,7 +120,7 @@ var OCdialogs = {
}).data('multiselect', multiselect).data('mimetype',mimetype_filter);
// build buttons
var b = [{
- text: t('dialogs', 'Choose'),
+ text: t('core', 'Choose'),
click: function(){
if (callback != undefined) {
var p;
@@ -140,7 +140,7 @@ var OCdialogs = {
}
},
{
- text: t('dialogs', 'Cancel'),
+ text: t('core', 'Cancel'),
click: function(){$(c_id).dialog('close'); }}
];
$(c_id).dialog({width: ((4*$('body').width())/9), height: 400, modal: modal, buttons: b});
@@ -156,11 +156,11 @@ var OCdialogs = {
var b = [];
switch (buttons) {
case OCdialogs.YES_NO_BUTTONS:
- b[1] = {text: t('dialogs', 'No'), click: function(){ if (callback != undefined) callback(false); $(c_id).dialog('close'); }};
- b[0] = {text: t('dialogs', 'Yes'), click: function(){ if (callback != undefined) callback(true); $(c_id).dialog('close');}};
+ b[1] = {text: t('core', 'No'), click: function(){ if (callback != undefined) callback(false); $(c_id).dialog('close'); }};
+ b[0] = {text: t('core', 'Yes'), click: function(){ if (callback != undefined) callback(true); $(c_id).dialog('close');}};
break;
case OCdialogs.OK_CANCEL_BUTTONS:
- b[1] = {text: t('dialogs', 'Cancel'), click: function(){$(c_id).dialog('close'); }};
+ b[1] = {text: t('core', 'Cancel'), click: function(){$(c_id).dialog('close'); }};
case OCdialogs.OK_BUTTON: // fallthrough
var f;
switch(dialog_type) {
@@ -174,7 +174,7 @@ var OCdialogs = {
f = function(){OCdialogs.form_ok_handler(callback, c_id)};
break;
}
- b[0] = {text: t('dialogs', 'Ok'), click: f};
+ b[0] = {text: t('core', 'Ok'), click: f};
break;
}
var possible_height = ($('tr', d).size()+1)*30;
diff --git a/core/js/share.js b/core/js/share.js
index b5e8b0e6613..36ee39d8eab 100644
--- a/core/js/share.js
+++ b/core/js/share.js
@@ -35,21 +35,29 @@ OC.Share={
}
}
var shares = false;
+ var link = false;
+ var image = OC.imagePath('core', 'actions/share');
$.each(OC.Share.itemShares, function(index) {
- if (OC.Share.itemShares[index].length > 0) {
- shares = true;
- return;
+ if (OC.Share.itemShares[index]) {
+ if (index == OC.Share.SHARE_TYPE_LINK) {
+ if (OC.Share.itemShares[index] == true) {
+ shares = true;
+ image = OC.imagePath('core', 'actions/public');
+ link = true;
+ return;
+ }
+ } else if (OC.Share.itemShares[index].length > 0) {
+ shares = true;
+ image = OC.imagePath('core', 'actions/shared');
+ }
}
});
+ if (itemType != 'file' && itemType != 'folder') {
+ $('a.share[data-item="'+itemSource+'"]').css('background', 'url('+image+') no-repeat center');
+ }
if (shares) {
- $('a.share[data-item="'+itemSource+'"]').css('background', 'url('+OC.imagePath('core', 'actions/shared')+') no-repeat center');
- if (typeof OC.Share.statuses[itemSource] === 'undefined') {
- OC.Share.statuses[itemSource] = false;
- }
+ OC.Share.statuses[itemSource] = link;
} else {
- if (itemType != 'file' && itemType != 'folder') {
- $('a.share[data-item="'+itemSource+'"]').css('background', 'url('+OC.imagePath('core', 'actions/share')+') no-repeat center');
- }
delete OC.Share.statuses[itemSource];
}
},
@@ -71,7 +79,8 @@ OC.Share={
var item = itemSource;
}
if (typeof OC.Share.statuses[item] === 'undefined') {
- checkShares = false;
+ // NOTE: Check does not always work and misses some shares, fix later
+ checkShares = true;
} else {
checkShares = true;
}
@@ -91,7 +100,7 @@ OC.Share={
callback(result.data);
}
} else {
- OC.dialogs.alert(result.data.message, 'Error while sharing');
+ OC.dialogs.alert(result.data.message, t('core', 'Error while sharing'));
}
});
},
@@ -102,14 +111,14 @@ OC.Share={
callback();
}
} else {
- OC.dialogs.alert('Error', 'Error while unsharing');
+ OC.dialogs.alert(t('core', 'Error'), t('core', 'Error while unsharing'));
}
});
},
setPermissions:function(itemType, itemSource, shareType, shareWith, permissions) {
$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setPermissions', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) {
if (!result || result.status !== 'success') {
- OC.dialogs.alert('Error', 'Error while changing permissions');
+ OC.dialogs.alert(t('core', 'Error'), t('core', 'Error while changing permissions'));
}
});
},
@@ -118,28 +127,30 @@ OC.Share={
var html = '<div id="dropdown" class="drop" data-item-type="'+itemType+'" data-item-source="'+itemSource+'">';
if (data.reshare) {
if (data.reshare.share_type == OC.Share.SHARE_TYPE_GROUP) {
- html += '<span class="reshare">Shared with you and the group '+data.reshare.share_with+' by '+data.reshare.uid_owner+'</span>';
+ html += '<span class="reshare">'+t('core', 'Shared with you and the group %s by %s', data.reshare.share_with, data.reshare.uid_owner)+'</span>';
} else {
- html += '<span class="reshare">Shared with you by '+data.reshare.uid_owner+'</span>';
+ html += '<span class="reshare">'+t('core', 'Shared with you by %s', data.reshare.uid_owner)+'</span>';
}
html += '<br />';
}
if (possiblePermissions & OC.PERMISSION_SHARE) {
- html += '<input id="shareWith" type="text" placeholder="Share with" />';
+ html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Share with')+'" />';
html += '<ul id="shareWithList">';
html += '</ul>';
if (link) {
html += '<div id="link">';
- html += '<input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" /><label for="linkCheckbox">Share with link</label>';
- // TODO Change to lock/unlock icon?
- html += '<a href="#" id="showPassword" style="display:none;"><img class="svg" alt="Password protect" src="'+OC.imagePath('core', 'actions/triangle-n')+'"/></a>';
+ html += '<input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" /><label for="linkCheckbox">'+t('core', 'Share with link')+'</label>';
+ html += '<a href="#" id="showPassword" style="display:none;"><img class="svg" alt="'+t('core', 'Password protect')+'" src="'+OC.imagePath('core', 'actions/lock')+'"/></a>';
html += '<br />';
html += '<input id="linkText" type="text" readonly="readonly" />';
html += '<div id="linkPass">';
- html += '<input id="linkPassText" type="password" placeholder="Password" />';
+ html += '<input id="linkPassText" type="password" placeholder="'+t('core', 'Password')+'" />';
html += '</div>';
html += '</div>';
}
+ html += '<div id="expiration">';
+ html += '<input type="checkbox" name="expirationCheckbox" id="expirationCheckbox" value="1" /><label for="expirationCheckbox">'+t('core', 'Set expiration date')+'</label>';
+ html += '<input id="expirationDate" type="text" placeholder="'+t('core', 'Expiration date')+'" style="display:none; width:90%;" />';
html += '</div>';
$(html).appendTo(appendTo);
// Reset item shares
@@ -149,7 +160,14 @@ OC.Share={
if (share.share_type == OC.Share.SHARE_TYPE_LINK) {
OC.Share.showLink(itemSource, share.share_with);
} else {
- OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions);
+ if (share.collection) {
+ OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions, share.collection);
+ } else {
+ OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions, false);
+ }
+ }
+ if (share.expiration.length > 0) {
+ OC.Share.showExpirationDate(share.expiration);
}
});
}
@@ -162,12 +180,12 @@ OC.Share={
response(result.data);
} else {
// Suggest sharing via email if valid email address
- var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
- if (pattern.test(search.term)) {
- response([{label: 'Share via email: '+search.term, value: {shareType: OC.Share.SHARE_TYPE_EMAIL, shareWith: search.term}}]);
- } else {
- response(['No people found']);
- }
+// var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
+// if (pattern.test(search.term)) {
+// response([{label: t('core', 'Share via email: %s', search.term), value: {shareType: OC.Share.SHARE_TYPE_EMAIL, shareWith: search.term}}]);
+// } else {
+ response([t('core', 'No people found')]);
+// }
}
});
// }
@@ -176,6 +194,7 @@ OC.Share={
event.preventDefault();
},
select: function(event, selected) {
+ event.stopPropagation();
var itemType = $('#dropdown').data('item-type');
var itemSource = $('#dropdown').data('item-source');
var shareType = selected.item.value.shareType;
@@ -192,7 +211,7 @@ OC.Share={
}
});
} else {
- html += '<input id="shareWith" type="text" placeholder="Resharing is not allowed" style="width:90%;" disabled="disabled"/>';
+ html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Resharing is not allowed')+'" style="width:90%;" disabled="disabled"/>';
html += '</div>';
$(html).appendTo(appendTo);
}
@@ -213,58 +232,74 @@ OC.Share={
}
});
},
- addShareWith:function(shareType, shareWith, permissions, possiblePermissions) {
+ addShareWith:function(shareType, shareWith, permissions, possiblePermissions, collection) {
if (!OC.Share.itemShares[shareType]) {
OC.Share.itemShares[shareType] = [];
}
OC.Share.itemShares[shareType].push(shareWith);
- var editChecked = createChecked = updateChecked = deleteChecked = shareChecked = '';
- if (permissions & OC.PERMISSION_CREATE) {
- createChecked = 'checked="checked"';
- editChecked = 'checked="checked"';
- }
- if (permissions & OC.PERMISSION_UPDATE) {
- updateChecked = 'checked="checked"';
- editChecked = 'checked="checked"';
- }
- if (permissions & OC.PERMISSION_DELETE) {
- deleteChecked = 'checked="checked"';
- editChecked = 'checked="checked"';
- }
- if (permissions & OC.PERMISSION_SHARE) {
- shareChecked = 'checked="checked"';
- }
- var html = '<li style="clear: both;" data-share-type="'+shareType+'" data-share-with="'+shareWith+'">';
- html += shareWith;
- if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) {
- if (editChecked == '') {
- html += '<label style="display:none;">';
+ if (collection) {
+ if (collection.item_type == 'file' || collection.item_type == 'folder') {
+ var item = collection.path;
} else {
- html += '<label>';
+ var item = collection.item_source;
}
- html += '<input type="checkbox" name="edit" class="permissions" '+editChecked+' />can edit</label>';
- }
- html += '<a href="#" class="showCruds" style="display:none;"><img class="svg" alt="Unshare" src="'+OC.imagePath('core', 'actions/triangle-s')+'"/></a>';
- html += '<a href="#" class="unshare" style="display:none;"><img class="svg" alt="Unshare" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>';
- html += '<div class="cruds" style="display:none;">';
- if (possiblePermissions & OC.PERMISSION_CREATE) {
- html += '<label><input type="checkbox" name="create" class="permissions" '+createChecked+' data-permissions="'+OC.PERMISSION_CREATE+'" />create</label>';
+ var collectionList = $('#shareWithList li').filterAttr('data-collection', item);
+ if (collectionList.length > 0) {
+ $(collectionList).append(', '+shareWith);
+ } else {
+ var html = '<li style="clear: both;" data-collection="'+item+'">'+t('core', 'Shared in %s with %s', item, shareWith)+'</li>';
+ $('#shareWithList').prepend(html);
}
- if (possiblePermissions & OC.PERMISSION_UPDATE) {
- html += '<label><input type="checkbox" name="update" class="permissions" '+updateChecked+' data-permissions="'+OC.PERMISSION_UPDATE+'" />update</label>';
+ } else {
+ var editChecked = createChecked = updateChecked = deleteChecked = shareChecked = '';
+ if (permissions & OC.PERMISSION_CREATE) {
+ createChecked = 'checked="checked"';
+ editChecked = 'checked="checked"';
}
- if (possiblePermissions & OC.PERMISSION_DELETE) {
- html += '<label><input type="checkbox" name="delete" class="permissions" '+deleteChecked+' data-permissions="'+OC.PERMISSION_DELETE+'" />delete</label>';
+ if (permissions & OC.PERMISSION_UPDATE) {
+ updateChecked = 'checked="checked"';
+ editChecked = 'checked="checked"';
}
- if (possiblePermissions & OC.PERMISSION_SHARE) {
- html += '<label><input type="checkbox" name="share" class="permissions" '+shareChecked+' data-permissions="'+OC.PERMISSION_SHARE+'" />share</label>';
+ if (permissions & OC.PERMISSION_DELETE) {
+ deleteChecked = 'checked="checked"';
+ editChecked = 'checked="checked"';
}
- html += '</div>';
- html += '</li>';
- $(html).appendTo('#shareWithList');
-
+ if (permissions & OC.PERMISSION_SHARE) {
+ shareChecked = 'checked="checked"';
+ }
+ var html = '<li style="clear: both;" data-share-type="'+shareType+'" data-share-with="'+shareWith+'">';
+ html += '<a href="#" class="unshare" style="display:none;"><img class="svg" alt="'+t('core', 'Unshare')+'" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>';
+ html += shareWith;
+ if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) {
+ if (editChecked == '') {
+ html += '<label style="display:none;">';
+ } else {
+ html += '<label>';
+ }
+ html += '<input type="checkbox" name="edit" class="permissions" '+editChecked+' />'+t('core', 'can edit')+'</label>';
+ }
+ html += '<a href="#" class="showCruds" style="display:none;"><img class="svg" alt="'+t('core', 'access control')+'" src="'+OC.imagePath('core', 'actions/triangle-s')+'"/></a>';
+ html += '<div class="cruds" style="display:none;">';
+ if (possiblePermissions & OC.PERMISSION_CREATE) {
+ html += '<label><input type="checkbox" name="create" class="permissions" '+createChecked+' data-permissions="'+OC.PERMISSION_CREATE+'" />'+t('core', 'create')+'</label>';
+ }
+ if (possiblePermissions & OC.PERMISSION_UPDATE) {
+ html += '<label><input type="checkbox" name="update" class="permissions" '+updateChecked+' data-permissions="'+OC.PERMISSION_UPDATE+'" />'+t('core', 'update')+'</label>';
+ }
+ if (possiblePermissions & OC.PERMISSION_DELETE) {
+ html += '<label><input type="checkbox" name="delete" class="permissions" '+deleteChecked+' data-permissions="'+OC.PERMISSION_DELETE+'" />'+t('core', 'delete')+'</label>';
+ }
+ if (possiblePermissions & OC.PERMISSION_SHARE) {
+ html += '<label><input type="checkbox" name="share" class="permissions" '+shareChecked+' data-permissions="'+OC.PERMISSION_SHARE+'" />'+t('core', 'share')+'</label>';
+ }
+ html += '</div>';
+ html += '</li>';
+ $(html).appendTo('#shareWithList');
+ $('#expiration').show();
+ }
},
showLink:function(itemSource, password) {
+ OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = true;
$('#linkCheckbox').attr('checked', true);
var filename = $('tr').filterAttr('data-id', String(itemSource)).data('file');
if ($('#dir').val() == '/') {
@@ -279,8 +314,9 @@ OC.Share={
$('#showPassword').show();
if (password != null) {
$('#linkPass').show('blind');
- $('#linkPassText').attr('placeholder', 'Password protected');
+ $('#linkPassText').attr('placeholder', t('core', 'Password protected'));
}
+ $('#expiration').show();
},
hideLink:function() {
$('#linkText').hide('blind');
@@ -289,6 +325,15 @@ OC.Share={
},
dirname:function(path) {
return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
+ },
+ showExpirationDate:function(date) {
+ $('#expirationCheckbox').attr('checked', true);
+ $('#expirationDate').before('<br />');
+ $('#expirationDate').val(date);
+ $('#expirationDate').show();
+ $('#expirationDate').datepicker({
+ dateFormat : 'dd-mm-yy'
+ });
}
}
@@ -358,6 +403,9 @@ $(document).ready(function() {
var index = OC.Share.itemShares[shareType].indexOf(shareWith);
OC.Share.itemShares[shareType].splice(index, 1);
OC.Share.updateIcon(itemType, itemSource);
+ if (typeof OC.Share.statuses[itemSource] === 'undefined') {
+ $('#expiration').hide();
+ }
});
});
@@ -395,12 +443,17 @@ $(document).ready(function() {
// Create a link
OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ, function() {
OC.Share.showLink(itemSource);
- // TODO Change icon
+ OC.Share.updateIcon(itemType, itemSource);
});
} else {
// Delete private link
OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() {
OC.Share.hideLink();
+ OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = false;
+ OC.Share.updateIcon(itemType, itemSource);
+ if (typeof OC.Share.statuses[itemSource] === 'undefined') {
+ $('#expiration').hide();
+ }
});
}
});
@@ -420,8 +473,34 @@ $(document).ready(function() {
var itemSource = $('#dropdown').data('item-source');
OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $(this).val(), OC.PERMISSION_READ, function() {
$('#linkPassText').val('');
- $('#linkPassText').attr('placeholder', 'Password protected');
+ $('#linkPassText').attr('placeholder', t('core', 'Password protected'));
+ });
+ }
+ });
+
+ $('#expirationCheckbox').live('click', function() {
+ if (this.checked) {
+ OC.Share.showExpirationDate('');
+ } else {
+ var itemType = $('#dropdown').data('item-type');
+ var itemSource = $('#dropdown').data('item-source');
+ $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: '' }, function(result) {
+ if (!result || result.status !== 'success') {
+ OC.dialogs.alert(t('core', 'Error'), t('core', 'Error unsetting expiration date'));
+ }
+ $('#expirationDate').hide();
});
}
});
+
+ $('#expirationDate').live('change', function() {
+ var itemType = $('#dropdown').data('item-type');
+ var itemSource = $('#dropdown').data('item-source');
+ $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: $(this).val() }, function(result) {
+ if (!result || result.status !== 'success') {
+ OC.dialogs.alert(t('core', 'Error'), t('core', 'Error setting expiration date'));
+ }
+ });
+ });
+
});