2012-12-17 22:43:24 +01:00
|
|
|
Modernizr.load({
|
2013-01-02 02:22:16 +01:00
|
|
|
test: Modernizr.input.placeholder,
|
|
|
|
nope: [
|
|
|
|
OC.filePath('contacts', 'css', 'placeholder_polyfill.min.css'),
|
|
|
|
OC.filePath('contacts', 'js', 'placeholder_polyfill.jquery.min.combo.js')
|
|
|
|
]
|
2012-12-17 22:43:24 +01:00
|
|
|
});
|
|
|
|
|
2013-01-25 14:30:53 +01:00
|
|
|
(function($) {
|
|
|
|
$.QueryString = (function(a) {
|
2014-03-08 09:03:28 +01:00
|
|
|
if (a === '') {return {};}
|
2013-01-25 14:30:53 +01:00
|
|
|
var b = {};
|
|
|
|
for (var i = 0; i < a.length; ++i)
|
|
|
|
{
|
|
|
|
var p=a[i].split('=');
|
2014-03-08 16:22:51 +01:00
|
|
|
if (p.length !== 2) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-03-08 09:03:28 +01:00
|
|
|
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, ' '));
|
2013-01-25 14:30:53 +01:00
|
|
|
}
|
|
|
|
return b;
|
2014-03-08 09:03:28 +01:00
|
|
|
})(window.location.search.substr(1).split('&'));
|
2013-01-25 14:30:53 +01:00
|
|
|
})(jQuery);
|
|
|
|
|
2012-11-01 15:31:58 +01:00
|
|
|
var utils = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* utils.isArray
|
|
|
|
*
|
|
|
|
* Best guess if object is an array.
|
|
|
|
*/
|
|
|
|
utils.isArray = function(obj) {
|
|
|
|
// do an instanceof check first
|
|
|
|
if (obj instanceof Array) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// then check for obvious falses
|
|
|
|
if (typeof obj !== 'object') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (utils.type(obj) === 'array') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-11-15 00:28:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
utils.isInt = function(s) {
|
|
|
|
return typeof s === 'number' && (s.toString().search(/^-?[0-9]+$/) === 0);
|
2012-12-17 15:19:22 +01:00
|
|
|
};
|
2012-11-15 00:28:43 +01:00
|
|
|
|
|
|
|
utils.isUInt = function(s) {
|
|
|
|
return typeof s === 'number' && (s.toString().search(/^[0-9]+$/) === 0);
|
2012-12-17 15:19:22 +01:00
|
|
|
};
|
2012-11-01 15:31:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* utils.type
|
|
|
|
*
|
|
|
|
* Attempt to ascertain actual object type.
|
|
|
|
*/
|
|
|
|
utils.type = function(obj) {
|
|
|
|
if (obj === null || typeof obj === 'undefined') {
|
|
|
|
return String (obj);
|
|
|
|
}
|
|
|
|
return Object.prototype.toString.call(obj)
|
|
|
|
.replace(/\[object ([a-zA-Z]+)\]/, '$1').toLowerCase();
|
|
|
|
};
|
|
|
|
|
|
|
|
utils.moveCursorToEnd = function(el) {
|
2012-11-22 08:17:57 +01:00
|
|
|
if (typeof el.selectionStart === 'number') {
|
2012-11-01 15:31:58 +01:00
|
|
|
el.selectionStart = el.selectionEnd = el.value.length;
|
2012-11-22 08:17:57 +01:00
|
|
|
} else if (typeof el.createTextRange !== 'undefined') {
|
2012-11-01 15:31:58 +01:00
|
|
|
el.focus();
|
|
|
|
var range = el.createTextRange();
|
|
|
|
range.collapse(false);
|
|
|
|
range.select();
|
|
|
|
}
|
2012-12-17 15:19:22 +01:00
|
|
|
};
|
2012-11-01 15:31:58 +01:00
|
|
|
|
2012-11-22 00:24:31 +01:00
|
|
|
Array.prototype.clone = function() {
|
|
|
|
return this.slice(0);
|
|
|
|
};
|
|
|
|
|
2012-09-17 16:15:31 +02:00
|
|
|
Array.prototype.clean = function(deleteValue) {
|
2012-11-22 00:24:31 +01:00
|
|
|
var arr = this.clone();
|
|
|
|
for (var i = 0; i < arr.length; i++) {
|
2014-03-08 09:03:28 +01:00
|
|
|
if (arr[i] === deleteValue) {
|
2012-11-22 00:24:31 +01:00
|
|
|
arr.splice(i, 1);
|
2012-09-17 16:15:31 +02:00
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
2012-11-22 00:24:31 +01:00
|
|
|
return arr;
|
2012-09-17 16:15:31 +02:00
|
|
|
};
|
|
|
|
|
2012-10-05 05:05:49 +02:00
|
|
|
// Keep it DRY ;)
|
|
|
|
var wrongKey = function(event) {
|
2012-12-17 21:03:10 +01:00
|
|
|
return ((event.type === 'keydown' || event.type === 'keypress')
|
|
|
|
&& (event.keyCode !== 32 && event.keyCode !== 13));
|
2012-12-17 15:19:22 +01:00
|
|
|
};
|
2012-10-05 05:05:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Simply notifier
|
|
|
|
* Arguments:
|
2013-09-03 14:04:18 +02:00
|
|
|
* @param string message - The text message to show.
|
|
|
|
* @param int timeout - The timeout in seconds before the notification disappears. Default 10.
|
|
|
|
* @param function timeouthandler - A function to run on timeout.
|
|
|
|
* @param function clickhandler - A function to run on click. If a timeouthandler is given it will be cancelled on click.
|
|
|
|
* @param object data - An object that will be passed as argument to the timeouthandler and clickhandler functions.
|
|
|
|
* @param bool cancel - If set cancel all ongoing timer events and hide the notification.
|
2012-10-05 05:05:49 +02:00
|
|
|
*/
|
|
|
|
OC.notify = function(params) {
|
|
|
|
var self = this;
|
|
|
|
if(!self.notifier) {
|
|
|
|
self.notifier = $('#notification');
|
2013-09-03 14:04:18 +02:00
|
|
|
self.notifier.on('click', function() { $(this).fadeOut();});
|
2012-10-05 05:05:49 +02:00
|
|
|
}
|
|
|
|
if(params.cancel) {
|
|
|
|
self.notifier.off('click');
|
|
|
|
for(var id in self.notifier.data()) {
|
|
|
|
if($.isNumeric(id)) {
|
|
|
|
clearTimeout(parseInt(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.notifier.text('').fadeOut().removeData();
|
|
|
|
}
|
2013-09-03 14:04:18 +02:00
|
|
|
if(params.message) {
|
|
|
|
self.notifier.text(params.message).fadeIn().css('display', 'inline');
|
|
|
|
}
|
|
|
|
|
2012-10-05 05:05:49 +02:00
|
|
|
var timer = setTimeout(function() {
|
|
|
|
self.notifier.fadeOut();
|
|
|
|
if(params.timeouthandler && $.isFunction(params.timeouthandler)) {
|
|
|
|
params.timeouthandler(self.notifier.data(dataid));
|
|
|
|
self.notifier.off('click');
|
|
|
|
self.notifier.removeData(dataid);
|
|
|
|
}
|
|
|
|
}, params.timeout && $.isNumeric(params.timeout) ? parseInt(params.timeout)*1000 : 10000);
|
|
|
|
var dataid = timer.toString();
|
|
|
|
if(params.data) {
|
|
|
|
self.notifier.data(dataid, params.data);
|
|
|
|
}
|
|
|
|
if(params.clickhandler && $.isFunction(params.clickhandler)) {
|
|
|
|
self.notifier.on('click', function() {
|
|
|
|
clearTimeout(timer);
|
|
|
|
self.notifier.off('click');
|
|
|
|
params.clickhandler(self.notifier.data(dataid));
|
|
|
|
self.notifier.removeData(dataid);
|
|
|
|
});
|
|
|
|
}
|
2012-12-17 15:19:22 +01:00
|
|
|
};
|
2012-10-05 05:05:49 +02:00
|
|
|
|
2012-10-15 21:33:21 +02:00
|
|
|
|
2012-09-17 16:15:31 +02:00
|
|
|
OC.Contacts = OC.Contacts || {
|
2013-01-25 14:30:53 +01:00
|
|
|
init:function() {
|
2012-11-22 00:25:40 +01:00
|
|
|
if(oc_debug === true) {
|
2013-05-18 04:56:59 +02:00
|
|
|
$.error = console.error;
|
2012-11-22 00:25:40 +01:00
|
|
|
}
|
2013-05-02 20:41:26 +02:00
|
|
|
var self = this;
|
2013-01-25 14:30:53 +01:00
|
|
|
|
2013-09-15 19:04:19 +02:00
|
|
|
this.lastSelectedContacts = [];
|
2012-09-17 16:15:31 +02:00
|
|
|
this.scrollTimeoutMiliSecs = 100;
|
|
|
|
this.isScrolling = false;
|
|
|
|
this.cacheElements();
|
2013-03-22 14:54:47 +01:00
|
|
|
this.storage = new OC.Contacts.Storage();
|
2013-05-02 20:41:26 +02:00
|
|
|
this.addressBooks = new OC.Contacts.AddressBookList(
|
|
|
|
this.storage,
|
|
|
|
$('#app-settings-content'),
|
2013-05-24 17:43:01 +02:00
|
|
|
$('#addressBookTemplate')
|
2013-05-02 20:41:26 +02:00
|
|
|
);
|
2012-12-13 02:30:20 +01:00
|
|
|
this.contacts = new OC.Contacts.ContactList(
|
2013-03-22 14:54:47 +01:00
|
|
|
this.storage,
|
2013-05-02 20:41:26 +02:00
|
|
|
this.addressBooks,
|
2012-10-22 15:35:33 +02:00
|
|
|
this.$contactList,
|
|
|
|
this.$contactListItemTemplate,
|
2013-03-12 00:28:41 +01:00
|
|
|
this.$contactDragItemTemplate,
|
2012-09-17 16:15:31 +02:00
|
|
|
this.$contactFullTemplate,
|
|
|
|
this.detailTemplates
|
|
|
|
);
|
2013-05-02 20:41:26 +02:00
|
|
|
this.groups = new OC.Contacts.GroupList(
|
|
|
|
this.storage,
|
|
|
|
this.$groupList,
|
|
|
|
this.$groupListItemTemplate
|
|
|
|
);
|
2013-05-08 06:47:36 +02:00
|
|
|
self.groups.loadGroups(function() {
|
2013-05-11 01:41:24 +02:00
|
|
|
self.loading(self.$navigation, false);
|
2013-05-08 06:47:36 +02:00
|
|
|
});
|
2013-06-01 00:42:46 +02:00
|
|
|
// Hide the list while populating it.
|
|
|
|
this.$contactList.hide();
|
2013-05-08 06:47:36 +02:00
|
|
|
$.when(this.addressBooks.loadAddressBooks()).then(function(addressBooks) {
|
2014-03-08 09:03:28 +01:00
|
|
|
var deferreds = $(addressBooks).map(function(/*i, elem*/) {
|
2013-09-05 22:07:40 +02:00
|
|
|
return self.contacts.loadContacts(this.getBackend(), this.getId(), this.isActive());
|
2013-05-08 06:47:36 +02:00
|
|
|
});
|
|
|
|
// This little beauty is from http://stackoverflow.com/a/6162959/373007 ;)
|
2014-03-08 09:03:28 +01:00
|
|
|
$.when.apply(null, deferreds.get()).then(function() {
|
2013-05-22 21:44:39 +02:00
|
|
|
self.contacts.setSortOrder(contacts_sortby);
|
2013-06-01 00:42:46 +02:00
|
|
|
self.$contactList.show();
|
2013-05-08 06:47:36 +02:00
|
|
|
$(document).trigger('status.contacts.loaded', {
|
|
|
|
numcontacts: self.contacts.length
|
2013-05-02 20:41:26 +02:00
|
|
|
});
|
2013-05-08 06:47:36 +02:00
|
|
|
self.loading(self.$rightContent, false);
|
|
|
|
// TODO: Move this to event handler
|
|
|
|
self.groups.selectGroup({id:contacts_lastgroup});
|
2014-03-08 09:03:28 +01:00
|
|
|
var id = $.QueryString.id; // Keep for backwards compatible links.
|
2013-05-09 21:18:32 +02:00
|
|
|
if(!id) {
|
|
|
|
id = window.location.hash.substr(1);
|
2013-05-08 06:47:36 +02:00
|
|
|
}
|
2013-05-09 21:18:32 +02:00
|
|
|
console.log('Groups loaded, id from url:', id);
|
|
|
|
if(id) {
|
|
|
|
self.openContact(id);
|
2013-05-08 06:47:36 +02:00
|
|
|
}
|
|
|
|
if(!contacts_properties_indexed) {
|
|
|
|
// Wait a couple of mins then check if contacts are indexed.
|
|
|
|
setTimeout(function() {
|
2014-03-02 23:19:01 +01:00
|
|
|
$.when($.post(OC.generateUrl('apps/contacts/indexproperties/{user}/')))
|
2013-05-08 06:47:36 +02:00
|
|
|
.then(function(response) {
|
|
|
|
if(!response.isIndexed) {
|
|
|
|
OC.notify({message:t('contacts', 'Indexing contacts'), timeout:20});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 10000);
|
|
|
|
} else {
|
|
|
|
console.log('contacts are indexed.');
|
|
|
|
}
|
|
|
|
}).fail(function(response) {
|
|
|
|
console.warn(response);
|
2013-05-18 05:45:48 +02:00
|
|
|
self.$rightContent.removeClass('loading');
|
|
|
|
message = t('contacts', 'Unrecoverable error loading address books: {msg}', {msg:response.message});
|
|
|
|
OC.dialogs.alert(message, t('contacts', 'Error.'));
|
2013-05-08 06:47:36 +02:00
|
|
|
});
|
|
|
|
}).fail(function(response) {
|
|
|
|
console.log(response.message);
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', response);
|
2013-05-02 20:41:26 +02:00
|
|
|
});
|
2014-03-08 09:03:28 +01:00
|
|
|
$(OC.Tags).on('change', this.groups.categoriesChanged);
|
2012-09-17 16:15:31 +02:00
|
|
|
this.bindEvents();
|
2012-10-05 05:05:49 +02:00
|
|
|
this.$toggleAll.show();
|
2013-04-30 20:00:33 +02:00
|
|
|
this.hideActions();
|
2013-12-09 22:44:57 +01:00
|
|
|
$('.hidden-on-load').removeClass('hidden-on-load');
|
2012-09-17 16:15:31 +02:00
|
|
|
},
|
|
|
|
loading:function(obj, state) {
|
2012-10-24 20:31:29 +02:00
|
|
|
$(obj).toggleClass('loading', state);
|
2012-09-17 16:15:31 +02:00
|
|
|
},
|
2012-10-05 05:05:49 +02:00
|
|
|
/**
|
|
|
|
* Show/hide elements in the header
|
|
|
|
* @param act An array of actions to show based on class name e.g ['add', 'delete']
|
|
|
|
*/
|
2012-11-13 17:01:14 +01:00
|
|
|
hideActions:function() {
|
|
|
|
this.showActions(false);
|
|
|
|
},
|
2012-10-05 05:05:49 +02:00
|
|
|
showActions:function(act) {
|
2012-12-13 02:38:58 +01:00
|
|
|
console.log('showActions', act);
|
|
|
|
//console.trace();
|
2012-10-05 05:05:49 +02:00
|
|
|
this.$headeractions.children().hide();
|
2012-11-13 17:01:14 +01:00
|
|
|
if(act && act.length > 0) {
|
2013-04-30 20:00:33 +02:00
|
|
|
this.$contactList.addClass('multiselect');
|
2013-12-18 15:35:41 +01:00
|
|
|
this.$contactListHeader.find('.actions').css('display', '');
|
2014-02-17 22:38:32 +01:00
|
|
|
this.$contactListHeader.find('.action').css('display', 'none');
|
2014-02-06 03:31:39 +01:00
|
|
|
this.$contactListHeader.find('.name').attr('colspan', '5');
|
2013-12-18 15:35:41 +01:00
|
|
|
this.$contactListHeader.find('.info').css('display', 'none');
|
2014-02-17 22:38:32 +01:00
|
|
|
this.$contactListHeader.find('.'+act.join(',.')).css('display', '');
|
2013-04-30 20:00:33 +02:00
|
|
|
} else {
|
2013-12-18 15:35:41 +01:00
|
|
|
this.$contactListHeader.find('.actions').css('display', 'none');
|
|
|
|
this.$contactListHeader.find('.name').attr('colspan', '1');
|
|
|
|
this.$contactListHeader.find('.info').css('display', '');
|
2013-04-30 20:00:33 +02:00
|
|
|
this.$contactList.removeClass('multiselect');
|
2012-11-13 17:01:14 +01:00
|
|
|
}
|
2012-10-05 05:05:49 +02:00
|
|
|
},
|
|
|
|
showAction:function(act, show) {
|
2014-02-17 22:38:32 +01:00
|
|
|
this.$contactListHeader.find('.' + act).toggle(show);
|
2012-10-05 05:05:49 +02:00
|
|
|
},
|
2012-09-17 16:15:31 +02:00
|
|
|
cacheElements: function() {
|
|
|
|
var self = this;
|
|
|
|
this.detailTemplates = {};
|
|
|
|
// Load templates for contact details.
|
|
|
|
// The weird double loading is because jquery apparently doesn't
|
|
|
|
// create a searchable object from a script element.
|
|
|
|
$.each($($('#contactDetailsTemplate').html()), function(idx, node) {
|
2012-12-20 22:58:04 +01:00
|
|
|
var $node = $(node);
|
|
|
|
if($node.is('div')) {
|
2012-09-17 16:15:31 +02:00
|
|
|
var $tmpl = $(node.innerHTML);
|
2012-12-20 22:58:04 +01:00
|
|
|
self.detailTemplates[$tmpl.data('element')] = $node;
|
2012-09-17 16:15:31 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.$groupListItemTemplate = $('#groupListItemTemplate');
|
|
|
|
this.$contactListItemTemplate = $('#contactListItemTemplate');
|
2013-03-12 00:28:41 +01:00
|
|
|
this.$contactDragItemTemplate = $('#contactDragItemTemplate');
|
2012-09-17 16:15:31 +02:00
|
|
|
this.$contactFullTemplate = $('#contactFullTemplate');
|
|
|
|
this.$contactDetailsTemplate = $('#contactDetailsTemplate');
|
2013-04-30 20:00:33 +02:00
|
|
|
this.$rightContent = $('#app-content');
|
|
|
|
this.$navigation = $('#app-navigation');
|
|
|
|
//this.$header = $('#contactsheader');
|
2012-09-17 16:15:31 +02:00
|
|
|
this.$groupList = $('#grouplist');
|
|
|
|
this.$contactList = $('#contactlist');
|
2013-04-30 20:00:33 +02:00
|
|
|
this.$contactListHeader = $('#contactsHeader');
|
2013-05-22 21:44:39 +02:00
|
|
|
this.$sortOrder = this.$contactListHeader.find('.action.sort');
|
|
|
|
this.$sortOrder.val(contacts_sortby||'fn');
|
2013-12-18 16:59:39 +01:00
|
|
|
this.$headeractions = this.$groupList.find('.contact-actions');
|
2013-04-30 20:00:33 +02:00
|
|
|
this.$toggleAll = this.$contactListHeader.find('.toggle');
|
2013-12-18 15:35:41 +01:00
|
|
|
this.$groups = this.$contactListHeader.find('.groups');
|
2012-10-05 05:05:49 +02:00
|
|
|
this.$ninjahelp = $('#ninjahelp');
|
2012-11-15 02:40:47 +01:00
|
|
|
this.$firstRun = $('#firstrun');
|
2013-04-30 20:00:33 +02:00
|
|
|
this.$settings = $('#app-settings');
|
2012-10-05 05:05:49 +02:00
|
|
|
},
|
|
|
|
// Build the select to add/remove from groups.
|
|
|
|
buildGroupSelect: function() {
|
2012-10-24 20:31:29 +02:00
|
|
|
// If a contact is open we know which categories it's in
|
2012-10-05 05:05:49 +02:00
|
|
|
if(this.currentid) {
|
2013-02-03 15:40:14 +01:00
|
|
|
var contact = this.contacts.findById(this.currentid);
|
|
|
|
if(contact === null) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-10-05 05:05:49 +02:00
|
|
|
this.$groups.find('optgroup,option:not([value="-1"])').remove();
|
|
|
|
var addopts = '', rmopts = '';
|
2012-12-13 02:30:20 +01:00
|
|
|
$.each(this.groups.categories, function(i, category) {
|
2012-10-05 05:05:49 +02:00
|
|
|
if(contact.inGroup(category.name)) {
|
|
|
|
rmopts += '<option value="' + category.id + '">' + category.name + '</option>';
|
|
|
|
} else {
|
|
|
|
addopts += '<option value="' + category.id + '">' + category.name + '</option>';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if(addopts.length) {
|
|
|
|
$(addopts).appendTo(this.$groups)
|
|
|
|
.wrapAll('<optgroup data-action="add" label="' + t('contacts', 'Add to...') + '"/>');
|
|
|
|
}
|
|
|
|
if(rmopts.length) {
|
|
|
|
$(rmopts).appendTo(this.$groups)
|
|
|
|
.wrapAll('<optgroup data-action="remove" label="' + t('contacts', 'Remove from...') + '"/>');
|
|
|
|
}
|
2012-12-13 02:30:20 +01:00
|
|
|
} else if(this.contacts.getSelectedContacts().length > 0) { // Otherwise add all categories to both add and remove
|
2012-10-05 05:05:49 +02:00
|
|
|
this.$groups.find('optgroup,option:not([value="-1"])').remove();
|
|
|
|
var addopts = '', rmopts = '';
|
2012-12-13 02:30:20 +01:00
|
|
|
$.each(this.groups.categories, function(i, category) {
|
2012-10-05 05:05:49 +02:00
|
|
|
rmopts += '<option value="' + category.id + '">' + category.name + '</option>';
|
|
|
|
addopts += '<option value="' + category.id + '">' + category.name + '</option>';
|
|
|
|
});
|
|
|
|
$(addopts).appendTo(this.$groups)
|
|
|
|
.wrapAll('<optgroup data-action="add" label="' + t('contacts', 'Add to...') + '"/>');
|
|
|
|
$(rmopts).appendTo(this.$groups)
|
|
|
|
.wrapAll('<optgroup data-action="remove" label="' + t('contacts', 'Remove from...') + '"/>');
|
2012-11-05 12:39:49 +01:00
|
|
|
} else {
|
|
|
|
// 3rd option: No contact open, none checked, just show "Add group..."
|
|
|
|
this.$groups.find('optgroup,option:not([value="-1"])').remove();
|
2012-10-05 05:05:49 +02:00
|
|
|
}
|
|
|
|
$('<option value="add">' + t('contacts', 'Add group...') + '</option>').appendTo(this.$groups);
|
|
|
|
this.$groups.val(-1);
|
2012-09-17 16:15:31 +02:00
|
|
|
},
|
|
|
|
bindEvents: function() {
|
|
|
|
var self = this;
|
2012-10-22 15:35:33 +02:00
|
|
|
|
2012-11-05 20:45:08 +01:00
|
|
|
// Should fix Opera check for delayed delete.
|
|
|
|
$(window).unload(function (){
|
|
|
|
$(window).trigger('beforeunload');
|
|
|
|
});
|
|
|
|
|
2013-02-23 22:27:04 +01:00
|
|
|
this.hashChange = function() {
|
2014-03-08 09:03:28 +01:00
|
|
|
console.log('hashchange', window.location.hash);
|
2013-05-09 05:53:46 +02:00
|
|
|
var id = String(window.location.hash.substr(1));
|
2014-03-08 09:03:28 +01:00
|
|
|
if(id && id !== self.currentid && self.contacts.findById(id) !== null) {
|
2013-01-25 18:59:28 +01:00
|
|
|
self.openContact(id);
|
2013-02-23 22:51:28 +01:00
|
|
|
} else if(!id && self.currentid) {
|
|
|
|
self.closeContact(self.currentid);
|
2013-01-25 18:59:28 +01:00
|
|
|
}
|
2014-03-08 09:03:28 +01:00
|
|
|
};
|
2013-02-23 22:27:04 +01:00
|
|
|
|
2013-05-09 05:54:17 +02:00
|
|
|
// This apparently get's called on some weird occasions.
|
2013-10-29 21:08:35 +01:00
|
|
|
//$(window).bind('popstate', this.hashChange);
|
2013-02-23 22:27:04 +01:00
|
|
|
$(window).bind('hashchange', this.hashChange);
|
2013-01-25 18:59:28 +01:00
|
|
|
|
2012-10-05 05:05:49 +02:00
|
|
|
// App specific events
|
2012-09-17 16:15:31 +02:00
|
|
|
$(document).bind('status.contact.deleted', function(e, data) {
|
2013-05-09 21:18:32 +02:00
|
|
|
var id = String(data.id);
|
2014-03-08 09:03:28 +01:00
|
|
|
if(id === self.currentid) {
|
2013-02-20 13:14:31 +01:00
|
|
|
delete self.currentid;
|
|
|
|
}
|
2012-09-17 16:15:31 +02:00
|
|
|
console.log('contact', data.id, 'deleted');
|
2012-10-05 05:05:49 +02:00
|
|
|
// update counts on group lists
|
2013-09-03 14:08:12 +02:00
|
|
|
self.groups.removeFromAll(data.id, true, true);
|
2012-10-05 05:05:49 +02:00
|
|
|
});
|
2012-11-13 22:42:55 +01:00
|
|
|
|
|
|
|
$(document).bind('status.contact.added', function(e, data) {
|
2013-05-09 21:18:32 +02:00
|
|
|
self.currentid = String(data.id);
|
2012-11-15 20:35:35 +01:00
|
|
|
self.buildGroupSelect();
|
2012-12-11 06:18:57 +01:00
|
|
|
self.hideActions();
|
2012-11-13 22:42:55 +01:00
|
|
|
});
|
|
|
|
|
2013-03-25 17:08:47 +01:00
|
|
|
// Keep error messaging at one place to be able to replace it.
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).bind('status.contacts.error', function(e, data) {
|
2014-02-19 00:49:19 +01:00
|
|
|
var message = data.message;
|
2013-09-27 16:38:22 +02:00
|
|
|
console.warn(message);
|
2013-05-02 20:41:26 +02:00
|
|
|
//console.trace();
|
2013-09-27 16:38:22 +02:00
|
|
|
OC.notify({message:message});
|
2012-09-17 16:15:31 +02:00
|
|
|
});
|
2012-11-13 22:42:55 +01:00
|
|
|
|
2012-09-17 16:15:31 +02:00
|
|
|
$(document).bind('status.contact.enabled', function(e, enabled) {
|
2012-12-17 15:19:22 +01:00
|
|
|
console.log('status.contact.enabled', enabled);
|
2012-12-11 06:18:57 +01:00
|
|
|
/*if(enabled) {
|
2012-12-10 00:02:06 +01:00
|
|
|
self.showActions(['back', 'download', 'delete', 'groups']);
|
2012-09-17 16:15:31 +02:00
|
|
|
} else {
|
2012-10-05 05:05:49 +02:00
|
|
|
self.showActions(['back']);
|
2012-12-11 06:18:57 +01:00
|
|
|
}*/
|
2012-09-17 16:15:31 +02:00
|
|
|
});
|
2012-11-13 22:42:55 +01:00
|
|
|
|
2013-05-24 03:33:20 +02:00
|
|
|
$(document).bind('status.contacts.count', function(e, response) {
|
|
|
|
console.log('Num contacts:', response.count);
|
|
|
|
if(response.count > 0) {
|
|
|
|
self.$contactList.show();
|
|
|
|
self.$firstRun.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-08-03 14:48:46 +02:00
|
|
|
$(document).bind('status.contacts.loaded status.contacts.deleted', function(e, response) {
|
2013-05-08 06:47:36 +02:00
|
|
|
console.log('status.contacts.loaded', response);
|
|
|
|
if(response.error) {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', response);
|
2013-05-08 06:47:36 +02:00
|
|
|
console.log('Error loading contacts!');
|
2013-05-24 03:33:20 +02:00
|
|
|
} else {
|
|
|
|
if(response.numcontacts === 0) {
|
|
|
|
self.$contactList.hide();
|
|
|
|
self.$firstRun.show();
|
|
|
|
} else {
|
|
|
|
self.$contactList.show();
|
|
|
|
self.$firstRun.hide();
|
2013-09-05 22:07:40 +02:00
|
|
|
$.each(self.addressBooks.addressBooks, function(idx, addressBook) {
|
|
|
|
console.log('addressBook', addressBook);
|
|
|
|
if(!addressBook.isActive()) {
|
|
|
|
self.contacts.showFromAddressbook(addressBook.getId(), false);
|
|
|
|
}
|
|
|
|
});
|
2013-05-24 03:33:20 +02:00
|
|
|
}
|
2012-09-17 16:15:31 +02:00
|
|
|
}
|
2012-10-05 05:05:49 +02:00
|
|
|
});
|
2012-11-13 22:42:55 +01:00
|
|
|
|
2012-10-05 05:05:49 +02:00
|
|
|
$(document).bind('status.contact.currentlistitem', function(e, result) {
|
|
|
|
//console.log('status.contact.currentlistitem', result, self.$rightContent.height());
|
|
|
|
if(self.dontScroll !== true) {
|
|
|
|
if(result.pos > self.$rightContent.height()) {
|
|
|
|
self.$rightContent.scrollTop(result.pos - self.$rightContent.height() + result.height);
|
|
|
|
}
|
|
|
|
else if(result.pos < self.$rightContent.offset().top) {
|
|
|
|
self.$rightContent.scrollTop(result.pos);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setTimeout(function() {
|
|
|
|
self.dontScroll = false;
|
|
|
|
}, 100);
|
|
|
|
}
|
2012-12-17 15:19:22 +01:00
|
|
|
self.currentlistid = result.id;
|
2012-10-05 05:05:49 +02:00
|
|
|
});
|
2012-11-23 01:16:46 +01:00
|
|
|
|
2012-10-05 05:05:49 +02:00
|
|
|
$(document).bind('status.nomorecontacts', function(e, result) {
|
|
|
|
console.log('status.nomorecontacts', result);
|
2012-11-15 02:40:47 +01:00
|
|
|
self.$contactList.hide();
|
|
|
|
self.$firstRun.show();
|
2012-10-05 05:05:49 +02:00
|
|
|
});
|
2012-11-23 01:16:46 +01:00
|
|
|
|
2012-10-05 05:05:49 +02:00
|
|
|
$(document).bind('status.visiblecontacts', function(e, result) {
|
|
|
|
console.log('status.visiblecontacts', result);
|
|
|
|
// TODO: To be decided.
|
|
|
|
});
|
2012-11-23 01:16:46 +01:00
|
|
|
|
2013-05-24 15:30:59 +02:00
|
|
|
$(document).bind('request.openurl', function(e, data) {
|
|
|
|
switch(data.type) {
|
|
|
|
case 'url':
|
|
|
|
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!-\/]))?/;
|
|
|
|
//if(new RegExp("[a-zA-Z0-9]+://([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?").test(data.url)) {
|
|
|
|
if(regexp.test(data.url)) {
|
|
|
|
var newWindow = window.open(data.url,'_blank');
|
|
|
|
newWindow.focus();
|
|
|
|
} else {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', {
|
|
|
|
error: true,
|
2013-05-24 15:30:59 +02:00
|
|
|
message: t('contacts', 'Invalid URL: "{url}"', {url:data.url})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'email':
|
|
|
|
var regexp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
|
|
|
|
if(regexp.test(data.url)) {
|
|
|
|
console.log('success');
|
|
|
|
try {
|
|
|
|
window.location = 'mailto:' + data.url;
|
|
|
|
} catch(e) {
|
|
|
|
alert(t('contacts', 'There was an error opening a mail composer.'));
|
|
|
|
}
|
|
|
|
} else {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', {
|
|
|
|
error: true,
|
2013-05-24 15:30:59 +02:00
|
|
|
message: t('contacts', 'Invalid email: "{url}"', {url:data.url})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
2014-01-24 14:06:43 +01:00
|
|
|
case 'adr':
|
2014-03-08 09:03:28 +01:00
|
|
|
address = data.url.filter(function(n) {
|
|
|
|
return n;
|
|
|
|
});
|
2014-01-24 14:06:43 +01:00
|
|
|
var newWindow = window.open('http://open.mapquest.com/?q='+address, '_blank');
|
|
|
|
newWindow.focus();
|
|
|
|
break;
|
2013-05-24 15:30:59 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-10-05 05:05:49 +02:00
|
|
|
// A contact id was in the request
|
|
|
|
$(document).bind('request.loadcontact', function(e, result) {
|
|
|
|
console.log('request.loadcontact', result);
|
|
|
|
if(self.numcontacts) {
|
|
|
|
self.openContact(result.id);
|
|
|
|
} else {
|
|
|
|
// Contacts are not loaded yet, try again.
|
|
|
|
console.log('waiting for contacts to load');
|
|
|
|
setTimeout(function() {
|
|
|
|
$(document).trigger('request.loadcontact', {
|
2012-12-17 15:19:22 +01:00
|
|
|
id: result.id
|
2012-10-05 05:05:49 +02:00
|
|
|
});
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
});
|
2012-11-23 01:16:46 +01:00
|
|
|
|
2013-05-06 01:49:10 +02:00
|
|
|
$(document).bind('request.contact.move', function(e, data) {
|
|
|
|
console.log('contact', data, 'request.contact.move');
|
|
|
|
self.addressBooks.moveContact(data.contact, data.from, data.target);
|
|
|
|
});
|
|
|
|
|
2012-12-10 00:02:06 +01:00
|
|
|
$(document).bind('request.contact.setasfavorite', function(e, data) {
|
|
|
|
console.log('contact', data.id, 'request.contact.setasfavorite');
|
2012-12-13 02:30:20 +01:00
|
|
|
self.groups.setAsFavorite(data.id, data.state);
|
2012-12-10 00:02:06 +01:00
|
|
|
});
|
|
|
|
|
2012-12-14 02:53:06 +01:00
|
|
|
$(document).bind('request.contact.addtogroup', function(e, data) {
|
2013-01-16 13:34:30 +01:00
|
|
|
self.groups.addTo(data.id, data.groupid, function(response) {
|
|
|
|
console.log('contact', data.id, 'request.contact.addtogroup', response);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).bind('request.contact.removefromgroup', function(e, data) {
|
|
|
|
console.log('contact', data.id, 'request.contact.removefromgroup');
|
|
|
|
self.groups.removeFrom(data.id, data.groupid);
|
2012-12-14 02:53:06 +01:00
|
|
|
});
|
|
|
|
|
2012-12-11 04:05:34 +01:00
|
|
|
$(document).bind('request.contact.export', function(e, data) {
|
2013-05-24 20:35:23 +02:00
|
|
|
console.log('request.contact.export', data);
|
2014-03-02 23:19:01 +01:00
|
|
|
document.location.href = OC.generateUrl('apps/contacts/addressbook/{backend}/{addressBookId}/contact/{contactId}/export', data);
|
2012-12-11 04:05:34 +01:00
|
|
|
});
|
|
|
|
|
2012-12-10 00:02:06 +01:00
|
|
|
$(document).bind('request.contact.close', function(e, data) {
|
2013-04-03 16:54:25 +02:00
|
|
|
var id = String(data.id);
|
2012-12-10 00:02:06 +01:00
|
|
|
console.log('contact', data.id, 'request.contact.close');
|
|
|
|
self.closeContact(id);
|
|
|
|
});
|
|
|
|
|
2013-05-22 03:20:36 +02:00
|
|
|
$(document).bind('request.contact.open', function(e, data) {
|
|
|
|
var id = String(data.id);
|
|
|
|
console.log('contact', data.id, 'request.contact.open');
|
|
|
|
self.openContact(id);
|
|
|
|
});
|
|
|
|
|
2012-12-11 04:05:34 +01:00
|
|
|
$(document).bind('request.contact.delete', function(e, data) {
|
2013-12-10 19:08:32 +01:00
|
|
|
var id = String(data.contactId);
|
2013-03-28 03:19:01 +01:00
|
|
|
console.log('contact', data, 'request.contact.delete');
|
2013-02-20 13:14:31 +01:00
|
|
|
self.closeContact(id);
|
2013-03-28 03:19:01 +01:00
|
|
|
self.contacts.delayedDelete(data);
|
2012-12-11 04:05:34 +01:00
|
|
|
self.$contactList.removeClass('dim');
|
2013-04-30 20:00:33 +02:00
|
|
|
self.hideActions();
|
2012-12-11 04:05:34 +01:00
|
|
|
});
|
|
|
|
|
2013-04-03 16:43:18 +02:00
|
|
|
$(document).bind('request.contact.merge', function(e, data) {
|
|
|
|
console.log('contact','request.contact.merge', data);
|
|
|
|
var merger = self.contacts.findById(data.merger);
|
|
|
|
var mergees = [];
|
|
|
|
if(!merger) {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', {
|
2013-04-03 16:43:18 +02:00
|
|
|
message: t('contacts', 'Merge failed. Cannot find contact: {id}', {id:data.merger})
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$.each(data.mergees, function(idx, id) {
|
|
|
|
var contact = self.contacts.findById(id);
|
|
|
|
if(!contact) {
|
|
|
|
console.warn('cannot find', id, 'by id');
|
|
|
|
}
|
|
|
|
mergees.push(contact);
|
|
|
|
});
|
|
|
|
if(!merger.merge(mergees)) {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', {
|
2013-04-03 16:43:18 +02:00
|
|
|
message: t('contacts', 'Merge failed.')
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
merger.saveAll(function(response) {
|
|
|
|
if(response.error) {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', {
|
2013-04-03 16:43:18 +02:00
|
|
|
message: t('contacts', 'Merge failed. Error saving contact.')
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if(data.deleteOther) {
|
|
|
|
self.contacts.delayedDelete(mergees);
|
|
|
|
}
|
2013-10-17 02:10:34 +02:00
|
|
|
console.log('merger', merger);
|
2013-04-03 16:43:18 +02:00
|
|
|
self.openContact(merger.getId());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-04-05 04:10:32 +02:00
|
|
|
$(document).bind('request.select.contactphoto.fromlocal', function(e, metadata) {
|
|
|
|
console.log('request.select.contactphoto.fromlocal', metadata);
|
2013-04-08 22:35:28 +02:00
|
|
|
$('#contactphoto_fileupload').trigger('click', metadata);
|
2012-10-15 21:33:21 +02:00
|
|
|
});
|
2012-11-23 01:16:46 +01:00
|
|
|
|
2013-04-05 04:10:32 +02:00
|
|
|
$(document).bind('request.select.contactphoto.fromcloud', function(e, metadata) {
|
|
|
|
console.log('request.select.contactphoto.fromcloud', metadata);
|
2012-10-15 21:33:21 +02:00
|
|
|
OC.dialogs.filepicker(t('contacts', 'Select photo'), function(path) {
|
2013-04-05 04:10:32 +02:00
|
|
|
self.cloudPhotoSelected(metadata, path);
|
2012-10-15 21:33:21 +02:00
|
|
|
}, false, 'image', true);
|
|
|
|
});
|
2012-11-23 01:16:46 +01:00
|
|
|
|
2013-04-05 04:10:32 +02:00
|
|
|
$(document).bind('request.edit.contactphoto', function(e, metadata) {
|
|
|
|
console.log('request.edit.contactphoto', metadata);
|
|
|
|
self.editCurrentPhoto(metadata);
|
2012-10-15 21:33:21 +02:00
|
|
|
});
|
2012-11-23 01:16:46 +01:00
|
|
|
|
2013-05-08 06:47:36 +02:00
|
|
|
$(document).bind('request.groups.reload', function(e, result) {
|
|
|
|
console.log('request.groups.reload', result);
|
2013-05-10 02:15:24 +02:00
|
|
|
self.groups.loadGroups(function() {
|
|
|
|
self.groups.triggerLastGroup();
|
|
|
|
});
|
2013-05-08 06:47:36 +02:00
|
|
|
});
|
|
|
|
|
2012-11-23 01:16:46 +01:00
|
|
|
$(document).bind('status.group.groupremoved', function(e, result) {
|
|
|
|
console.log('status.group.groupremoved', result);
|
|
|
|
if(parseInt(result.groupid) === parseInt(self.currentgroup)) {
|
2012-12-13 02:30:20 +01:00
|
|
|
self.contacts.showContacts([]);
|
2012-11-23 01:16:46 +01:00
|
|
|
self.currentgroup = 'all';
|
|
|
|
}
|
|
|
|
$.each(result.contacts, function(idx, contactid) {
|
2012-12-13 02:30:20 +01:00
|
|
|
var contact = self.contacts.findById(contactid);
|
2012-12-17 15:19:22 +01:00
|
|
|
|
2013-04-08 22:37:37 +02:00
|
|
|
contact.removeFromGroup(result.groupname);
|
2012-11-23 01:16:46 +01:00
|
|
|
});
|
2012-11-22 19:32:47 +01:00
|
|
|
});
|
|
|
|
|
2013-05-21 23:39:50 +02:00
|
|
|
$(document).bind('status.group.grouprenamed', function(e, result) {
|
|
|
|
console.log('status.group.grouprenamed', result);
|
|
|
|
$.each(result.contacts, function(idx, contactid) {
|
|
|
|
var contact = self.contacts.findById(contactid);
|
|
|
|
if(!contact) {
|
2014-03-08 09:03:28 +01:00
|
|
|
console.warn('Couldn\'t find contact', contactid);
|
2013-05-21 23:39:50 +02:00
|
|
|
return true; // continue
|
|
|
|
}
|
|
|
|
contact.renameGroup(result.from, result.to);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-09-06 20:33:31 +02:00
|
|
|
$(document).bind('status.group.contactremoved', function(e, result) {
|
|
|
|
console.log('status.group.contactremoved', result, self.currentgroup, result.groupid);
|
|
|
|
var contact = self.contacts.findById(result.contactid);
|
|
|
|
if(contact) {
|
|
|
|
if(contact.inGroup(result.groupname)) {
|
|
|
|
contact.removeFromGroup(result.groupname);
|
|
|
|
}
|
|
|
|
if(parseInt(self.currentgroup) === parseInt(result.groupid)) {
|
|
|
|
console.log('Hiding', contact.getId());
|
|
|
|
contact.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-10-24 20:31:29 +02:00
|
|
|
$(document).bind('status.group.contactadded', function(e, result) {
|
|
|
|
console.log('status.group.contactadded', result);
|
2013-03-11 20:27:16 +01:00
|
|
|
var contact = self.contacts.findById(result.contactid);
|
2013-09-06 20:33:31 +02:00
|
|
|
if(contact) {
|
|
|
|
if(!contact.inGroup(result.groupname)) {
|
|
|
|
contact.addToGroup(result.groupname);
|
|
|
|
}
|
|
|
|
if(parseInt(self.currentgroup) === parseInt(result.groupid)) {
|
|
|
|
console.log('Showing', contact.getId());
|
|
|
|
contact.show();
|
|
|
|
}
|
2014-01-25 17:08:01 +01:00
|
|
|
if(self.currentgroup === 'uncategorized') {
|
|
|
|
console.log('Hiding', contact.getId());
|
|
|
|
contact.hide();
|
|
|
|
}
|
2013-02-03 15:40:14 +01:00
|
|
|
}
|
2012-10-24 20:31:29 +02:00
|
|
|
});
|
|
|
|
|
2012-10-26 01:57:16 +02:00
|
|
|
// Group sorted, save the sort order
|
|
|
|
$(document).bind('status.groups.sorted', function(e, result) {
|
|
|
|
console.log('status.groups.sorted', result);
|
2013-03-25 17:08:47 +01:00
|
|
|
$.when(self.storage.setPreference('groupsort', result.sortorder)).then(function(response) {
|
2013-03-28 03:19:01 +01:00
|
|
|
if(response.error) {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', {
|
|
|
|
message: response ? response.message : t('contacts', 'Network or server error. Please inform administrator.')
|
|
|
|
});
|
2012-10-26 01:57:16 +02:00
|
|
|
}
|
2013-03-25 17:08:47 +01:00
|
|
|
})
|
2013-05-24 02:57:12 +02:00
|
|
|
.fail(function(response) {
|
|
|
|
console.log(response.message);
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', response);
|
2013-05-24 02:57:12 +02:00
|
|
|
done = true;
|
2012-10-26 01:57:16 +02:00
|
|
|
});
|
|
|
|
});
|
2012-10-23 10:55:18 +02:00
|
|
|
// Group selected, only show contacts from that group
|
|
|
|
$(document).bind('status.group.selected', function(e, result) {
|
|
|
|
console.log('status.group.selected', result);
|
|
|
|
self.currentgroup = result.id;
|
|
|
|
// Close any open contact.
|
|
|
|
if(self.currentid) {
|
|
|
|
var id = self.currentid;
|
|
|
|
self.closeContact(id);
|
2012-12-07 15:08:25 +01:00
|
|
|
self.jumpToContact(id);
|
2012-10-23 10:55:18 +02:00
|
|
|
}
|
|
|
|
self.$toggleAll.show();
|
2013-04-30 20:00:33 +02:00
|
|
|
self.hideActions();
|
2012-10-23 10:55:18 +02:00
|
|
|
if(result.type === 'category' || result.type === 'fav') {
|
2012-12-13 02:30:20 +01:00
|
|
|
self.contacts.showContacts(result.contacts);
|
2012-10-24 20:31:29 +02:00
|
|
|
} else if(result.type === 'shared') {
|
2012-12-13 02:30:20 +01:00
|
|
|
self.contacts.showFromAddressbook(self.currentgroup, true, true);
|
2013-05-12 21:59:24 +02:00
|
|
|
} else if(result.type === 'uncategorized') {
|
|
|
|
self.contacts.showUncategorized();
|
2012-10-23 10:55:18 +02:00
|
|
|
} else {
|
2012-12-13 02:30:20 +01:00
|
|
|
self.contacts.showContacts(self.currentgroup);
|
2012-10-23 10:55:18 +02:00
|
|
|
}
|
2013-03-25 17:08:47 +01:00
|
|
|
$.when(self.storage.setPreference('lastgroup', self.currentgroup)).then(function(response) {
|
2013-03-28 03:19:01 +01:00
|
|
|
if(response.error) {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', response);
|
2012-10-23 10:55:18 +02:00
|
|
|
}
|
2013-03-25 17:08:47 +01:00
|
|
|
})
|
2013-05-24 02:57:12 +02:00
|
|
|
.fail(function(response) {
|
|
|
|
console.log(response.message);
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', response);
|
2013-05-24 02:57:12 +02:00
|
|
|
done = true;
|
2012-10-23 10:55:18 +02:00
|
|
|
});
|
|
|
|
self.$rightContent.scrollTop(0);
|
|
|
|
});
|
2012-09-17 16:15:31 +02:00
|
|
|
// mark items whose title was hid under the top edge as read
|
|
|
|
/*this.$rightContent.scroll(function() {
|
|
|
|
// prevent too many scroll requests;
|
|
|
|
if(!self.isScrolling) {
|
|
|
|
self.isScrolling = true;
|
|
|
|
var num = self.$contactList.find('tr').length;
|
|
|
|
//console.log('num', num);
|
|
|
|
var offset = self.$contactList.find('tr:eq(' + (num-20) + ')').offset().top;
|
|
|
|
if(offset < self.$rightContent.height()) {
|
|
|
|
console.log('load more');
|
2012-12-13 02:30:20 +01:00
|
|
|
self.contacts.loadContacts(num, function() {
|
2012-09-17 16:15:31 +02:00
|
|
|
self.isScrolling = false;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
setTimeout(function() {
|
|
|
|
self.isScrolling = false;
|
|
|
|
}, self.scrollTimeoutMiliSecs);
|
|
|
|
}
|
|
|
|
//console.log('scroll, unseen:', offset, self.$rightContent.height());
|
|
|
|
}
|
|
|
|
});*/
|
2013-04-08 22:35:28 +02:00
|
|
|
$('#contactphoto_fileupload').on('click', function(event, metadata) {
|
|
|
|
var form = $('#file_upload_form');
|
2014-03-02 23:01:56 +01:00
|
|
|
var url = OC.generateUrl(
|
2014-03-02 23:19:01 +01:00
|
|
|
'apps/contacts/addressbook/{backend}/{addressBookId}/contact/{contactId}/photo',
|
2013-10-22 17:10:23 +02:00
|
|
|
{backend: metadata.backend, addressBookId: metadata.addressBookId, contactId: metadata.contactId}
|
2013-09-04 08:03:33 +02:00
|
|
|
);
|
|
|
|
form.attr('action', url);
|
2013-05-19 05:19:58 +02:00
|
|
|
}).on('change', function() {
|
|
|
|
console.log('#contactphoto_fileupload, change');
|
|
|
|
self.uploadPhoto(this.files);
|
2013-04-08 22:35:28 +02:00
|
|
|
});
|
|
|
|
|
2013-05-19 05:19:58 +02:00
|
|
|
var target = $('#file_upload_target');
|
|
|
|
target.load(function() {
|
|
|
|
var response = $.parseJSON(target.contents().text());
|
2014-03-08 09:03:28 +01:00
|
|
|
if(response && response.status === 'success') {
|
2013-05-19 05:19:58 +02:00
|
|
|
console.log('response', response);
|
|
|
|
self.editPhoto(
|
2013-09-04 08:03:33 +02:00
|
|
|
response.data.metadata,
|
2013-05-19 05:19:58 +02:00
|
|
|
response.data.tmp
|
|
|
|
);
|
|
|
|
//alert('File: ' + file.tmp + ' ' + file.name + ' ' + file.mime);
|
|
|
|
} else if(response) {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', response);
|
2013-05-19 05:19:58 +02:00
|
|
|
}
|
2012-11-05 12:39:12 +01:00
|
|
|
});
|
|
|
|
|
2012-10-05 05:05:49 +02:00
|
|
|
this.$ninjahelp.find('.close').on('click keydown',function(event) {
|
|
|
|
if(wrongKey(event)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.$ninjahelp.hide();
|
|
|
|
});
|
2012-11-01 15:31:58 +01:00
|
|
|
|
2013-05-31 21:32:16 +02:00
|
|
|
this.$toggleAll.on('change', function(event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2012-10-30 07:03:09 +01:00
|
|
|
var isChecked = $(this).is(':checked');
|
2012-11-15 02:41:52 +01:00
|
|
|
self.setAllChecked(isChecked);
|
2012-10-05 05:05:49 +02:00
|
|
|
if(self.$groups.find('option').length === 1) {
|
|
|
|
self.buildGroupSelect();
|
|
|
|
}
|
2012-11-13 17:01:14 +01:00
|
|
|
if(isChecked) {
|
2013-05-31 21:32:16 +02:00
|
|
|
self.showActions(['toggle', 'add', 'download', 'groups', 'delete', 'favorite', 'merge']);
|
2012-11-13 17:01:14 +01:00
|
|
|
} else {
|
2013-04-30 20:00:33 +02:00
|
|
|
self.hideActions();
|
2012-11-13 17:01:14 +01:00
|
|
|
}
|
2012-10-05 05:05:49 +02:00
|
|
|
});
|
2012-11-01 15:31:58 +01:00
|
|
|
|
2014-03-08 09:03:28 +01:00
|
|
|
this.$contactList.on('change', 'input:checkbox', function(/*event*/) {
|
2013-04-03 16:43:18 +02:00
|
|
|
var selected = self.contacts.getSelectedContacts();
|
2013-09-15 19:04:19 +02:00
|
|
|
var id = String($(this).val());
|
|
|
|
// Save list of last selected contact to be able to select range
|
2014-03-08 09:03:28 +01:00
|
|
|
$(this).is(':checked') && self.lastSelectedContacts.indexOf(id) === -1
|
2013-09-15 19:04:19 +02:00
|
|
|
? self.lastSelectedContacts.push(id)
|
|
|
|
: self.lastSelectedContacts.splice(self.lastSelectedContacts.indexOf(id), 1);
|
|
|
|
|
2013-04-03 16:43:18 +02:00
|
|
|
if(selected.length > 0 && self.$groups.find('option').length === 1) {
|
|
|
|
self.buildGroupSelect();
|
|
|
|
}
|
|
|
|
if(selected.length === 0) {
|
2013-04-30 20:00:33 +02:00
|
|
|
self.hideActions();
|
2013-04-03 16:43:18 +02:00
|
|
|
} else if(selected.length === 1) {
|
2013-05-31 21:32:16 +02:00
|
|
|
self.showActions(['toggle', 'add', 'download', 'groups', 'delete', 'favorite']);
|
2013-04-03 16:43:18 +02:00
|
|
|
} else {
|
2013-05-31 21:32:16 +02:00
|
|
|
self.showActions(['toggle', 'add', 'download', 'groups', 'delete', 'favorite', 'merge']);
|
2012-10-05 05:05:49 +02:00
|
|
|
}
|
|
|
|
});
|
2014-01-02 13:51:13 +01:00
|
|
|
|
2014-03-08 09:03:28 +01:00
|
|
|
this.$contactList.on('click', 'label:not([for=select_all])', function(/*event*/) {
|
2014-01-23 20:53:12 +01:00
|
|
|
var $input = $(this).prev('input');
|
|
|
|
$input.prop('checked', !$input.prop('checked'));
|
2014-01-24 15:21:48 +01:00
|
|
|
$input.trigger('change');
|
2014-01-02 13:51:13 +01:00
|
|
|
return false; // Prevent opening contact
|
|
|
|
});
|
2012-11-01 15:31:58 +01:00
|
|
|
|
2013-05-22 21:44:39 +02:00
|
|
|
this.$sortOrder.on('change', function() {
|
|
|
|
$(this).blur().addClass('loading');
|
|
|
|
contacts_sortby = $(this).val();
|
|
|
|
self.contacts.setSortOrder();
|
|
|
|
$(this).removeClass('loading');
|
|
|
|
self.storage.setPreference('sortby', contacts_sortby);
|
|
|
|
});
|
|
|
|
|
2012-12-13 02:38:58 +01:00
|
|
|
// Add to/remove from group multiple contacts.
|
2012-10-05 05:05:49 +02:00
|
|
|
this.$groups.on('change', function() {
|
|
|
|
var $opt = $(this).find('option:selected');
|
|
|
|
var action = $opt.parent().data('action');
|
2013-03-30 17:33:58 +01:00
|
|
|
var groupName, groupId, buildnow = false;
|
2012-10-22 15:35:33 +02:00
|
|
|
|
2013-03-30 17:33:58 +01:00
|
|
|
var contacts = self.contacts.getSelectedContacts();
|
|
|
|
var ids = $.map(contacts, function(c) {return c.getId();});
|
2012-11-14 15:27:38 +01:00
|
|
|
|
2012-11-15 02:41:52 +01:00
|
|
|
self.setAllChecked(false);
|
2012-11-23 01:19:16 +01:00
|
|
|
self.$toggleAll.prop('checked', false);
|
2012-11-24 01:40:29 +01:00
|
|
|
if(!self.currentid) {
|
2013-04-30 20:00:33 +02:00
|
|
|
self.hideActions();
|
2012-11-24 01:40:29 +01:00
|
|
|
}
|
2012-12-17 15:19:22 +01:00
|
|
|
|
2012-11-14 15:27:38 +01:00
|
|
|
if($opt.val() === 'add') { // Add new group
|
|
|
|
action = 'add';
|
2012-10-05 05:05:49 +02:00
|
|
|
console.log('add group...');
|
|
|
|
self.$groups.val(-1);
|
2012-11-14 15:27:38 +01:00
|
|
|
self.addGroup(function(response) {
|
2013-03-29 23:23:47 +01:00
|
|
|
if(!response.error) {
|
2012-11-14 15:27:38 +01:00
|
|
|
groupId = response.id;
|
|
|
|
groupName = response.name;
|
2012-12-13 02:30:20 +01:00
|
|
|
self.groups.addTo(ids, groupId, function(result) {
|
2013-05-03 00:23:56 +02:00
|
|
|
if(!result.error) {
|
2012-11-14 15:27:38 +01:00
|
|
|
$.each(ids, function(idx, id) {
|
|
|
|
// Delay each contact to not trigger too many ajax calls
|
|
|
|
// at a time.
|
|
|
|
setTimeout(function() {
|
2013-02-03 15:40:14 +01:00
|
|
|
var contact = self.contacts.findById(id);
|
|
|
|
if(contact === null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
contact.addToGroup(groupName);
|
2012-11-14 15:27:38 +01:00
|
|
|
// I don't think this is used...
|
|
|
|
if(buildnow) {
|
|
|
|
self.buildGroupSelect();
|
2012-10-19 22:09:59 +02:00
|
|
|
}
|
2012-11-14 15:27:38 +01:00
|
|
|
}, 1000);
|
2012-10-19 22:09:59 +02:00
|
|
|
});
|
2012-11-14 15:27:38 +01:00
|
|
|
} else {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', result);
|
2012-11-14 15:27:38 +01:00
|
|
|
}
|
2012-10-19 22:09:59 +02:00
|
|
|
});
|
2012-11-14 15:27:38 +01:00
|
|
|
} else {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', response);
|
2012-11-14 15:27:38 +01:00
|
|
|
}
|
2012-10-19 22:09:59 +02:00
|
|
|
});
|
2012-10-05 05:05:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-12-17 15:19:22 +01:00
|
|
|
|
2012-11-14 15:27:38 +01:00
|
|
|
groupName = $opt.text(), groupId = $opt.val();
|
2012-10-22 15:35:33 +02:00
|
|
|
|
2012-10-05 05:05:49 +02:00
|
|
|
if(action === 'add') {
|
2012-12-13 02:30:20 +01:00
|
|
|
self.groups.addTo(ids, $opt.val(), function(result) {
|
2012-11-01 15:31:58 +01:00
|
|
|
console.log('after add', result);
|
2013-05-03 00:23:56 +02:00
|
|
|
if(!result.error) {
|
2012-11-01 15:31:58 +01:00
|
|
|
$.each(result.ids, function(idx, id) {
|
|
|
|
// Delay each contact to not trigger too many ajax calls
|
|
|
|
// at a time.
|
|
|
|
setTimeout(function() {
|
2012-11-14 15:27:38 +01:00
|
|
|
console.log('adding', id, 'to', groupName);
|
2013-02-03 15:40:14 +01:00
|
|
|
var contact = self.contacts.findById(id);
|
|
|
|
if(contact === null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
contact.addToGroup(groupName);
|
2012-11-01 15:31:58 +01:00
|
|
|
// I don't think this is used...
|
2012-11-05 12:39:49 +01:00
|
|
|
if(buildnow) {
|
|
|
|
self.buildGroupSelect();
|
|
|
|
}
|
2012-11-01 15:31:58 +01:00
|
|
|
}, 1000);
|
|
|
|
});
|
|
|
|
} else {
|
2012-11-14 15:27:38 +01:00
|
|
|
var msg = result.message ? result.message : t('contacts', 'Error adding to group.');
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', {message:msg});
|
2012-11-01 15:31:58 +01:00
|
|
|
}
|
2012-10-05 05:05:49 +02:00
|
|
|
});
|
|
|
|
if(!buildnow) {
|
|
|
|
self.$groups.val(-1).hide().find('optgroup,option:not([value="-1"])').remove();
|
|
|
|
}
|
|
|
|
} else if(action === 'remove') {
|
2013-09-06 20:33:31 +02:00
|
|
|
self.groups.removeFrom(ids, $opt.val(), false, function(result) {
|
2012-11-01 15:31:58 +01:00
|
|
|
console.log('after remove', result);
|
2013-05-03 00:23:56 +02:00
|
|
|
if(!result.error) {
|
2012-11-01 15:31:58 +01:00
|
|
|
var groupname = $opt.text(), groupid = $opt.val();
|
|
|
|
$.each(result.ids, function(idx, id) {
|
2013-02-03 15:40:14 +01:00
|
|
|
var contact = self.contacts.findById(id);
|
|
|
|
if(contact === null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
contact.removeFromGroup(groupname);
|
2012-11-05 12:39:49 +01:00
|
|
|
if(buildnow) {
|
|
|
|
self.buildGroupSelect();
|
|
|
|
}
|
2012-11-01 15:31:58 +01:00
|
|
|
});
|
|
|
|
} else {
|
2012-11-14 15:27:38 +01:00
|
|
|
var msg = result.message ? result.message : t('contacts', 'Error removing from group.');
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', {message:msg});
|
2012-11-01 15:31:58 +01:00
|
|
|
}
|
2012-10-05 05:05:49 +02:00
|
|
|
});
|
|
|
|
if(!buildnow) {
|
|
|
|
self.$groups.val(-1).hide().find('optgroup,option:not([value="-1"])').remove();
|
|
|
|
}
|
|
|
|
} // else something's wrong ;)
|
2012-11-15 02:41:52 +01:00
|
|
|
self.setAllChecked(false);
|
2012-10-05 05:05:49 +02:00
|
|
|
});
|
2012-11-01 15:31:58 +01:00
|
|
|
|
2013-06-02 12:16:49 +02:00
|
|
|
this.$contactList.on('mouseenter', 'tr.contact', function(event) {
|
|
|
|
var $td = $(this).find('td').filter(':visible').last();
|
2014-02-27 15:03:44 +01:00
|
|
|
$('<a />').addClass('icon-delete svg delete action').appendTo($td);
|
2013-06-02 12:16:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.$contactList.on('mouseleave', 'tr.contact', function(event) {
|
|
|
|
$(this).find('a.delete').remove();
|
|
|
|
});
|
|
|
|
|
2013-09-15 19:04:19 +02:00
|
|
|
// Prevent Firefox from selecting the table-cell
|
|
|
|
this.$contactList.mousedown(function (event) {
|
|
|
|
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-10-05 05:05:49 +02:00
|
|
|
// Contact list. Either open a contact or perform an action (mailto etc.)
|
2013-05-31 21:32:16 +02:00
|
|
|
this.$contactList.on('click', 'tr.contact', function(event) {
|
2012-09-17 16:15:31 +02:00
|
|
|
if($(event.target).is('input')) {
|
|
|
|
return;
|
|
|
|
}
|
2013-09-15 19:04:19 +02:00
|
|
|
// Select a single contact or a range of contacts.
|
|
|
|
if(event.ctrlKey || event.metaKey || event.shiftKey) {
|
2012-10-05 05:05:49 +02:00
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
self.dontScroll = true;
|
2013-09-15 19:04:19 +02:00
|
|
|
var $input = $(this).find('input:checkbox');
|
|
|
|
var index = self.$contactList.find('tr.contact:visible').index($(this));
|
|
|
|
if(event.shiftKey && self.lastSelectedContacts.length > 0) {
|
|
|
|
self.contacts.selectRange(
|
|
|
|
$(this).data('id'),
|
|
|
|
self.lastSelectedContacts[self.lastSelectedContacts.length-1]
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
self.contacts.setSelected($(this).data('id'), !$input.prop('checked'));
|
|
|
|
}
|
2012-10-05 05:05:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-09-17 16:15:31 +02:00
|
|
|
if($(event.target).is('a.mailto')) {
|
2013-05-24 15:30:59 +02:00
|
|
|
$(document).trigger('request.openurl', {
|
|
|
|
type: 'email',
|
|
|
|
url: $.trim($(this).find('.email').text())
|
|
|
|
});
|
2012-09-17 16:15:31 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-06-01 01:25:36 +02:00
|
|
|
if($(event.target).is('a.delete')) {
|
|
|
|
$(document).trigger('request.contact.delete', {
|
2013-11-04 15:03:04 +01:00
|
|
|
contactId: $(this).data('id')
|
2013-06-01 01:25:36 +02:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2013-05-09 21:18:32 +02:00
|
|
|
self.openContact(String($(this).data('id')));
|
2012-09-17 16:15:31 +02:00
|
|
|
});
|
2012-12-17 15:19:22 +01:00
|
|
|
|
2013-05-01 01:47:45 +02:00
|
|
|
this.$settings.find('#app-settings-header').on('click keydown',function(event) {
|
|
|
|
if(wrongKey(event)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var bodyListener = function(e) {
|
2014-03-08 09:03:28 +01:00
|
|
|
if(self.$settings.find($(e.target)).length === 0) {
|
2013-05-01 01:47:45 +02:00
|
|
|
self.$settings.switchClass('open', '');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if(self.$settings.hasClass('open')) {
|
|
|
|
self.$settings.switchClass('open', '');
|
|
|
|
$('body').unbind('click', bodyListener);
|
|
|
|
} else {
|
|
|
|
self.$settings.switchClass('', 'open');
|
|
|
|
$('body').bind('click', bodyListener);
|
|
|
|
}
|
|
|
|
});
|
2012-11-15 02:42:33 +01:00
|
|
|
|
2013-02-16 23:00:11 +01:00
|
|
|
var addContact = function() {
|
2012-12-14 02:53:06 +01:00
|
|
|
console.log('add');
|
2013-10-29 19:27:25 +01:00
|
|
|
if(self.currentid) {
|
|
|
|
if(self.currentid === 'new') {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
var contact = self.contacts.findById(self.currentid);
|
|
|
|
if(contact) {
|
2014-03-04 20:39:33 +01:00
|
|
|
contact.close(true);
|
2013-10-29 19:27:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-12-14 02:53:06 +01:00
|
|
|
self.currentid = 'new';
|
|
|
|
// Properties that the contact doesn't know
|
2012-12-17 15:19:22 +01:00
|
|
|
console.log('addContact, groupid', self.currentgroup);
|
2012-12-14 02:53:06 +01:00
|
|
|
var groupprops = {
|
|
|
|
favorite: false,
|
|
|
|
groups: self.groups.categories,
|
2012-12-17 15:19:22 +01:00
|
|
|
currentgroup: {id:self.currentgroup, name:self.groups.nameById(self.currentgroup)}
|
2012-12-14 02:53:06 +01:00
|
|
|
};
|
2013-03-04 17:57:46 +01:00
|
|
|
self.$firstRun.hide();
|
|
|
|
self.$contactList.show();
|
2012-12-14 02:53:06 +01:00
|
|
|
self.tmpcontact = self.contacts.addContact(groupprops);
|
2013-10-29 21:19:10 +01:00
|
|
|
self.tmpcontact.prependTo(self.$contactList.find('tbody')).show().find('.fullname').focus();
|
2013-09-14 18:35:25 +02:00
|
|
|
self.$rightContent.scrollTop(0);
|
2012-12-14 02:53:06 +01:00
|
|
|
self.hideActions();
|
2013-02-16 23:00:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.$firstRun.on('click keydown', '.import', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
self.$settings.find('.settings').click();
|
|
|
|
});
|
|
|
|
|
2013-04-30 20:00:33 +02:00
|
|
|
this.$firstRun.on('click keydown', '.add-contact', function(event) {
|
2013-02-16 23:00:11 +01:00
|
|
|
if(wrongKey(event)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addContact();
|
|
|
|
});
|
|
|
|
|
2013-12-18 16:59:39 +01:00
|
|
|
this.$groupList.on('click keydown', '.add-contact', function(event) {
|
2013-02-16 23:00:11 +01:00
|
|
|
if(wrongKey(event)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addContact();
|
2012-11-15 02:42:33 +01:00
|
|
|
});
|
|
|
|
|
2013-12-18 15:35:41 +01:00
|
|
|
this.$contactListHeader.on('click keydown', '.delete', function(event) {
|
2012-10-05 05:05:49 +02:00
|
|
|
if(wrongKey(event)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-17 16:15:31 +02:00
|
|
|
console.log('delete');
|
|
|
|
if(self.currentid) {
|
2013-03-30 17:33:58 +01:00
|
|
|
console.assert(typeof self.currentid === 'string', 'self.currentid is not a string');
|
|
|
|
contactInfo = self.contacts[self.currentid].metaData();
|
|
|
|
self.contacts.delayedDelete(contactInfo);
|
2012-10-05 05:05:49 +02:00
|
|
|
} else {
|
2012-12-13 02:30:20 +01:00
|
|
|
self.contacts.delayedDelete(self.contacts.getSelectedContacts());
|
2012-10-05 05:05:49 +02:00
|
|
|
}
|
2013-04-30 20:00:33 +02:00
|
|
|
self.hideActions();
|
2012-10-05 05:05:49 +02:00
|
|
|
});
|
2012-11-15 00:28:43 +01:00
|
|
|
|
2013-12-18 15:35:41 +01:00
|
|
|
this.$contactListHeader.on('click keydown', '.download', function(event) {
|
2012-10-05 05:05:49 +02:00
|
|
|
if(wrongKey(event)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-20 01:29:28 +01:00
|
|
|
|
|
|
|
var doDownload = function(contacts) {
|
|
|
|
// Only get backend, addressbookid and contactid
|
|
|
|
contacts = $.map(contacts, function(c) {return c.metaData();});
|
|
|
|
var targets = {};
|
|
|
|
// Try to shorten request URI
|
|
|
|
$.each(contacts, function(idx, contact) {
|
|
|
|
if(!targets[contact.backend]) {
|
|
|
|
targets[contact.backend] = {};
|
|
|
|
}
|
|
|
|
if(!targets[contact.backend][contact.addressBookId]) {
|
|
|
|
targets[contact.backend][contact.addressBookId] = [];
|
|
|
|
}
|
|
|
|
targets[contact.backend][contact.addressBookId].push(contact.contactId);
|
|
|
|
});
|
2014-03-02 23:01:56 +01:00
|
|
|
var url = OC.generateUrl('exportSelected', {t:targets});
|
2013-12-20 01:29:28 +01:00
|
|
|
//console.log('export url', url);
|
|
|
|
document.location.href = url;
|
|
|
|
};
|
2013-03-30 17:33:58 +01:00
|
|
|
var contacts = self.contacts.getSelectedContacts();
|
2013-12-20 01:29:28 +01:00
|
|
|
console.log('download', contacts.length);
|
|
|
|
|
|
|
|
// The 300 is just based on my little testing with Apache2
|
|
|
|
// Other web servers may fail before.
|
|
|
|
if(contacts.length > 300) {
|
|
|
|
OC.notify({
|
2014-03-08 09:03:28 +01:00
|
|
|
message:t('contacts', 'You have selected over 300 contacts.\nThis will most likely fail! Click here to try anyway.'),
|
2013-12-20 01:29:28 +01:00
|
|
|
timeout:5,
|
|
|
|
clickhandler:function() {
|
|
|
|
doDownload(contacts);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
doDownload(contacts);
|
|
|
|
}
|
2012-09-17 16:15:31 +02:00
|
|
|
});
|
2012-11-15 00:28:43 +01:00
|
|
|
|
2013-04-30 20:00:33 +02:00
|
|
|
this.$contactListHeader.on('click keydown', '.merge', function(event) {
|
2012-10-05 05:05:49 +02:00
|
|
|
if(wrongKey(event)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-04-03 16:43:18 +02:00
|
|
|
console.log('merge');
|
|
|
|
self.mergeSelectedContacts();
|
|
|
|
});
|
|
|
|
|
2013-04-30 20:00:33 +02:00
|
|
|
this.$contactListHeader.on('click keydown', '.favorite', function(event) {
|
2012-10-05 05:05:49 +02:00
|
|
|
if(wrongKey(event)) {
|
2012-11-22 05:34:37 +01:00
|
|
|
return;
|
2012-09-17 16:15:31 +02:00
|
|
|
}
|
2013-03-30 20:13:52 +01:00
|
|
|
|
|
|
|
var contacts = self.contacts.getSelectedContacts();
|
|
|
|
|
|
|
|
self.setAllChecked(false);
|
|
|
|
self.$toggleAll.prop('checked', false);
|
|
|
|
if(!self.currentid) {
|
2013-04-30 20:00:33 +02:00
|
|
|
self.hideActions();
|
2012-09-17 16:15:31 +02:00
|
|
|
}
|
2013-03-30 20:13:52 +01:00
|
|
|
|
|
|
|
$.each(contacts, function(idx, contact) {
|
|
|
|
if(!self.groups.isFavorite(contact.getId())) {
|
|
|
|
self.groups.setAsFavorite(contact.getId(), true, function(result) {
|
|
|
|
if(result.status !== 'success') {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', {message:
|
2013-03-30 20:13:52 +01:00
|
|
|
t('contacts',
|
|
|
|
'Error setting {name} as favorite.',
|
|
|
|
{name:contact.getDisplayName()})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2012-11-22 05:34:37 +01:00
|
|
|
}
|
|
|
|
});
|
2013-03-30 20:13:52 +01:00
|
|
|
|
2013-04-30 20:00:33 +02:00
|
|
|
self.hideActions();
|
2012-09-17 16:15:31 +02:00
|
|
|
});
|
2012-11-15 00:28:43 +01:00
|
|
|
|
2012-09-17 16:15:31 +02:00
|
|
|
this.$contactList.on('mouseenter', 'td.email', function(event) {
|
2013-02-12 11:56:09 +01:00
|
|
|
if($.trim($(this).text()).length > 3) {
|
2012-10-15 21:33:21 +02:00
|
|
|
$(this).find('.mailto').css('display', 'inline-block'); //.fadeIn(100);
|
2012-09-17 16:15:31 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.$contactList.on('mouseleave', 'td.email', function(event) {
|
|
|
|
$(this).find('.mailto').fadeOut(100);
|
|
|
|
});
|
2012-10-05 05:05:49 +02:00
|
|
|
|
2013-01-14 09:15:49 +01:00
|
|
|
$('body').on('touchmove', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
2013-03-29 22:40:59 +01:00
|
|
|
$(document).on('keyup', function(event) {
|
2013-04-03 16:54:25 +02:00
|
|
|
if(!$(event.target).is('body') || event.isPropagationStopped()) {
|
2012-10-05 05:05:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-12-03 19:39:28 +01:00
|
|
|
var keyCode = Math.max(event.keyCode, event.which);
|
2012-10-30 07:03:09 +01:00
|
|
|
// TODO: This should go in separate method
|
2012-12-03 19:39:28 +01:00
|
|
|
console.log(event, keyCode + ' ' + event.target.nodeName);
|
2012-10-05 05:05:49 +02:00
|
|
|
/**
|
|
|
|
* To add:
|
|
|
|
* Shift-a: add addressbook
|
|
|
|
* u (85): hide/show leftcontent
|
|
|
|
* f (70): add field
|
|
|
|
*/
|
2012-12-03 19:39:28 +01:00
|
|
|
switch(keyCode) {
|
2012-10-05 05:05:49 +02:00
|
|
|
case 13: // Enter?
|
|
|
|
console.log('Enter?');
|
|
|
|
if(!self.currentid && self.currentlistid) {
|
|
|
|
self.openContact(self.currentlistid);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 27: // Esc
|
|
|
|
if(self.$ninjahelp.is(':visible')) {
|
|
|
|
self.$ninjahelp.hide();
|
|
|
|
} else if(self.currentid) {
|
|
|
|
self.closeContact(self.currentid);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 46: // Delete
|
|
|
|
if(event.shiftKey) {
|
2012-12-13 02:30:20 +01:00
|
|
|
self.contacts.delayedDelete(self.currentid);
|
2012-10-05 05:05:49 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 40: // down
|
|
|
|
case 74: // j
|
|
|
|
console.log('next');
|
|
|
|
if(!self.currentid && self.currentlistid) {
|
2012-12-13 02:30:20 +01:00
|
|
|
self.contacts.contacts[self.currentlistid].next();
|
2012-10-05 05:05:49 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 65: // a
|
|
|
|
if(event.shiftKey) {
|
|
|
|
console.log('add group?');
|
|
|
|
break;
|
|
|
|
}
|
2014-03-08 09:03:28 +01:00
|
|
|
addContact();
|
2012-10-05 05:05:49 +02:00
|
|
|
break;
|
|
|
|
case 38: // up
|
|
|
|
case 75: // k
|
|
|
|
console.log('previous');
|
|
|
|
if(!self.currentid && self.currentlistid) {
|
2012-12-13 02:30:20 +01:00
|
|
|
self.contacts.contacts[self.currentlistid].prev();
|
2012-10-05 05:05:49 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 34: // PageDown
|
|
|
|
case 78: // n
|
2012-12-17 15:19:22 +01:00
|
|
|
console.log('page down');
|
2012-10-05 05:05:49 +02:00
|
|
|
break;
|
|
|
|
case 79: // o
|
|
|
|
console.log('open contact?');
|
|
|
|
break;
|
|
|
|
case 33: // PageUp
|
|
|
|
case 80: // p
|
|
|
|
// prev addressbook
|
2012-12-13 02:30:20 +01:00
|
|
|
//OC.contacts.contacts.previousAddressbook();
|
2012-10-05 05:05:49 +02:00
|
|
|
break;
|
|
|
|
case 82: // r
|
|
|
|
console.log('refresh - what?');
|
|
|
|
break;
|
|
|
|
case 63: // ? German.
|
|
|
|
if(event.shiftKey) {
|
|
|
|
self.$ninjahelp.toggle('fast');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 171: // ? Danish
|
|
|
|
case 191: // ? Standard qwerty
|
2014-03-08 09:03:28 +01:00
|
|
|
self.$ninjahelp.toggle('fast').position({my: 'center', at: 'center', of: '#content'});
|
2012-10-05 05:05:49 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2012-10-22 15:35:33 +02:00
|
|
|
|
2012-12-17 15:19:22 +01:00
|
|
|
// find all with a title attribute and tipsy them
|
2012-12-10 20:58:34 +01:00
|
|
|
$('.tooltipped.downwards:not(.onfocus)').tipsy({gravity: 'n'});
|
|
|
|
$('.tooltipped.upwards:not(.onfocus)').tipsy({gravity: 's'});
|
|
|
|
$('.tooltipped.rightwards:not(.onfocus)').tipsy({gravity: 'w'});
|
|
|
|
$('.tooltipped.leftwards:not(.onfocus)').tipsy({gravity: 'e'});
|
|
|
|
$('.tooltipped.downwards.onfocus').tipsy({trigger: 'focus', gravity: 'n'});
|
|
|
|
$('.tooltipped.rightwards.onfocus').tipsy({trigger: 'focus', gravity: 'w'});
|
2012-09-17 16:15:31 +02:00
|
|
|
},
|
2013-04-03 16:43:18 +02:00
|
|
|
mergeSelectedContacts: function() {
|
|
|
|
var contacts = this.contacts.getSelectedContacts();
|
|
|
|
this.$rightContent.append('<div id="merge_contacts_dialog"></div>');
|
|
|
|
if(!this.$mergeContactsTmpl) {
|
|
|
|
this.$mergeContactsTmpl = $('#mergeContactsTemplate');
|
|
|
|
}
|
|
|
|
var $dlg = this.$mergeContactsTmpl.octemplate();
|
2013-04-05 22:21:08 +02:00
|
|
|
var $liTmpl = $dlg.find('li').detach();
|
|
|
|
var $mergeList = $dlg.find('.mergelist');
|
2013-04-03 16:43:18 +02:00
|
|
|
$.each(contacts, function(idx, contact) {
|
2013-04-05 22:21:08 +02:00
|
|
|
var $li = $liTmpl
|
|
|
|
.octemplate({idx: idx, id: contact.getId(), displayname: contact.getDisplayName()});
|
|
|
|
if(!contact.data.thumbnail) {
|
|
|
|
$li.addClass('thumbnail');
|
|
|
|
} else {
|
|
|
|
$li.css('background-image', 'url(data:image/png;base64,' + contact.data.thumbnail + ')');
|
|
|
|
}
|
|
|
|
if(idx === 0) {
|
|
|
|
$li.find('input:radio').prop('checked', true);
|
|
|
|
}
|
|
|
|
$mergeList.append($li);
|
2013-04-03 16:43:18 +02:00
|
|
|
});
|
|
|
|
$('#merge_contacts_dialog').html($dlg).ocdialog({
|
2013-06-03 15:45:54 +02:00
|
|
|
modal: true,
|
2013-04-03 16:43:18 +02:00
|
|
|
closeOnEscape: true,
|
|
|
|
title: t('contacts', 'Merge contacts'),
|
|
|
|
height: 'auto', width: 'auto',
|
|
|
|
buttons: [
|
|
|
|
{
|
2013-04-05 19:06:26 +02:00
|
|
|
text: t('contacts', 'Merge contacts'),
|
2013-04-03 16:43:18 +02:00
|
|
|
click:function() {
|
|
|
|
// Do the merging, use $(this) to get dialog
|
|
|
|
var contactid = $(this).find('input:radio:checked').val();
|
|
|
|
var others = [];
|
|
|
|
var deleteOther = $(this).find('#delete_other').prop('checked');
|
|
|
|
console.log('Selected contact', contactid, 'Delete others', deleteOther);
|
|
|
|
$.each($(this).find('input:radio:not(:checked)'), function(idx, item) {
|
|
|
|
others.push($(item).val());
|
|
|
|
});
|
|
|
|
console.log('others', others);
|
|
|
|
$(document).trigger('request.contact.merge', {
|
|
|
|
merger: contactid,
|
|
|
|
mergees: others,
|
|
|
|
deleteOther: deleteOther
|
|
|
|
});
|
|
|
|
|
|
|
|
$(this).ocdialog('close');
|
|
|
|
},
|
|
|
|
defaultButton: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: t('contacts', 'Cancel'),
|
2014-03-08 06:30:29 +01:00
|
|
|
click:function() {
|
2013-04-03 16:43:18 +02:00
|
|
|
$(this).ocdialog('close');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2014-03-08 06:30:29 +01:00
|
|
|
close: function(/*event, ui*/) {
|
2013-04-03 16:43:18 +02:00
|
|
|
$(this).ocdialog('destroy').remove();
|
2014-03-08 09:03:28 +01:00
|
|
|
$('#merge_contacts_dialog').remove();
|
2013-04-03 16:43:18 +02:00
|
|
|
},
|
2014-03-08 06:30:29 +01:00
|
|
|
open: function(/*event, ui*/) {
|
2013-04-03 16:43:18 +02:00
|
|
|
$dlg.find('input').focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-11-14 15:27:38 +01:00
|
|
|
addGroup: function(cb) {
|
|
|
|
var self = this;
|
2013-04-03 16:43:18 +02:00
|
|
|
this.$rightContent.append('<div id="add_group_dialog"></div>');
|
2012-11-14 15:27:38 +01:00
|
|
|
if(!this.$addGroupTmpl) {
|
|
|
|
this.$addGroupTmpl = $('#addGroupTemplate');
|
|
|
|
}
|
2013-04-03 16:43:18 +02:00
|
|
|
this.$contactList.addClass('dim');
|
2012-11-14 15:27:38 +01:00
|
|
|
var $dlg = this.$addGroupTmpl.octemplate();
|
2013-04-01 15:12:53 +02:00
|
|
|
$('#add_group_dialog').html($dlg).ocdialog({
|
2012-11-14 15:27:38 +01:00
|
|
|
modal: true,
|
|
|
|
closeOnEscape: true,
|
|
|
|
title: t('contacts', 'Add group'),
|
|
|
|
height: 'auto', width: 'auto',
|
2013-04-01 15:12:53 +02:00
|
|
|
buttons: [
|
|
|
|
{
|
|
|
|
text: t('contacts', 'OK'),
|
|
|
|
click:function() {
|
|
|
|
var name = $(this).find('input').val();
|
|
|
|
if(name.trim() === '') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
self.groups.addGroup(
|
|
|
|
{name:$dlg.find('input:text').val()},
|
|
|
|
function(response) {
|
|
|
|
if(typeof cb === 'function') {
|
|
|
|
cb(response);
|
|
|
|
} else {
|
|
|
|
if(response.error) {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', response);
|
2013-04-01 15:12:53 +02:00
|
|
|
}
|
2012-11-14 15:27:38 +01:00
|
|
|
}
|
2013-04-01 15:12:53 +02:00
|
|
|
});
|
|
|
|
$(this).ocdialog('close');
|
2013-04-03 16:54:25 +02:00
|
|
|
},
|
|
|
|
defaultButton: true
|
2012-11-14 15:27:38 +01:00
|
|
|
},
|
2013-04-01 15:12:53 +02:00
|
|
|
{
|
|
|
|
text: t('contacts', 'Cancel'),
|
2014-03-08 06:30:29 +01:00
|
|
|
click:function() {
|
2013-04-01 15:12:53 +02:00
|
|
|
$(this).ocdialog('close');
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-14 15:27:38 +01:00
|
|
|
}
|
2013-04-01 15:12:53 +02:00
|
|
|
],
|
2014-03-08 06:30:29 +01:00
|
|
|
close: function(/*event, ui*/) {
|
2013-04-01 15:12:53 +02:00
|
|
|
$(this).ocdialog('destroy').remove();
|
2012-11-14 15:27:38 +01:00
|
|
|
$('#add_group_dialog').remove();
|
2013-04-03 16:54:25 +02:00
|
|
|
self.$contactList.removeClass('dim');
|
2012-11-14 15:27:38 +01:00
|
|
|
},
|
2014-03-08 06:30:29 +01:00
|
|
|
open: function(/*event, ui*/) {
|
2012-11-14 15:27:38 +01:00
|
|
|
$dlg.find('input').focus();
|
2012-12-17 15:19:22 +01:00
|
|
|
}
|
2012-11-14 15:27:38 +01:00
|
|
|
});
|
|
|
|
},
|
2012-11-15 02:41:52 +01:00
|
|
|
setAllChecked: function(checked) {
|
|
|
|
var selector = checked ? 'input:checkbox:visible:not(checked)' : 'input:checkbox:visible:checked';
|
2012-12-20 22:58:46 +01:00
|
|
|
$.each(this.$contactList.find(selector), function() {
|
2012-11-15 02:41:52 +01:00
|
|
|
$(this).prop('checked', checked);
|
|
|
|
});
|
2013-09-15 19:04:19 +02:00
|
|
|
this.lastSelectedContacts = [];
|
2012-11-15 02:41:52 +01:00
|
|
|
},
|
2012-10-05 05:05:49 +02:00
|
|
|
jumpToContact: function(id) {
|
2014-01-28 21:37:50 +01:00
|
|
|
this.$rightContent.scrollTop(this.contacts.contactPos(id));
|
2012-10-05 05:05:49 +02:00
|
|
|
},
|
|
|
|
closeContact: function(id) {
|
2013-02-23 22:27:04 +01:00
|
|
|
$(window).unbind('hashchange', this.hashChange);
|
2013-05-05 16:26:19 +02:00
|
|
|
if(this.currentid === 'new') {
|
2013-09-14 15:55:22 +02:00
|
|
|
this.tmpcontact.slideUp().remove();
|
2013-05-05 16:26:19 +02:00
|
|
|
this.$contactList.show();
|
|
|
|
} else {
|
2012-12-13 02:30:20 +01:00
|
|
|
var contact = this.contacts.findById(id);
|
2013-10-29 21:08:35 +01:00
|
|
|
if(contact) {
|
2014-01-25 23:54:05 +01:00
|
|
|
// Only show the list element if contact is in current group
|
|
|
|
var showListElement = contact.inGroup(this.groups.nameById(this.currentgroup))
|
|
|
|
|| this.currentgroup === 'all'
|
|
|
|
|| (this.currentgroup === 'uncategorized' && contact.groups().length === 0);
|
|
|
|
contact.close(showListElement);
|
2012-11-01 02:01:00 +01:00
|
|
|
}
|
2012-10-05 05:05:49 +02:00
|
|
|
}
|
2012-11-15 20:35:35 +01:00
|
|
|
delete this.currentid;
|
2013-04-30 20:00:33 +02:00
|
|
|
this.hideActions();
|
2012-10-05 05:05:49 +02:00
|
|
|
this.$groups.find('optgroup,option:not([value="-1"])').remove();
|
2013-03-04 17:57:46 +01:00
|
|
|
if(this.contacts.length === 0) {
|
|
|
|
$(document).trigger('status.nomorecontacts');
|
|
|
|
}
|
2013-02-23 22:27:04 +01:00
|
|
|
window.location.hash = '';
|
|
|
|
$(window).bind('hashchange', this.hashChange);
|
2012-10-05 05:05:49 +02:00
|
|
|
},
|
|
|
|
openContact: function(id) {
|
2013-10-29 21:08:35 +01:00
|
|
|
var self = this;
|
2014-03-08 09:03:28 +01:00
|
|
|
if(typeof id === 'undefined' || id === 'undefined') {
|
2013-05-09 21:18:32 +02:00
|
|
|
console.warn('id is undefined!');
|
|
|
|
console.trace();
|
|
|
|
}
|
2013-03-30 20:57:12 +01:00
|
|
|
this.hideActions();
|
2013-05-09 21:18:32 +02:00
|
|
|
console.log('Contacts.openContact', id, typeof id);
|
2014-01-28 21:21:33 +01:00
|
|
|
if(this.currentid && this.currentid !== id) {
|
2014-03-04 21:56:46 +01:00
|
|
|
this.closeContact(this.currentid);
|
2014-01-28 21:21:33 +01:00
|
|
|
}
|
2014-01-26 04:33:59 +01:00
|
|
|
this.currentid = id;
|
|
|
|
var contact = this.contacts.findById(this.currentid);
|
|
|
|
// If opened from search we can't be sure the contact is in currentgroup
|
2014-02-05 22:31:31 +01:00
|
|
|
if(!contact.inGroup(this.groups.nameById(this.currentgroup))
|
|
|
|
&& ['all', 'fav', 'uncategorized'].indexOf(this.currentgroup) === -1
|
|
|
|
) {
|
2014-01-26 04:33:59 +01:00
|
|
|
this.groups.selectGroup({id:'all'});
|
|
|
|
}
|
2013-02-23 22:27:04 +01:00
|
|
|
$(window).unbind('hashchange', this.hashChange);
|
2014-02-05 22:31:31 +01:00
|
|
|
console.assert(typeof this.currentid === 'string', 'Current ID not string:' + this.currentid);
|
2012-12-14 02:53:06 +01:00
|
|
|
// Properties that the contact doesn't know
|
|
|
|
var groupprops = {
|
2012-12-13 02:30:20 +01:00
|
|
|
favorite: this.groups.isFavorite(this.currentid),
|
|
|
|
groups: this.groups.categories,
|
2012-12-17 15:19:22 +01:00
|
|
|
currentgroup: {id:this.currentgroup, name:this.groups.nameById(this.currentgroup)}
|
2012-12-10 00:02:06 +01:00
|
|
|
};
|
2013-09-11 05:50:00 +02:00
|
|
|
if(!contact) {
|
2013-05-06 01:49:10 +02:00
|
|
|
console.warn('Error opening', this.currentid);
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', {
|
2013-05-06 01:49:10 +02:00
|
|
|
message: t('contacts', 'Could not find contact: {id}', {id:this.currentid})
|
|
|
|
});
|
|
|
|
this.currentid = null;
|
|
|
|
return;
|
|
|
|
}
|
2013-09-11 05:50:00 +02:00
|
|
|
var $contactelem = contact.renderContact(groupprops);
|
|
|
|
var $listElement = contact.getListItemElement();
|
|
|
|
console.log('selected element', $listElement);
|
2013-10-29 21:08:35 +01:00
|
|
|
window.location.hash = this.currentid;
|
|
|
|
self.jumpToContact(self.currentid);
|
2013-10-29 21:19:10 +01:00
|
|
|
$contactelem.insertAfter($listElement).show().find('.fullname').focus();
|
2013-09-11 05:50:00 +02:00
|
|
|
$listElement.hide();
|
2013-02-12 10:52:58 +01:00
|
|
|
setTimeout(function() {
|
2013-10-29 21:08:35 +01:00
|
|
|
$(window).bind('hashchange', self.hashChange);
|
2013-02-23 22:27:04 +01:00
|
|
|
}, 500);
|
2012-10-05 05:05:49 +02:00
|
|
|
},
|
2012-09-17 16:15:31 +02:00
|
|
|
update: function() {
|
|
|
|
console.log('update');
|
|
|
|
},
|
2012-11-05 12:39:12 +01:00
|
|
|
uploadPhoto:function(filelist) {
|
2013-05-19 05:19:58 +02:00
|
|
|
console.log('uploadPhoto');
|
2012-11-05 12:39:12 +01:00
|
|
|
if(!filelist) {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', {message:t('contacts','No files selected for upload.')});
|
2012-11-05 12:39:12 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var file = filelist[0];
|
|
|
|
var form = $('#file_upload_form');
|
2014-03-08 06:30:29 +01:00
|
|
|
|
2013-06-02 15:34:57 +02:00
|
|
|
if(file.size > $('#max_upload').val()) {
|
|
|
|
$(document).trigger('status.contacts.error', {
|
2012-11-05 12:39:12 +01:00
|
|
|
message:t(
|
|
|
|
'contacts',
|
2012-12-17 15:19:22 +01:00
|
|
|
'The file you are trying to upload exceed the maximum size for file uploads on this server.')
|
2012-11-05 12:39:12 +01:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
form.submit();
|
|
|
|
}
|
|
|
|
},
|
2013-04-05 04:10:32 +02:00
|
|
|
cloudPhotoSelected:function(metadata, path) {
|
2012-10-15 21:33:21 +02:00
|
|
|
var self = this;
|
2013-04-05 19:06:26 +02:00
|
|
|
console.log('cloudPhotoSelected', metadata);
|
2014-03-02 23:01:56 +01:00
|
|
|
var url = OC.generateUrl(
|
2014-03-02 23:19:01 +01:00
|
|
|
'apps/contacts/addressbook/{backend}/{addressBookId}/contact/{contactId}/photo/cacheFS',
|
2013-10-22 17:10:23 +02:00
|
|
|
{backend: metadata.backend, addressBookId: metadata.addressBookId, contactId: metadata.contactId, path: path}
|
2013-09-04 08:03:33 +02:00
|
|
|
);
|
2013-10-22 17:10:23 +02:00
|
|
|
var jqXHR = $.getJSON(url, function(response) {
|
2013-09-04 08:03:33 +02:00
|
|
|
console.log('response', response);
|
2013-10-22 17:10:23 +02:00
|
|
|
response = self.storage.formatResponse(response, jqXHR);
|
|
|
|
if(!response.error) {
|
2013-06-02 15:34:57 +02:00
|
|
|
self.editPhoto(metadata, response.data.tmp);
|
2013-09-03 14:05:00 +02:00
|
|
|
} else {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', response);
|
2012-10-15 21:33:21 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2013-04-05 04:10:32 +02:00
|
|
|
editCurrentPhoto:function(metadata) {
|
2012-09-17 16:15:31 +02:00
|
|
|
var self = this;
|
2014-03-02 23:01:56 +01:00
|
|
|
var url = OC.generateUrl(
|
2014-03-02 23:19:01 +01:00
|
|
|
'apps/contacts/addressbook/{backend}/{addressBookId}/contact/{contactId}/photo/cacheCurrent',
|
2013-10-22 17:10:23 +02:00
|
|
|
{backend: metadata.backend, addressBookId: metadata.addressBookId, contactId: metadata.contactId}
|
2013-09-04 08:03:33 +02:00
|
|
|
);
|
|
|
|
console.log('url', url);
|
2013-10-22 17:10:23 +02:00
|
|
|
var jqXHR = $.getJSON(url, function(response) {
|
2014-03-08 09:03:28 +01:00
|
|
|
response = self.storage.formatResponse(response, jqXHR);
|
2013-10-22 17:10:23 +02:00
|
|
|
if(!response.error) {
|
2013-06-02 15:34:57 +02:00
|
|
|
self.editPhoto(metadata, response.data.tmp);
|
|
|
|
} else {
|
|
|
|
$(document).trigger('status.contacts.error', response);
|
2012-10-15 21:33:21 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2013-04-05 04:10:32 +02:00
|
|
|
editPhoto:function(metadata, tmpkey) {
|
|
|
|
console.log('editPhoto', metadata, tmpkey);
|
2012-10-15 21:33:21 +02:00
|
|
|
$('.tipsy').remove();
|
|
|
|
// Simple event handler, called from onChange and onSelect
|
2013-09-04 08:03:33 +02:00
|
|
|
// event handlers, as per the Jcrop invocation below
|
2012-10-15 21:33:21 +02:00
|
|
|
var showCoords = function(c) {
|
2013-09-04 08:03:33 +02:00
|
|
|
$('#x').val(c.x);
|
|
|
|
$('#y').val(c.y);
|
2012-10-15 21:33:21 +02:00
|
|
|
$('#w').val(c.w);
|
|
|
|
$('#h').val(c.h);
|
|
|
|
};
|
|
|
|
|
|
|
|
var clearCoords = function() {
|
|
|
|
$('#coords input').val('');
|
|
|
|
};
|
2012-10-22 15:35:33 +02:00
|
|
|
|
2012-10-15 21:33:21 +02:00
|
|
|
var self = this;
|
|
|
|
if(!this.$cropBoxTmpl) {
|
|
|
|
this.$cropBoxTmpl = $('#cropBoxTemplate');
|
|
|
|
}
|
2013-05-19 05:19:58 +02:00
|
|
|
var $container = $('<div />').appendTo($('body'));
|
2014-03-02 23:01:56 +01:00
|
|
|
var url = OC.generateUrl(
|
2014-03-02 23:19:01 +01:00
|
|
|
'apps/contacts/addressbook/{backend}/{addressBookId}/contact/{contactId}/photo/{key}/crop',
|
2013-10-22 17:10:23 +02:00
|
|
|
{backend: metadata.backend, addressBookId: metadata.addressBookId, contactId: metadata.contactId, key: tmpkey}
|
2013-09-04 08:03:33 +02:00
|
|
|
);
|
2013-04-05 04:10:32 +02:00
|
|
|
var $dlg = this.$cropBoxTmpl.octemplate(
|
|
|
|
{
|
2013-09-04 08:03:33 +02:00
|
|
|
action: url,
|
2013-04-05 04:10:32 +02:00
|
|
|
backend: metadata.backend,
|
2013-04-08 22:35:28 +02:00
|
|
|
addressbookid: metadata.addressbookid,
|
2013-04-05 04:10:32 +02:00
|
|
|
contactid: metadata.contactid,
|
|
|
|
tmpkey: tmpkey
|
2013-09-04 08:03:33 +02:00
|
|
|
}).prependTo($container);
|
|
|
|
|
|
|
|
$.when(this.storage.getTempContactPhoto(
|
|
|
|
metadata.backend,
|
2013-10-22 17:10:23 +02:00
|
|
|
metadata.addressBookId,
|
|
|
|
metadata.contactId,
|
2013-09-04 08:03:33 +02:00
|
|
|
tmpkey
|
|
|
|
))
|
|
|
|
.then(function(image) {
|
|
|
|
var x = 5, y = 5, w = h = Math.min(image.width, image.height);
|
|
|
|
//$dlg.css({'min-width': w, 'min-height': h});
|
|
|
|
console.log(x,y,w,h);
|
|
|
|
$(image).attr('id', 'cropbox').prependTo($dlg).show()
|
|
|
|
.Jcrop({
|
2012-10-15 21:33:21 +02:00
|
|
|
onChange: showCoords,
|
|
|
|
onSelect: showCoords,
|
|
|
|
onRelease: clearCoords,
|
2013-09-04 08:03:33 +02:00
|
|
|
//maxSize: [w, h],
|
2012-10-15 21:33:21 +02:00
|
|
|
bgColor: 'black',
|
|
|
|
bgOpacity: .4,
|
2012-12-17 15:19:22 +01:00
|
|
|
boxWidth: 400,
|
2012-10-15 21:33:21 +02:00
|
|
|
boxHeight: 400,
|
2013-09-04 08:03:33 +02:00
|
|
|
setSelect: [ x, y, w-10, h-10 ],
|
|
|
|
aspectRatio: 1
|
2012-10-15 21:33:21 +02:00
|
|
|
});
|
2013-09-04 08:03:33 +02:00
|
|
|
$container.ocdialog({
|
2013-09-03 14:05:00 +02:00
|
|
|
modal: true,
|
|
|
|
closeOnEscape: true,
|
|
|
|
title: t('contacts', 'Edit profile picture'),
|
2013-09-15 00:58:46 +02:00
|
|
|
height: image.height+100, width: image.width+20,
|
2013-09-03 14:05:00 +02:00
|
|
|
buttons: [
|
|
|
|
{
|
2013-09-04 08:03:33 +02:00
|
|
|
text: t('contacts', 'Crop photo'),
|
2013-09-03 14:05:00 +02:00
|
|
|
click:function() {
|
2013-09-04 08:03:33 +02:00
|
|
|
self.savePhoto($(this), function() {
|
|
|
|
$container.ocdialog('close');
|
|
|
|
});
|
2013-09-03 14:05:00 +02:00
|
|
|
},
|
|
|
|
defaultButton: true
|
|
|
|
}
|
|
|
|
],
|
2014-03-08 06:30:29 +01:00
|
|
|
close: function(/*event, ui*/) {
|
2013-09-03 19:26:29 +02:00
|
|
|
$(this).ocdialog('destroy').remove();
|
2013-09-03 14:05:00 +02:00
|
|
|
$container.remove();
|
|
|
|
},
|
2014-03-08 06:30:29 +01:00
|
|
|
open: function(/*event, ui*/) {
|
2013-09-04 08:03:33 +02:00
|
|
|
showCoords({x:x,y:y,w:w-10,h:h-10});
|
2013-09-03 14:05:00 +02:00
|
|
|
}
|
|
|
|
});
|
2013-09-04 08:03:33 +02:00
|
|
|
})
|
|
|
|
.fail(function() {
|
|
|
|
console.warn('Error getting temporary photo');
|
|
|
|
});
|
2012-10-15 21:33:21 +02:00
|
|
|
},
|
2013-09-04 08:03:33 +02:00
|
|
|
savePhoto:function($dlg, cb) {
|
|
|
|
var $form = $dlg.find('#cropform');
|
|
|
|
var $target = $dlg.find('#crop_target');
|
|
|
|
console.log('target', $target);
|
|
|
|
$target.on('load', function() {
|
|
|
|
console.log('submitted');
|
|
|
|
var response = $.parseJSON($target.contents().text());
|
2013-10-22 17:10:23 +02:00
|
|
|
console.log('response', response);
|
2014-03-08 09:03:28 +01:00
|
|
|
if(response && response.status === 'success') {
|
2012-10-15 21:33:21 +02:00
|
|
|
$(document).trigger('status.contact.photoupdated', {
|
2013-04-08 22:35:28 +02:00
|
|
|
id: response.data.id,
|
|
|
|
thumbnail: response.data.thumbnail
|
2012-09-17 16:15:31 +02:00
|
|
|
});
|
2012-10-15 21:33:21 +02:00
|
|
|
} else {
|
2013-04-08 22:35:28 +02:00
|
|
|
if(!response) {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', {
|
|
|
|
message:t('contacts', 'Network or server error. Please inform administrator.')
|
|
|
|
});
|
2012-10-15 21:33:21 +02:00
|
|
|
} else {
|
2013-06-02 15:34:57 +02:00
|
|
|
$(document).trigger('status.contacts.error', response);
|
2013-03-14 23:14:48 +01:00
|
|
|
}
|
|
|
|
}
|
2013-09-04 08:03:33 +02:00
|
|
|
cb();
|
2013-03-14 23:14:48 +01:00
|
|
|
});
|
2013-09-04 08:03:33 +02:00
|
|
|
$form.submit();
|
2014-03-02 23:19:01 +01:00
|
|
|
}
|
2012-09-17 16:15:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
2014-03-02 23:19:01 +01:00
|
|
|
$.getScript(OC.generateUrl('apps/contacts/ajax/config.js'))
|
2014-03-02 23:01:56 +01:00
|
|
|
.done(function() {
|
|
|
|
OC.Contacts.init();
|
|
|
|
})
|
|
|
|
.fail(function(jqxhr, settings, exception) {
|
|
|
|
console.log('Failed loading settings.', jqxhr, settings, exception);
|
2013-03-22 14:53:27 +01:00
|
|
|
});
|
2012-09-17 16:15:31 +02:00
|
|
|
|
|
|
|
});
|