mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-18 07:52:21 +01:00
Contacts: Basic import working again.
This commit is contained in:
parent
09442c2888
commit
1c94afbede
@ -46,7 +46,7 @@
|
||||
#leftcontent h3 img.shared:hover { opacity: 1; }
|
||||
|
||||
#groupactions { box-sizing: border-box; height: 4em; border-bottom: 1px solid #DDDDDD; }
|
||||
#groupactions > button, .addcontact {
|
||||
#groupactions > button, .addcontact, .import-upload-button {
|
||||
-moz-border-bottom-colors: none;
|
||||
-moz-border-left-colors: none;
|
||||
-moz-border-right-colors: none;
|
||||
@ -217,6 +217,26 @@ dl.form { display: inline-block; width: auto; margin: 0; padding: 0; cursor: nor
|
||||
|
||||
/* Single elements */
|
||||
#file_upload_target, #import_upload_target, #crop_target { display:none; }
|
||||
#import_fileupload {
|
||||
height: 2.29em;
|
||||
width: 2.5em;
|
||||
margin-right: -2.5em;
|
||||
cursor: pointer;
|
||||
z-index: 1001;
|
||||
}
|
||||
.import-upload-button {
|
||||
background-image: url("%webroot%/core/img/actions/upload-white.svg");
|
||||
background-position: center center;
|
||||
background-repeat: no-repeat;
|
||||
cursor: pointer;
|
||||
height: 2.29em;
|
||||
width: 2.5em;
|
||||
z-index: 100;
|
||||
margin: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
#toggle_all { position: absolute; bottom: .5em; left: .8em; }
|
||||
input.propertytype { float: left; font-size: .8em; width: 8em !important; direction: rtl;}
|
||||
.contactphoto { float: left; display: inline-block; border-radius: 0.3em; border: thin solid #bbb; margin: 0.5em; background: url('%webroot%/core/img/loading.gif') no-repeat center center; -moz-box-shadow: 0 1px 3px #777; -webkit-box-shadow: 0 1px 3px #777; box-shadow: 0 1px 3px #777; opacity: 1; }
|
||||
@ -227,7 +247,7 @@ input.propertytype { float: left; font-size: .8em; width: 8em !important; direct
|
||||
#phototools li { display: inline; }
|
||||
#phototools li a { float:left; cursor:pointer; width:22px; height:22px; opacity: 0.6; }
|
||||
#phototools li a:hover { opacity: 0.8; }
|
||||
#contactphoto_fileupload, #import_fileupload { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter:alpha(opacity=0); opacity:0; z-index:1001; width:0; height:0;}
|
||||
#contactphoto_fileupload, #import_fileupload { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter:alpha(opacity=0); opacity:0; z-index:1001; }
|
||||
.favorite { display: inline-block; float: left; height: 20px; width: 20px; background:url('%appswebroot%/contacts/img/inactive_star.png') no-repeat center; }
|
||||
.favorite.active, .favorite:hover { background:url('%appswebroot%/contacts/img/active_star.png') no-repeat center; }
|
||||
.favorite.inactive { background:url('%appswebroot%/contacts/img/inactive_star.png') no-repeat center; }
|
||||
|
223
js/app.js
223
js/app.js
@ -1254,26 +1254,207 @@ OC.Contacts = OC.Contacts || {
|
||||
$(this).find('.mailto').fadeOut(100);
|
||||
});
|
||||
|
||||
var addAddressbookCallback = function(name) {
|
||||
return;
|
||||
self.addAddressbook({name:name}, function(response) {
|
||||
console.log('addAddressbookCallback', response);
|
||||
if(response.status === 'success') {
|
||||
} else {
|
||||
}
|
||||
var addAddressbookCallback = function(select, name) {
|
||||
var id;
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
async:false,
|
||||
url:OC.filePath('contacts', 'ajax', 'addressbook/add.php'),
|
||||
data:{ name: name },
|
||||
success:function(jsondata) {
|
||||
console.log(jsondata);
|
||||
if(jsondata.status == 'success') {
|
||||
id = jsondata.data.addressbook.id
|
||||
} else {
|
||||
OC.notify({message:jsondata.data.message});
|
||||
}
|
||||
},
|
||||
error:function(jqXHR, textStatus, errorThrown) {
|
||||
OC.notify({message:textStatus + ': ' + errorThrown});
|
||||
id = false;
|
||||
},
|
||||
});
|
||||
return id;
|
||||
}
|
||||
|
||||
this.$importIntoSelect.multiSelect({
|
||||
createCallback:addAddressbookCallback,
|
||||
singleSelect: true,
|
||||
createText:String(t('contacts', 'Add group')),
|
||||
checked:[],
|
||||
oncheck:function() {},
|
||||
onuncheck:function() {},
|
||||
minWidth: 150,
|
||||
createCallback:addAddressbookCallback,
|
||||
singleSelect: true,
|
||||
createText:String(t('contacts', 'Add address book')),
|
||||
minWidth: 120,
|
||||
});
|
||||
|
||||
// Import using jquery.fileupload
|
||||
$(function() {
|
||||
var uploadingFiles = {}, numfiles = 0, uploadedfiles = 0, retries = 0;
|
||||
var aid, importError = false;
|
||||
var $progressbar = $('#import-progress');
|
||||
|
||||
var waitForImport = function() {
|
||||
if(numfiles == 0 && uploadedfiles == 0) {
|
||||
$progressbar.progressbar('value',100);
|
||||
if(!importError) {
|
||||
OC.notify({message:t('contacts', 'Import done')});
|
||||
}
|
||||
//OC.Contacts.Contacts.update({aid:aid});
|
||||
retries = aid = 0;
|
||||
$progressbar.fadeOut();
|
||||
$('.import-upload').show();
|
||||
} else {
|
||||
setTimeout(function() { //
|
||||
waitForImport();
|
||||
}, 1000);
|
||||
}
|
||||
};
|
||||
var doImport = function(file, aid, cb) {
|
||||
$.post(OC.filePath('contacts', '', 'import.php'), { id: aid, file: file, fstype: 'OC_FilesystemView' },
|
||||
function(jsondata) {
|
||||
if(jsondata.status != 'success') {
|
||||
importError = true;
|
||||
OC.notify({message:jsondata.data.message});
|
||||
}
|
||||
if(typeof cb == 'function') {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
};
|
||||
|
||||
var importFiles = function(aid, uploadingFiles) {
|
||||
console.log('importFiles', this, aid, uploadingFiles);
|
||||
if(numfiles != uploadedfiles) {
|
||||
OC.notify({message:t('contacts', 'Not all files uploaded. Retrying...')});
|
||||
retries += 1;
|
||||
if(retries > 3) {
|
||||
numfiles = uploadedfiles = retries = aid = 0;
|
||||
uploadingFiles = {};
|
||||
$progressbar.fadeOut();
|
||||
OC.dialogs.alert(t('contacts', 'Something went wrong with the upload, please retry.'), t('contacts', 'Error'));
|
||||
return;
|
||||
}
|
||||
setTimeout(function() { // Just to let any uploads finish
|
||||
importFiles(aid, uploadingFiles);
|
||||
}, 1000);
|
||||
}
|
||||
$progressbar.progressbar('value',50);
|
||||
var todo = uploadedfiles;
|
||||
$.each(uploadingFiles, function(fileName, data) {
|
||||
doImport(fileName, aid, function() {
|
||||
delete uploadingFiles[fileName];
|
||||
numfiles -= 1; uploadedfiles -= 1;
|
||||
$progressbar.progressbar('value',50+(50/(todo-uploadedfiles)));
|
||||
});
|
||||
})
|
||||
OC.notify({message:t('contacts', 'Importing...'), timeout:20});
|
||||
waitForImport();
|
||||
};
|
||||
|
||||
$('.doImport').on('click keypress', function(event) { // Just to let any uploads finish
|
||||
if(wrongKey(event)) {
|
||||
return;
|
||||
}
|
||||
aid = $(this).prev('select').val();
|
||||
$('.import-select').hide();
|
||||
importFiles(aid, uploadingFiles);
|
||||
});
|
||||
|
||||
$('#import_fileupload').fileupload({
|
||||
dropZone: $('#contacts'), // restrict dropZone to contacts list.
|
||||
acceptFileTypes: /^text\/(directory|vcard|x-vcard)$/i,
|
||||
add: function(e, data) {
|
||||
var files = data.files;
|
||||
var totalSize=0;
|
||||
if(files) {
|
||||
numfiles += files.length; uploadedfiles = 0;
|
||||
for(var i=0;i<files.length;i++) {
|
||||
if(files[i].size ==0 && files[i].type== '') {
|
||||
OC.dialogs.alert(t('files', 'Unable to upload your file as it is a directory or has 0 bytes'), t('files', 'Upload Error'));
|
||||
return;
|
||||
}
|
||||
totalSize+=files[i].size;
|
||||
}
|
||||
}
|
||||
if(totalSize>$('#max_upload').val()) {
|
||||
OC.dialogs.alert(t('contacts','The file you are trying to upload exceed the maximum size for file uploads on this server.'), t('contacts','Upload too large'));
|
||||
numfiles = uploadedfiles = retries = aid = 0;
|
||||
uploadingFiles = {};
|
||||
return;
|
||||
} else {
|
||||
if($.support.xhrFileUpload) {
|
||||
$.each(files, function(i, file) {
|
||||
var fileName = file.name;
|
||||
console.log('file.name', file.name);
|
||||
var jqXHR = $('#import_fileupload').fileupload('send',
|
||||
{
|
||||
files: file,
|
||||
formData: function(form) {
|
||||
var formArray = form.serializeArray();
|
||||
formArray['aid'] = aid;
|
||||
return formArray;
|
||||
}})
|
||||
.success(function(response, textStatus, jqXHR) {
|
||||
if(response.status == 'success') {
|
||||
// import the file
|
||||
uploadedfiles += 1;
|
||||
} else {
|
||||
OC.notify({message:response.data.message});
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.error(function(jqXHR, textStatus, errorThrown) {
|
||||
console.log(textStatus);
|
||||
OC.notify({message:errorThrown + ': ' + textStatus,});
|
||||
});
|
||||
uploadingFiles[fileName] = jqXHR;
|
||||
});
|
||||
} else {
|
||||
data.submit().success(function(data, status) {
|
||||
response = jQuery.parseJSON(data[0].body.innerText);
|
||||
if(response[0] != undefined && response[0].status == 'success') {
|
||||
var file=response[0];
|
||||
delete uploadingFiles[file.name];
|
||||
$('tr').filterAttr('data-file',file.name).data('mime',file.mime);
|
||||
var size = $('tr').filterAttr('data-file',file.name).find('td.filesize').text();
|
||||
if(size==t('files','Pending')){
|
||||
$('tr').filterAttr('data-file',file.name).find('td.filesize').text(file.size);
|
||||
}
|
||||
FileList.loadingDone(file.name);
|
||||
} else {
|
||||
OC.notify({message:response.data.message});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: function(e, data) {
|
||||
console.log('fail');
|
||||
OC.notify({message:data.errorThrown + ': ' + data.textStatus});
|
||||
// TODO: Remove file from upload queue.
|
||||
},
|
||||
progressall: function(e, data) {
|
||||
var progress = (data.loaded/data.total)*50;
|
||||
$progressbar.progressbar('value',progress);
|
||||
},
|
||||
start: function(e, data) {
|
||||
$progressbar.progressbar({value:0});
|
||||
$progressbar.fadeIn();
|
||||
if(data.dataType != 'iframe ') {
|
||||
$('#upload input.stop').show();
|
||||
}
|
||||
},
|
||||
stop: function(e, data) {
|
||||
console.log('stop, data', data);
|
||||
// stop only gets fired once so we collect uploaded items here.
|
||||
$('.import-upload').hide();
|
||||
$('.import-select').show();
|
||||
|
||||
if(data.dataType != 'iframe ') {
|
||||
$('#upload input.stop').hide();
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
$(document).on('keypress', function(event) {
|
||||
if(event.target.nodeName.toUpperCase() != 'BODY') {
|
||||
return;
|
||||
@ -1583,9 +1764,14 @@ OC.Contacts = OC.Contacts || {
|
||||
}
|
||||
});
|
||||
},
|
||||
// NOTE: Deprecated
|
||||
addAddressbook:function(data, cb) {
|
||||
$.post(OC.filePath('contacts', 'ajax', 'addressbook/add.php'), { name: data.name, description: data.description },
|
||||
function(jsondata) {
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
async:false,
|
||||
url:OC.filePath('contacts', 'ajax', 'addressbook/add.php'),
|
||||
data:{ name: data.name, description: data.description },
|
||||
success:function(jsondata) {
|
||||
if(jsondata.status == 'success') {
|
||||
if(typeof cb === 'function') {
|
||||
cb({
|
||||
@ -1595,11 +1781,12 @@ OC.Contacts = OC.Contacts || {
|
||||
}
|
||||
} else {
|
||||
if(typeof cb === 'function') {
|
||||
cb({status:'error'});
|
||||
cb({status:'error', message:jsondata.data.message});
|
||||
}
|
||||
}
|
||||
});
|
||||
}});
|
||||
},
|
||||
// NOTE: Deprecated
|
||||
selectAddressbook:function(cb) {
|
||||
var self = this;
|
||||
var jqxhr = $.get(OC.filePath('contacts', 'templates', 'selectaddressbook.html'), function(data) {
|
||||
|
@ -42,22 +42,27 @@
|
||||
</li>
|
||||
<li><h3 class="import" role="button"><?php echo $l->t('Import'); ?></h3>
|
||||
<ul class="hidden">
|
||||
<li>
|
||||
<li class="import-upload">
|
||||
<form id="import_upload_form" action="<?php echo OCP\Util::linkTo('contacts', 'ajax/uploadimport.php'); ?>" method="post" enctype="multipart/form-data" target="import_upload_target">
|
||||
<input id="import_fileupload" type="file" accept="text/vcard,text/x-vcard,text/directory" multiple="multiple" />
|
||||
<input id="import_fileupload" type="file" accept="text/vcard,text/x-vcard,text/directory" multiple="multiple" name="importfile" />
|
||||
<label><?php echo $l->t('Select files to import'); ?></label>
|
||||
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $_['uploadMaxFilesize'] ?>" id="max_upload">
|
||||
<button class="import-upload-button" title="<?php echo $l->t('Select files'); ?>"></button>
|
||||
</form>
|
||||
<iframe name="import_upload_target" id='import_upload_target' src=""></iframe>
|
||||
</li>
|
||||
<li><?php echo $l->t('Import into:'); ?></li>
|
||||
<li>
|
||||
<select id="import_into" title="<?php echo $l->t('Import into:'); ?>">
|
||||
<li class="import-select hidden"><label><?php echo $l->t('Import into:'); ?></label></li>
|
||||
<li class="import-select hidden"><select id="import_into" title="<?php echo $l->t('Import into:'); ?>">
|
||||
<?php foreach($_['addressbooks'] as $addressbook) {
|
||||
if($addressbook['permissions'] & OCP\PERMISSION_CREATE) {
|
||||
?>
|
||||
<option value="<?php echo $addressbook['id'] ?>"><?php echo $addressbook['displayname'] ?></option>
|
||||
<?php }} ?>
|
||||
</select>
|
||||
<button class="doImport"><?php echo $l->t('OK'); ?></button>
|
||||
</li>
|
||||
<li>
|
||||
<div id="import-progress"></div>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
Loading…
x
Reference in New Issue
Block a user