summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-07-22 14:49:38 +0200
committerThomas Tanghus <thomas@tanghus.net>2012-07-23 01:17:38 +0200
commit644b6e60d555cf5bae1c03e32c7330fe4d8dce56 (patch)
tree401412e16e7b6e99accec43ee345d5386d8dea38 /apps
parentdc05fd7b920eee413124a67af7747106c8a652e0 (diff)
downloadnextcloud-server-644b6e60d555cf5bae1c03e32c7330fe4d8dce56.tar.gz
nextcloud-server-644b6e60d555cf5bae1c03e32c7330fe4d8dce56.zip
Revert "No need to set checksum for PHOTO."
This reverts commit 3937d19fa2ef3da2719d0425ce02707d0345960c.
Diffstat (limited to 'apps')
-rw-r--r--apps/contacts/ajax/loadphoto.php46
-rw-r--r--apps/contacts/js/contacts.js104
2 files changed, 101 insertions, 49 deletions
diff --git a/apps/contacts/ajax/loadphoto.php b/apps/contacts/ajax/loadphoto.php
new file mode 100644
index 00000000000..be924b5db4d
--- /dev/null
+++ b/apps/contacts/ajax/loadphoto.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * ownCloud - Addressbook
+ *
+ * @author Thomas Tanghus
+ * @copyright 2012 Thomas Tanghus <thomas@tanghus.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+// Check if we are a user
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('contacts');
+
+require_once 'loghandler.php';
+
+$id = isset($_GET['id']) ? $_GET['id'] : '';
+$refresh = isset($_GET['refresh']) ? true : false;
+
+if($id == '') {
+ bailOut(OC_Contacts_App::$l10n->t('Missing contact id.'));
+}
+
+$checksum = '';
+$vcard = OC_Contacts_App::getContactVCard( $id );
+foreach($vcard->children as $property){
+ if($property->name == 'PHOTO') {
+ $checksum = md5($property->serialize());
+ break;
+ }
+}
+
+OCP\JSON::success(array('data' => array('checksum'=>$checksum)));
+
diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js
index de6060a1118..7c1304c559a 100644
--- a/apps/contacts/js/contacts.js
+++ b/apps/contacts/js/contacts.js
@@ -21,31 +21,27 @@ Contacts={
* data: An object that will be passed as argument to the timeouthandler and clickhandler functions.
*/
notify:function(params) {
- self = this;
- if(!self.notifier) {
- self.notifier = $('#notification');
- }
- self.notifier.text(params.message);
- self.notifier.fadeIn();
- self.notifier.on('click', function() { $(this).fadeOut();});
+ var notifier = $('#notification');
+ notifier.text(params.message);
+ notifier.fadeIn();
var timer = setTimeout(function() {
- self.notifier.fadeOut();
+ notifier.fadeOut();
if(params.timeouthandler && $.isFunction(params.timeouthandler)) {
- params.timeouthandler(self.notifier.data(dataid));
- self.notifier.off('click');
- self.notifier.removeData(dataid);
+ 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) {
- self.notifier.data(dataid, params.data);
+ notifier.data(dataid, params.data);
}
if(params.clickhandler && $.isFunction(params.clickhandler)) {
- self.notifier.on('click', function() {
+ notifier.on('click', function() {
clearTimeout(timer);
- self.notifier.off('click');
- params.clickhandler(self.notifier.data(dataid));
- self.notifier.removeData(dataid);
+ notifier.off('click');
+ params.clickhandler(notifier.data(dataid));
+ notifier.data(dataid, null);
});
}
},
@@ -299,6 +295,16 @@ Contacts={
$('#contacts_propertymenu_dropdown a').keydown(propertyMenuItem);
},
Card:{
+ id:'',
+ fn:'',
+ fullname:'',
+ shortname:'',
+ famname:'',
+ givname:'',
+ addname:'',
+ honpre:'',
+ honsuf:'',
+ data:undefined,
update:function(params) { // params {cid:int, aid:int}
if(!params) { params = {}; }
$('#contacts li,#contacts h3').removeClass('active');
@@ -578,12 +584,8 @@ Contacts={
$(this).find('input').val('');
}
});
-
- with(this) {
- delete fn; delete fullname; delete givname; delete famname;
- delete addname; delete honpre; delete honsuf;
- }
-
+ this.fn = ''; this.fullname = ''; this.givname = ''; this.famname = ''; this.addname = ''; this.honpre = ''; this.honsuf = '';
+ var narray = undefined;
if(this.data.FN) {
this.fn = this.data.FN[0]['value'];
}
@@ -1208,17 +1210,28 @@ Contacts={
$('#phototools li a').tipsy('hide');
var wrapper = $('#contacts_details_photo_wrapper');
wrapper.addClass('loading').addClass('wait');
- delete this.photo;
- this.photo = new Image();
- $(this.photo).load(function () {
+
+ var img = new Image();
+ $(img).load(function () {
$('img.contacts_details_photo').remove()
- $(this).addClass('contacts_details_photo');
+ $(this).addClass('contacts_details_photo').hide();
wrapper.removeClass('loading').removeClass('wait');
- $(this).insertAfter($('#phototools')).fadeIn('fast');
+ $(this).insertAfter($('#phototools')).fadeIn();
}).error(function () {
// notify the user that the image could not be loaded
Contacts.UI.notify({message:t('contacts','Error loading profile picture.')});
}).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){
+ if(jsondata.status == 'success'){
+ $('#contacts_details_photo_wrapper').data('checksum', jsondata.data.checksum);
+ Contacts.UI.Card.loadPhotoHandlers();
+ }
+ else{
+ OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
+ }
+ });
+ $('#file_upload_form').show();
},
editCurrentPhoto:function(){
$.getJSON(OC.filePath('contacts', 'ajax', 'currentphoto.php'),{'id':this.id},function(jsondata){
@@ -1480,15 +1493,7 @@ Contacts={
}
},
Contacts:{
- contacts:{},
batchnum:50,
- get:function(id) {
- if(!this.contacts[id]) {
- // TODO: Check if item isn't loaded yet. If so insert it.
- this.contacts[id] = $('#contacts li[data-id="'+id+'"]');
- }
- return this.contacts[id];
- },
drop:function(event, ui) {
var dragitem = ui.draggable, droptarget = $(this);
if(dragitem.is('li')) {
@@ -1527,16 +1532,13 @@ Contacts={
* If 'contactlist' or 'contacts' aren't defined they will be search for based in the properties in 'data'.
*/
insertContact:function(params) {
- var id, bookid;
if(!params.contactlist) {
// FIXME: Check if contact really exists.
- bookid = params.data ? params.data.addressbookid : params.contact.data('bookid');
- id = params.data ? params.data.id : params.contact.data('id');
+ var bookid = params.data ? params.data.addressbookid : params.contact.data('bookid');
params.contactlist = $('#contacts ul[data-id="'+bookid+'"]');
}
if(!params.contacts) {
- bookid = params.data ? params.data.addressbookid : params.contact.data('bookid');
- id = params.data ? params.data.id : params.contact.data('id');
+ var bookid = params.data ? params.data.addressbookid : params.contact.data('bookid');
params.contacts = $('#contacts ul[data-id="'+bookid+'"] li');
}
var contact = params.data
@@ -1556,7 +1558,6 @@ Contacts={
if(!added || !params.contacts) {
params.contactlist.append(contact);
}
- //this.contacts[id] = contact;
return contact;
},
next:function(reverse) {
@@ -1691,13 +1692,18 @@ $(document).ready(function(){
OCCategories.changed = Contacts.UI.Card.categoriesChanged;
OCCategories.app = 'contacts';
- $('#chooseaddressbook').on('click keydown', Contacts.UI.Addressbooks.overview);
- $('#contacts_newcontact').on('click keydown', Contacts.UI.Card.editNew);
+ $('#notification').click(function(){
+ $('#notification').fadeOut();
+ });
+
+ $('#chooseaddressbook').click(Contacts.UI.Addressbooks.overview);
+ $('#chooseaddressbook').keydown(Contacts.UI.Addressbooks.overview);
- var ninjahelp = $('#ninjahelp');
+ $('#contacts_newcontact').click(Contacts.UI.Card.editNew);
+ $('#contacts_newcontact').keydown(Contacts.UI.Card.editNew);
- ninjahelp.find('.close').on('click keydown',function() {
- ninjahelp.hide();
+ $('#ninjahelp .close').on('click keydown',function() {
+ $('#ninjahelp').hide();
});
$(document).on('keyup', function(event) {
@@ -1715,7 +1721,7 @@ $(document).ready(function(){
*/
switch(event.which) {
case 27: // Esc
- ninjahelp.hide();
+ $('#ninjahelp').hide();
break;
case 46:
if(event.shiftKey) {
@@ -1762,7 +1768,7 @@ $(document).ready(function(){
Contacts.UI.Contacts.update({cid:Contacts.UI.Card.id});
break;
case 191: // ?
- ninjahelp.toggle('fast');
+ $('#ninjahelp').toggle('fast');
break;
}
@@ -1774,7 +1780,7 @@ $(document).ready(function(){
$('.contacts').click();
}
});
- $(document).on('click', '#contacts', function(event){
+ $(document).on('click', '.contacts', function(event){
var $tgt = $(event.target);
if ($tgt.is('li') || $tgt.is('a')) {
var item = $tgt.is('li')?$($tgt):($tgt).parent();