Merge branch 'master' into subadmin

This commit is contained in:
Georg Ehrke 2012-07-21 17:01:45 +02:00
commit 6ccd4e0cfb
1 changed files with 129 additions and 84 deletions

View File

@ -12,10 +12,38 @@ String.prototype.strip_tags = function(){
Contacts={ Contacts={
UI:{ UI:{
/**
* Arguments:
* message: The text message to show. The only mandatory parameter.
* timeout: The timeout in seconds before the notification disappears. Default 10.
* timeouthandler: A function to run on timeout.
* clickhandler: A function to run on click. If a timeouthandler is given it will be cancelled.
* data: An object that will be passed as argument to the timeouthandler and clickhandler functions.
*/
notify:function(params) { notify:function(params) {
$('#notification').text(params.message); var notifier = $('#notification');
$('#notification').fadeIn(); notifier.text(params.message);
setTimeout(function() {$('#notification').fadeOut();}, 10000); notifier.fadeIn();
var timer = setTimeout(function() {
notifier.fadeOut();
if(params.timeouthandler && $.isFunction(params.timeouthandler)) {
params.timeouthandler(notifier.data(dataid));
notifier.off('click');
notifier.data(dataid, null);
}
}, params.timeout && $.isNumeric(params.timeout) ? parseInt(params.timeout)*1000 : 10000);
var dataid = timer.toString();
if(params.data) {
notifier.data(dataid, params.data);
}
if(params.clickhandler && $.isFunction(params.clickhandler)) {
notifier.on('click', function() {
clearTimeout(timer);
notifier.off('click');
params.clickhandler(notifier.data(dataid));
notifier.data(dataid, null);
});
}
}, },
notImplemented:function() { notImplemented:function() {
OC.dialogs.alert(t('contacts', 'Sorry, this functionality has not been implemented yet'), t('contacts', 'Not implemented')); OC.dialogs.alert(t('contacts', 'Sorry, this functionality has not been implemented yet'), t('contacts', 'Not implemented'));
@ -96,7 +124,7 @@ Contacts={
$('.addresscard,.propertylist li,.propertycontainer').hover( $('.addresscard,.propertylist li,.propertycontainer').hover(
function () { function () {
$(this).find('.globe,.mail,.delete,.edit').animate({ opacity: 1.0 }, 200, function() {}); $(this).find('.globe,.mail,.delete,.edit').animate({ opacity: 1.0 }, 200, function() {});
}, },
function () { function () {
$(this).find('.globe,.mail,.delete,.edit').animate({ opacity: 0.1 }, 200, function() {}); $(this).find('.globe,.mail,.delete,.edit').animate({ opacity: 0.1 }, 200, function() {});
} }
@ -107,7 +135,7 @@ Contacts={
obj.tipsy('hide'); obj.tipsy('hide');
Contacts.UI.Card.deleteProperty(obj, 'single'); Contacts.UI.Card.deleteProperty(obj, 'single');
} }
var goToUrl = function(obj) { var goToUrl = function(obj) {
var url = Contacts.UI.propertyContainerFor(obj).find('#url').val(); var url = Contacts.UI.propertyContainerFor(obj).find('#url').val();
if(url != '') { if(url != '') {
@ -115,7 +143,7 @@ Contacts={
newWindow.focus(); newWindow.focus();
} }
} }
$('#identityprops a.delete').click( function() { deleteItem($(this)) }); $('#identityprops a.delete').click( function() { deleteItem($(this)) });
$('#identityprops a.delete').keydown( function() { deleteItem($(this)) }); $('#identityprops a.delete').keydown( function() { deleteItem($(this)) });
$('#categories_value a.edit').click( function() { $(this).tipsy('hide');OCCategories.edit(); } ); $('#categories_value a.edit').click( function() { $(this).tipsy('hide');OCCategories.edit(); } );
@ -140,7 +168,7 @@ Contacts={
}); });
$('#edit_name').click(function(){Contacts.UI.Card.editName()}); $('#edit_name').click(function(){Contacts.UI.Card.editName()});
$('#edit_name').keydown(function(){Contacts.UI.Card.editName()}); $('#edit_name').keydown(function(){Contacts.UI.Card.editName()});
$('#phototools li a').click(function() { $('#phototools li a').click(function() {
$(this).tipsy('hide'); $(this).tipsy('hide');
}); });
@ -167,13 +195,13 @@ Contacts={
OC.dialogs.filepicker(t('contacts', 'Select photo'), Contacts.UI.Card.cloudPhotoSelected, false, 'image', true); OC.dialogs.filepicker(t('contacts', 'Select photo'), Contacts.UI.Card.cloudPhotoSelected, false, 'image', true);
}); });
/* Initialize the photo edit dialog */ /* Initialize the photo edit dialog */
$('#edit_photo_dialog').dialog({ $('#edit_photo_dialog').dialog({
autoOpen: false, modal: true, height: 'auto', width: 'auto' autoOpen: false, modal: true, height: 'auto', width: 'auto'
}); });
$('#edit_photo_dialog' ).dialog( 'option', 'buttons', [ $('#edit_photo_dialog' ).dialog( 'option', 'buttons', [
{ {
text: "Ok", text: "Ok",
click: function() { click: function() {
Contacts.UI.Card.savePhoto(this); Contacts.UI.Card.savePhoto(this);
$(this).dialog('close'); $(this).dialog('close');
} }
@ -183,7 +211,7 @@ Contacts={
click: function() { $(this).dialog('close'); } click: function() { $(this).dialog('close'); }
} }
] ); ] );
// Name has changed. Update it and reorder. // Name has changed. Update it and reorder.
$('#fn').change(function(){ $('#fn').change(function(){
var name = $('#fn').val().strip_tags(); var name = $('#fn').val().strip_tags();
@ -198,16 +226,16 @@ Contacts={
Contacts.UI.Contacts.scrollTo(Contacts.UI.Card.id); Contacts.UI.Contacts.scrollTo(Contacts.UI.Card.id);
}); });
$('#contacts_deletecard').click( function() { Contacts.UI.Card.doDelete();return false;} ); $('#contacts_deletecard').click( function() { Contacts.UI.Card.delayedDelete();return false;} );
$('#contacts_deletecard').keydown( function(event) { $('#contacts_deletecard').keydown( function(event) {
if(event.which == 13 || event.which == 32) { if(event.which == 13 || event.which == 32) {
Contacts.UI.Card.doDelete(); Contacts.UI.Card.delayedDelete();
} }
return false; return false;
}); });
$('#contacts_downloadcard').click( function() { Contacts.UI.Card.doExport();return false;} ); $('#contacts_downloadcard').click( function() { Contacts.UI.Card.doExport();return false;} );
$('#contacts_downloadcard').keydown( function(event) { $('#contacts_downloadcard').keydown( function(event) {
if(event.which == 13 || event.which == 32) { if(event.which == 13 || event.which == 32) {
Contacts.UI.Card.doExport(); Contacts.UI.Card.doExport();
} }
@ -222,12 +250,12 @@ Contacts={
$('#contacts_details_photo_wrapper').bind('dragover',function(event){ $('#contacts_details_photo_wrapper').bind('dragover',function(event){
$(event.target).addClass('droppable'); $(event.target).addClass('droppable');
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
}); });
$('#contacts_details_photo_wrapper').bind('dragleave',function(event){ $('#contacts_details_photo_wrapper').bind('dragleave',function(event){
$(event.target).removeClass('droppable'); $(event.target).removeClass('droppable');
//event.stopPropagation(); //event.stopPropagation();
//event.preventDefault(); //event.preventDefault();
}); });
$('#contacts_details_photo_wrapper').bind('drop',function(event){ $('#contacts_details_photo_wrapper').bind('drop',function(event){
event.stopPropagation(); event.stopPropagation();
@ -313,10 +341,10 @@ Contacts={
if($('.contacts li').length > 0) { if($('.contacts li').length > 0) {
$.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':newid},function(jsondata){ $.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':newid},function(jsondata){
if(jsondata.status == 'success'){ if(jsondata.status == 'success'){
if(bookid == 'unknown') { if(bookid == 'unknown') {
bookid = jsondata.data.addressbookid; bookid = jsondata.data.addressbookid;
var contact = Contacts.UI.Contacts.insertContact({ var contact = Contacts.UI.Contacts.insertContact({
contactlist:$('#contacts ul[data-id="'+bookid+'"]'), contactlist:$('#contacts ul[data-id="'+bookid+'"]'),
data:jsondata.data data:jsondata.data
}); });
} }
@ -330,7 +358,7 @@ Contacts={
}); });
} }
} }
// Make sure proper DOM is loaded. // Make sure proper DOM is loaded.
if(!$('#card').length && newid) { if(!$('#card').length && newid) {
console.log('Loading card DOM'); console.log('Loading card DOM');
@ -415,7 +443,7 @@ Contacts={
} }
}); });
} }
if(!$('#card').length) { if(!$('#card').length) {
console.log('Loading card DOM'); console.log('Loading card DOM');
$.getJSON(OC.filePath('contacts', 'ajax', 'loadcard.php'),{'requesttoken': requesttoken},function(jsondata){ $.getJSON(OC.filePath('contacts', 'ajax', 'loadcard.php'),{'requesttoken': requesttoken},function(jsondata){
@ -432,47 +460,56 @@ Contacts={
localAddcontact(n, fn, aid, isnew); localAddcontact(n, fn, aid, isnew);
} }
}, },
doDelete:function() { delayedDelete:function() {
$('#contacts_deletecard').tipsy('hide'); $('#contacts_deletecard').tipsy('hide');
OC.dialogs.confirm(t('contacts', 'Are you sure you want to delete this contact?'), t('contacts', 'Warning'), function(answer) { var newid = '', bookid;
if(answer == true) { var curlistitem = $('#contacts li[data-id="'+Contacts.UI.Card.id+'"]');
$.post(OC.filePath('contacts', 'ajax', 'deletecard.php'),{'id':Contacts.UI.Card.id},function(jsondata){ curlistitem.removeClass('active');
if(jsondata.status == 'success'){ var newlistitem = curlistitem.prev('li');
var newid = '', bookid; if(!newlistitem) {
var curlistitem = $('#contacts li[data-id="'+jsondata.data.id+'"]'); newlistitem = curlistitem.next('li');
var newlistitem = curlistitem.prev('li'); }
if(!newlistitem) { curlistitem.detach();
newlistitem = curlistitem.next('li'); if($(newlistitem).is('li')) {
} newid = newlistitem.data('id');
curlistitem.remove(); bookid = newlistitem.data('bookid');
if($(newlistitem).is('li')) { }
newid = newlistitem.data('id'); $('#rightcontent').data('id',newid);
bookid = newlistitem.data('bookid'); this.id = this.fn = this.fullname = this.shortname = this.famname = this.givname = this.addname = this.honpre = this.honsuf = '';
} this.data = undefined;
$('#rightcontent').data('id',newid);
this.id = this.fn = this.fullname = this.shortname = this.famname = this.givname = this.addname = this.honpre = this.honsuf = ''; if($('.contacts li').length > 0) { // Load first in list.
this.data = undefined; Contacts.UI.Card.update({cid:newid, aid:bookid});
} else {
if($('.contacts li').length > 0) { // Load first in list. // load intro page
Contacts.UI.Card.update({cid:newid, aid:bookid}); $.getJSON(OC.filePath('contacts', 'ajax', 'loadintro.php'),{},function(jsondata){
} else { if(jsondata.status == 'success'){
// load intro page id = '';
$.getJSON(OC.filePath('contacts', 'ajax', 'loadintro.php'),{},function(jsondata){ $('#rightcontent').data('id','');
if(jsondata.status == 'success'){ $('#rightcontent').html(jsondata.data.page);
id = ''; }
$('#rightcontent').data('id',''); else{
$('#rightcontent').html(jsondata.data.page); OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
} }
else{ });
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); }
} Contacts.UI.notify({
}); data:curlistitem,
} message:t('contacts','Click to undo deletion of "') + curlistitem.find('a').text() + '"',
} timeouthandler:function(contact) {
else{ Contacts.UI.Card.doDelete(contact.data('id'));
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); delete contact;
} },
}); clickhandler:function(contact) {
Contacts.UI.Contacts.insertContact({contact:contact});
Contacts.UI.notify({message:t('contacts', 'Cancelled deletion of: "') + curlistitem.find('a').text() + '"'});
}
});
},
doDelete:function(id) {
$.post(OC.filePath('contacts', 'ajax', 'deletecard.php'),{'id':id},function(jsondata) {
if(jsondata.status == 'error'){
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
} }
}); });
return false; return false;
@ -524,7 +561,7 @@ Contacts={
$('#contacts_propertymenu_dropdown a[data-type="'+propname+'"]').parent().hide(); $('#contacts_propertymenu_dropdown a[data-type="'+propname+'"]').parent().hide();
var property = this.data[propname][0]; var property = this.data[propname][0];
var value = property['value'], checksum = property['checksum']; var value = property['value'], checksum = property['checksum'];
if(propname == 'BDAY') { if(propname == 'BDAY') {
var val = $.datepicker.parseDate('yy-mm-dd', value.substring(0, 10)); var val = $.datepicker.parseDate('yy-mm-dd', value.substring(0, 10));
value = $.datepicker.formatDate('dd-mm-yy', val); value = $.datepicker.formatDate('dd-mm-yy', val);
@ -589,7 +626,7 @@ Contacts={
$.each(names, function(key, value) { $.each(names, function(key, value) {
$('#fn_select') $('#fn_select')
.append($('<option></option>') .append($('<option></option>')
.text(value)); .text(value));
}); });
$('#fn_select').combobox('value', this.fn); $('#fn_select').combobox('value', this.fn);
$('#contact_identity').find('*[data-element="N"]').data('checksum', this.data.N[0]['checksum']); $('#contact_identity').find('*[data-element="N"]').data('checksum', this.data.N[0]['checksum']);
@ -840,7 +877,7 @@ Contacts={
title: t('contacts', 'Edit name'), title: t('contacts', 'Edit name'),
height: 'auto', width: 'auto', height: 'auto', width: 'auto',
buttons: { buttons: {
'Ok':function() { 'Ok':function() {
Contacts.UI.Card.saveName(this); Contacts.UI.Card.saveName(this);
$(this).dialog('close'); $(this).dialog('close');
}, },
@ -891,9 +928,9 @@ Contacts={
$.each(names, function(key, value) { $.each(names, function(key, value) {
$('#fn_select') $('#fn_select')
.append($('<option></option>') .append($('<option></option>')
.text(value)); .text(value));
}); });
if(this.id == '') { if(this.id == '') {
var aid = $(dlg).find('#aid').val(); var aid = $(dlg).find('#aid').val();
Contacts.UI.Card.add(n.join(';'), $('#short').text(), aid); Contacts.UI.Card.add(n.join(';'), $('#short').text(), aid);
@ -957,7 +994,7 @@ Contacts={
container = $('#addressdisplay dl').last(); container = $('#addressdisplay dl').last();
container.removeClass('template').addClass('propertycontainer'); container.removeClass('template').addClass('propertycontainer');
} else { } else {
params['checksum'] = Contacts.UI.checksumFor(obj); params['checksum'] = Contacts.UI.checksumFor(obj);
} }
/* Initialize the address edit dialog */ /* Initialize the address edit dialog */
if($('#edit_address_dialog').dialog('isOpen') == true){ if($('#edit_address_dialog').dialog('isOpen') == true){
@ -1173,7 +1210,7 @@ Contacts={
$('#phototools li a').tipsy('hide'); $('#phototools li a').tipsy('hide');
var wrapper = $('#contacts_details_photo_wrapper'); var wrapper = $('#contacts_details_photo_wrapper');
wrapper.addClass('loading').addClass('wait'); wrapper.addClass('loading').addClass('wait');
var img = new Image(); var img = new Image();
$(img).load(function () { $(img).load(function () {
$('img.contacts_details_photo').remove() $('img.contacts_details_photo').remove()
@ -1182,9 +1219,9 @@ Contacts={
$(this).insertAfter($('#phototools')).fadeIn(); $(this).insertAfter($('#phototools')).fadeIn();
}).error(function () { }).error(function () {
// notify the user that the image could not be loaded // notify the user that the image could not be loaded
$(t('contacts','something went wrong.')).insertAfter($('#phototools')); Contacts.UI.notify({message:t('contacts','Error loading profile picture.')});
}).attr('src', OC.linkTo('contacts', 'photo.php')+'?id='+self.id+refreshstr); }).attr('src', OC.linkTo('contacts', 'photo.php')+'?id='+self.id+refreshstr);
$.getJSON(OC.filePath('contacts', 'ajax', 'loadphoto.php'),{'id':this.id, 'refresh': refresh},function(jsondata){ $.getJSON(OC.filePath('contacts', 'ajax', 'loadphoto.php'),{'id':this.id, 'refresh': refresh},function(jsondata){
if(jsondata.status == 'success'){ if(jsondata.status == 'success'){
$('#contacts_details_photo_wrapper').data('checksum', jsondata.data.checksum); $('#contacts_details_photo_wrapper').data('checksum', jsondata.data.checksum);
@ -1430,7 +1467,7 @@ Contacts={
var displayname = $("#displayname_"+bookid).val().trim(); var displayname = $("#displayname_"+bookid).val().trim();
var active = $("#edit_active_"+bookid+":checked").length; var active = $("#edit_active_"+bookid+":checked").length;
var description = $("#description_"+bookid).val(); var description = $("#description_"+bookid).val();
if(displayname.length == 0) { if(displayname.length == 0) {
OC.dialogs.alert(t('contacts', 'Displayname cannot be empty.'), t('contacts', 'Error')); OC.dialogs.alert(t('contacts', 'Displayname cannot be empty.'), t('contacts', 'Error'));
return false; return false;
@ -1498,13 +1535,21 @@ Contacts={
alert('Dropping address books not implemented yet'); alert('Dropping address books not implemented yet');
}, },
/** /**
* @params params An object with the propeties 'contactlist':a jquery object of the ul to insert into, * @params params An object with the properties 'contactlist':a jquery object of the ul to insert into,
* 'contacts':a jquery object of all items in the list and either 'data': an object with the properties * 'contacts':a jquery object of all items in the list and either 'data': an object with the properties
* id, addressbookid and displayname or 'contact': a listitem to be inserted directly. * id, addressbookid and displayname or 'contact': a listitem to be inserted directly.
* If 'contacts' is defined the new contact will be inserted alphabetically into the list, otherwise * If 'contactlist' or 'contacts' aren't defined they will be search for based in the properties in 'data'.
* it will be appended.
*/ */
insertContact:function(params) { insertContact:function(params) {
if(!params.contactlist) {
// FIXME: Check if contact really exists.
var bookid = params.data ? params.data.addressbookid : params.contact.data('bookid');
params.contactlist = $('#contacts ul[data-id="'+bookid+'"]');
}
if(!params.contacts) {
var bookid = params.data ? params.data.addressbookid : params.contact.data('bookid');
params.contacts = $('#contacts ul[data-id="'+bookid+'"] li');
}
var contact = params.data var contact = params.data
? $('<li data-id="'+params.data.id+'" data-bookid="'+params.data.addressbookid+'" role="button"><a href="'+OC.linkTo('contacts', 'index.php')+'&id='+params.data.id+'" style="background: url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+params.data.id+') no-repeat scroll 0% 0% transparent;">'+params.data.displayname+'</a></li>') ? $('<li data-id="'+params.data.id+'" data-bookid="'+params.data.addressbookid+'" role="button"><a href="'+OC.linkTo('contacts', 'index.php')+'&id='+params.data.id+'" style="background: url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+params.data.id+') no-repeat scroll 0% 0% transparent;">'+params.data.displayname+'</a></li>')
: params.contact; : params.contact;
@ -1545,7 +1590,7 @@ Contacts={
$.getJSON(OC.filePath('contacts', 'ajax', 'contacts.php'),opts,function(jsondata){ $.getJSON(OC.filePath('contacts', 'ajax', 'contacts.php'),opts,function(jsondata){
if(jsondata.status == 'success'){ if(jsondata.status == 'success'){
var books = jsondata.data.entries; var books = jsondata.data.entries;
$.each(books, function(b, book) { $.each(books, function(b, book) {
if($('#contacts h3[data-id="'+b+'"]').length == 0) { if($('#contacts h3[data-id="'+b+'"]').length == 0) {
firstrun = true; firstrun = true;
if($('#contacts h3').length == 0) { if($('#contacts h3').length == 0) {
@ -1564,7 +1609,7 @@ Contacts={
if(!added) { if(!added) {
$('#contacts').append(item); $('#contacts').append(item);
} }
} }
} }
$('#contacts h3[data-id="'+b+'"]').on('click', function(event) { $('#contacts h3[data-id="'+b+'"]').on('click', function(event) {
@ -1644,13 +1689,13 @@ $(document).ready(function(){
$('#notification').click(function(){ $('#notification').click(function(){
$('#notification').fadeOut(); $('#notification').fadeOut();
}); });
$('#chooseaddressbook').click(Contacts.UI.Addressbooks.overview); $('#chooseaddressbook').click(Contacts.UI.Addressbooks.overview);
$('#chooseaddressbook').keydown(Contacts.UI.Addressbooks.overview); $('#chooseaddressbook').keydown(Contacts.UI.Addressbooks.overview);
$('#contacts_newcontact').click(Contacts.UI.Card.editNew); $('#contacts_newcontact').click(Contacts.UI.Card.editNew);
$('#contacts_newcontact').keydown(Contacts.UI.Card.editNew); $('#contacts_newcontact').keydown(Contacts.UI.Card.editNew);
// Load a contact. // Load a contact.
$('.contacts').keydown(function(event) { $('.contacts').keydown(function(event) {
if(event.which == 13 || event.which == 32) { if(event.which == 13 || event.which == 32) {
@ -1722,7 +1767,7 @@ $(document).ready(function(){
} }
} }
}; };
fileUpload.onprogress = function(e){ fileUpload.onprogress = function(e){
if (e.lengthComputable){ if (e.lengthComputable){
var _progress = Math.round((e.loaded * 100) / e.total); var _progress = Math.round((e.loaded * 100) / e.total);
@ -1752,7 +1797,7 @@ $(document).ready(function(){
$(function() { $(function() {
var uploadingFiles = {}, numfiles = 0, uploadedfiles = 0, retries = 0; var uploadingFiles = {}, numfiles = 0, uploadedfiles = 0, retries = 0;
var aid; var aid;
$('#import_upload_start').fileupload({ $('#import_upload_start').fileupload({
dropZone: $('#contacts'), // restrict dropZone to contacts list. dropZone: $('#contacts'), // restrict dropZone to contacts list.
acceptFileTypes: /^text\/(directory|vcard|x-vcard)$/i, acceptFileTypes: /^text\/(directory|vcard|x-vcard)$/i,
@ -1914,7 +1959,7 @@ $(document).ready(function(){
$(this).dialog('close'); $(this).dialog('close');
} }
}, },
'Cancel':function() { 'Cancel':function() {
$(this).dialog('close'); $(this).dialog('close');
numfiles = uploadedfiles = retries = aid = 0; numfiles = uploadedfiles = retries = aid = 0;
uploadingFiles = {}; uploadingFiles = {};
@ -1941,11 +1986,11 @@ $(document).ready(function(){
} }
if(data.dataType != 'iframe ') { if(data.dataType != 'iframe ') {
$('#upload input.stop').hide(); $('#upload input.stop').hide();
} }
} }
}) })
}); });
Contacts.UI.loadHandlers(); Contacts.UI.loadHandlers();
Contacts.UI.Contacts.update({cid:id}); Contacts.UI.Contacts.update({cid:id});
}); });