diff --git a/css/contacts.css b/css/contacts.css index 5867cd5a..9a1a2526 100644 --- a/css/contacts.css +++ b/css/contacts.css @@ -31,8 +31,8 @@ } #content textarea { font-family: inherit; } -#content input:-moz-placeholder #content ::-moz-placeholder, #content input[placeholder], #content input:placeholder, #content input:-ms-input-placeholder, #content input::-webkit-input-placeholder, #content input:-moz-placeholder { - color: #aaa; +#content ::-moz-placeholder, #content input:-moz-placeholder, #content input[placeholder], #content input:placeholder, #content input:-ms-input-placeholder, #content input::-webkit-input-placeholder, #content input:-moz-placeholder { + color: #bbb; text-overflow: ellipsis; } @@ -146,6 +146,11 @@ /* reset box-sizing for multiSelect */ #content div.multiselect, #content div.multiselect > * { -webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box; } + +/* Reset values for jquery.multiselect */ +.ui-multiselect-checkboxes label { width: 100%; color: #333; font-size: 1em !important; } +.ui-multiselect-checkboxes input[type="checkbox"] { margin: 3px !important; } + #content .multiselectoptions > li > * { -webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box; color: #888888; diff --git a/index.php b/index.php index b28e3c03..4e80db04 100644 --- a/index.php +++ b/index.php @@ -48,6 +48,7 @@ $freeSpace=max($freeSpace, 0); $maxUploadFilesize = min($maxUploadFilesize, $freeSpace); OCP\Util::addscript('contacts', 'multiselect'); +OCP\Util::addscript('', 'jquery.multiselect'); OCP\Util::addscript('', 'oc-vcategories'); OCP\Util::addscript('contacts', 'modernizr.custom'); OCP\Util::addscript('contacts', 'app'); @@ -58,6 +59,7 @@ OCP\Util::addscript('contacts', 'jquery.combobox'); OCP\Util::addscript('files', 'jquery.fileupload'); OCP\Util::addscript('contacts', 'jquery.Jcrop'); OCP\Util::addStyle('contacts', 'multiselect'); +OCP\Util::addStyle('', 'jquery.multiselect'); OCP\Util::addStyle('contacts', 'jquery.combobox'); OCP\Util::addStyle('contacts', 'jquery.Jcrop'); OCP\Util::addStyle('contacts', 'contacts'); diff --git a/js/app.js b/js/app.js index ba8334e6..5b76d05f 100644 --- a/js/app.js +++ b/js/app.js @@ -389,8 +389,14 @@ OC.Contacts = OC.Contacts || { }); $(document).bind('request.contact.addtogroup', function(e, data) { - console.log('contact', data.id, 'request.contact.addtogroup'); - self.groups.addTo(data.id, data.groupid); + 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); }); $(document).bind('request.contact.export', function(e, data) { diff --git a/js/contacts.js b/js/contacts.js index a0f18b30..7e5d4bde 100644 --- a/js/contacts.js +++ b/js/contacts.js @@ -225,10 +225,6 @@ OC.Contacts = OC.Contacts || {}; var q = ''; if(params.obj) { obj = params.obj; - if($(obj).is('select')) { - console.warn('Group adding will have to be refactored.'); - return; - } q = this.queryStringFor(obj); element = this.propertyTypeFor(obj); } else { @@ -476,17 +472,17 @@ OC.Contacts = OC.Contacts || {}; self.access.id = parseInt(jsondata.data.aid); self.data = jsondata.data.details; // Add contact to current group - if(self.groupprops && self.groupprops.currentgroup.name !== 'all' - && self.groupprops.currentgroup.name !== 'fav') { + if(self.groupprops && self.groupprops.currentgroup.id !== 'all' + && self.groupprops.currentgroup.id !== 'fav') { if(!self.data.CATEGORIES) { - self.data.CATEGORIES = [{value:[self.groupprops.currentgroup.name], parameters:[]}]; - // Save to vCard - self.saveProperty({name:'CATEGORIES', value:self.data.CATEGORIES[0].value.join(',') }); - // Tell OC.Contacts to save in backend + self.addToGroup(self.groupprops.currentgroup.name); $(document).trigger('request.contact.addtogroup', { id: self.id, groupid: self.groupprops.currentgroup.id }); + self.$groupSelect.find('option[value="' + self.groupprops.currentgroup.id + '"]') + .attr('selected', 'selected'); + self.$groupSelect.multiselect('refresh'); } } $(document).trigger('status.contact.added', { @@ -579,25 +575,16 @@ OC.Contacts = OC.Contacts || {}; return $container.is('input') ? $container.val() : (function() { - if($container.is('select[data-element="categories"]')) { - console.warn('Group adding will have to be refactored.'); - retval = {}; - $.each($container.find(':selected'), function(idx, e) { - retval[$(e).val()] = $(e).text(); + var $elem = $container.find('textarea.value,input.value:not(:checkbox)'); + console.assert($elem.length > 0, 'Couldn\'t find value for ' + $container.data('element')); + if($elem.length === 1) { + return $elem.val(); + } else if($elem.length > 1) { + var retval = []; + $.each($elem, function(idx, e) { + retval.push($(e).val()); }); return retval; - } else { - var $elem = $container.find('textarea.value,input.value:not(:checkbox)'); - console.assert($elem.length > 0, 'Couldn\'t find value for ' + $container.data('element')); - if($elem.length === 1) { - return $elem.val(); - } else if($elem.length > 1) { - var retval = []; - $.each($elem, function(idx, e) { - retval.push($(e).val()); - }); - return retval; - } } })(); }; @@ -660,13 +647,33 @@ OC.Contacts = OC.Contacts || {}; var self = this; this.groupprops = groupprops; - var buildGroupSelect = function($groupSelect, availableGroups) { + var buildGroupSelect = function(availableGroups) { + //this.$groupSelect.find('option').remove(); $.each(availableGroups, function(idx, group) { var $option = $(''); if(self.inGroup(group.name)) { $option.attr('selected', 'selected'); } - $groupSelect.append($option); + self.$groupSelect.append($option); + }); + self.$groupSelect.multiselect({ + header: false, + selectedList: 3, + noneSelectedText: self.$groupSelect.attr('title'), + selectedText: t('contacts', '# groups') + }); + self.$groupSelect.bind('multiselectclick', function(event, ui) { + var action = ui.checked ? 'addtogroup' : 'removefromgroup'; + console.assert(typeof self.id === 'number', 'ID is not a number') + $(document).trigger('request.contact.' + action, { + id: self.id, + groupid: parseInt(ui.value) + }); + if(ui.checked) { + self.addToGroup(ui.text); + } else { + self.removeFromGroup(ui.text); + } }); }; @@ -699,8 +706,7 @@ OC.Contacts = OC.Contacts || {}; }); this.$groupSelect = this.$fullelem.find('#contactgroups'); - buildGroupSelect(this.$groupSelect, groupprops.groups); - this.$groupSelect.multiSelect(); + buildGroupSelect(groupprops.groups); this.$addMenu = this.$fullelem.find('#addproperty'); this.$addMenu.on('change', function(event) { @@ -1656,7 +1662,7 @@ OC.Contacts = OC.Contacts || {}; self.contacts[parseInt(contact.id)] = new Contact( self, - contact.id, + parseInt(contact.id), self.addressbooks[parseInt(contact.aid)], contact.data, self.$contactListItemTemplate, diff --git a/js/groups.js b/js/groups.js index b0b0fecc..0e496941 100644 --- a/js/groups.js +++ b/js/groups.js @@ -206,6 +206,8 @@ OC.Contacts = OC.Contacts || {}; cb({status:'error', message:t('contacts', 'Contacts are already in this group.')}); } } + } else { + console.warn('Invalid data type: ' + typeof contactid); } if(doPost) { $.post(OC.filePath('contacts', 'ajax', 'categories/addto.php'), {contactids: ids, categoryid: groupid},function(jsondata) { diff --git a/templates/contacts.php b/templates/contacts.php index 82ec67b8..697879b2 100644 --- a/templates/contacts.php +++ b/templates/contacts.php @@ -175,9 +175,6 @@