OC.Contacts = OC.Contacts || {}; OC.Contacts.Settings = OC.Contacts.Settings || { init:function() { this.Addressbook.adrsettings = $('.addressbooks-settings').first(); this.Addressbook.adractions = $('#contacts-settings').find('div.actions'); console.log('actions: ' + this.Addressbook.adractions.length); OC.Share.loadIcons('addressbook'); }, Addressbook:{ showActions:function(act) { this.adractions.children().hide(); this.adractions.children('.'+act.join(',.')).show(); }, doActivate:function(id, tgt) { var active = tgt.is(':checked'); console.log('doActivate: ', id, active); $.post(OC.filePath('contacts', 'ajax', 'addressbook/activate.php'), {id: id, active: Number(active)}, function(jsondata) { if (jsondata.status == 'success'){ if(!active) { $('#contacts h3[data-id="'+id+'"],#contacts ul[data-id="'+id+'"]').remove(); } else { OC.Contacts.Contacts.update(); } } else { console.log('Error:', jsondata.data.message); OC.Contacts.notify(t('contacts', 'Error') + ': ' + jsondata.data.message); tgt.checked = !active; } }); }, doDelete:function(id) { console.log('doDelete: ', id); var check = confirm('Do you really want to delete this address book?'); if(check == false){ return false; } else { var row = $('.addressbooks-settings tr[data-id="'+id+'"]'); OC.Contacts.loading(row.find('.name')); $.post(OC.filePath('contacts', 'ajax', 'addressbook/delete.php'), { id: id}, function(jsondata) { if (jsondata.status == 'success'){ $('#contacts h3[data-id="'+id+'"],#contacts ul[data-id="'+id+'"]').remove(); row.remove() OC.Contacts.Settings.Addressbook.showActions(['new',]); OC.Contacts.Contacts.update(); } else { OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); } }); } }, doEdit:function(id) { console.log('doEdit: ', id); var owner = this.adrsettings.find('[data-id="'+id+'"]').data('owner'); var actions = ['description', 'save', 'cancel']; if(owner == OC.currentUser || id === 'new') { actions.push('active', 'name'); } this.showActions(actions); var name = this.adrsettings.find('[data-id="'+id+'"]').find('.name').text(); var description = this.adrsettings.find('[data-id="'+id+'"]').find('.description').text(); var active = this.adrsettings.find('[data-id="'+id+'"]').find(':checkbox').is(':checked'); console.log('name, desc', name, description); this.adractions.find('.active').prop('checked', active); this.adractions.find('.name').val(name); this.adractions.find('.description').val(description); this.adractions.data('id', id); }, doSave:function() { var name = this.adractions.find('.name').val(); var description = this.adractions.find('.description').val(); var active = this.adractions.find('.active').is(':checked'); var id = this.adractions.data('id'); console.log('doSave:', id, name, description, active); if(name.length == 0) { OC.dialogs.alert(t('contacts', 'Displayname cannot be empty.'), t('contacts', 'Error')); return false; } var url; if (id == 'new'){ url = OC.filePath('contacts', 'ajax', 'addressbook/add.php'); }else{ url = OC.filePath('contacts', 'ajax', 'addressbook/update.php'); } self = this; $.post(url, { id: id, name: name, active: Number(active), description: description }, function(jsondata){ if(jsondata.status == 'success'){ self.showActions(['new',]); self.adractions.removeData('id'); active = Boolean(Number(jsondata.data.addressbook.active)); if(id == 'new') { self.adrsettings.find('table') .append('