1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-11-29 11:24:11 +01:00

put dialog UI functions in a new js class

change addressbook name in UI when changed
This commit is contained in:
babelouest 2014-04-07 01:18:09 -04:00
parent 57211530f8
commit 489aaa1eae
3 changed files with 356 additions and 386 deletions

View File

@ -69,36 +69,37 @@ OC.Contacts = OC.Contacts || {};
}); });
}); });
$('#add-address-book-element').on('click keypress', function() { $('#add-address-book-element').on('click keypress', function() {
console.log('OC.Contacts', OC.Contacts);
$("#addressbooks-ui") $("#addressbooks-ui")
.dialog({ .dialog({
title:"Add new Addressbook", title:"Add new Addressbook",
close: function() { $(this).hide() }, close: function() { $(this).hide(); },
modal: false, modal: false,
width: 'auto', width: 'auto',
height: 'auto', height: 'auto',
position: ['top', 100], position: ['top', 100],
buttons: { buttons: {
Ok: function() { Ok: function() {
addressbookUiOk(); OC.Contacts.addressBookDialog.addressbookUiOk();
}, },
Cancel: function() { Cancel: function() {
addressbookUiCancel(); OC.Contacts.addressBookDialog.addressbookUiCancel();
} }
}, },
open: openAddressbookUi() open: function() {
OC.Contacts.addressBookDialog.openAddressbookUi();
}
}); });
}); });
this.$li.find('a.action.edit').on('click keypress', function(event) { this.$li.find('a.action.edit').on('click keypress', function(/*event*/) {
$.when(self.storage.getAddressBook(self.getBackend(), self.getId())) $.when(self.storage.getAddressBook(self.getBackend(), self.getId()))
.then(function(response) { .then(function(response) {
if(!response.error) { if(!response.error) {
if(response.data) { if(response.data) {
var addressbook = response.data; var addressbook = response.data;
console.log('addressbook', addressbook); console.log('addressbook', addressbook);
$("#addressbooks-ui") $('#addressbooks-ui')
.dialog({ .dialog({
title:"Edit Addressbook", title:'Edit Addressbook',
close: function() { $(this).hide() }, close: function() { $(this).hide() },
modal: false, modal: false,
width: 'auto', width: 'auto',
@ -106,15 +107,15 @@ OC.Contacts = OC.Contacts || {};
position: ['top', 100], position: ['top', 100],
buttons: { buttons: {
Ok: function() { Ok: function() {
addressbookUiEditOk(); OC.Contacts.addressBookDialog.addressbookUiEditOk();
self.setDisplayName($('#addressbooks-ui-name').val());
}, },
Cancel: function() { Cancel: function() {
addressbookUiCancel(); OC.Contacts.addressBookDialog.addressbookUiCancel();
} }
}, },
open: editAddressbookUI(addressbook) open: OC.Contacts.addressBookDialog.editAddressbookUI(addressbook)
}); });
//self.insertContacts(response.data.contacts);
} }
} else { } else {
console.warn('Addressbook getAddressbook - no data !!'); console.warn('Addressbook getAddressbook - no data !!');
@ -124,41 +125,6 @@ OC.Contacts = OC.Contacts || {};
console.warn('Request Failed:', response.message); console.warn('Request Failed:', response.message);
$(document).trigger('status.contacts.error', response); $(document).trigger('status.contacts.error', response);
}); });
// TODO: remove this mock value
/*if($(this).data('open')) {
return;
}
var editor = this;
event.stopPropagation();
event.preventDefault();
var $dropdown = $('<li><div><input type="text" value="{name}" /></div></li>')
.octemplate({name:self.getDisplayName()}).insertAfter(self.$li);
var $input = $dropdown.find('input');
//$input.focus().get(0).select();
$input.addnew({
autoOpen: true,
//autoClose: false,
addText: t('contacts', 'Save'),
ok: function(event, name) {
console.log('edit-address-book ok', name);
$input.addClass('loading');
self.update({displayname:name}, function(response) {
console.log('response', response);
if(response.error) {
$(document).trigger('status.contacts.error', response);
} else {
self.setDisplayName(response.data.displayname);
$input.addnew('close');
}
$input.removeClass('loading');
});
},
close: function() {
$dropdown.remove();
$(editor).data('open', false);
}
});
$(this).data('open', true);*/
}); });
return this.$li; return this.$li;
}; };
@ -355,7 +321,7 @@ OC.Contacts = OC.Contacts || {};
}); });
this.$importFileInput.fileupload({ this.$importFileInput.fileupload({
dataType: 'json', dataType: 'json',
start: function(e, data) { start: function(/*e, data*/) {
self.$importProgress.progressbar({value:false}); self.$importProgress.progressbar({value:false});
$('.tipsy').remove(); $('.tipsy').remove();
$('.import-upload').hide(); $('.import-upload').hide();

View File

@ -168,6 +168,7 @@ OC.notify = function(params) {
$('#app-settings-content'), $('#app-settings-content'),
$('#addressBookTemplate') $('#addressBookTemplate')
); );
this.addressBookDialog = new OC.Contacts.AddressBookDialog();
this.contacts = new OC.Contacts.ContactList( this.contacts = new OC.Contacts.ContactList(
this.storage, this.storage,
this.addressBooks, this.addressBooks,

View File

@ -1,5 +1,15 @@
OC.Contacts = OC.Contacts || {};
function openAddressbookUi() { (function(window, $, OC) {
'use strict';
var AddressBookDialog = function() {
};
OC.Contacts.AddressBookDialog = AddressBookDialog;
AddressBookDialog.prototype.openAddressbookUi = function() {
var self = this;
$('#addressbooks-ui')[0].reset(); $('#addressbooks-ui')[0].reset();
$('#addressbooks-ui-uri').attr('disabled', false); $('#addressbooks-ui-uri').attr('disabled', false);
$('#addressbooks-ui-ldapanonymous').attr('checked', false); $('#addressbooks-ui-ldapanonymous').attr('checked', false);
@ -9,16 +19,16 @@ function openAddressbookUi() {
$('#addressbooks-ui-ldapbasednmodify').attr('disabled', false); $('#addressbooks-ui-ldapbasednmodify').attr('disabled', false);
$('#addressbooks-ui-backend').change(function() { $('#addressbooks-ui-backend').change(function() {
storage = new OC.Contacts.Storage(); var storage = OC.Contacts.storage;
addressbookUiInit(); self.addressbookUiInit();
$.when(storage.getConnectors($('#addressbooks-ui-backend').val())) $.when(storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) { .then(function(response) {
$('#addressbooks-ui-ldapvcardconnector').empty(); $('#addressbooks-ui-ldapvcardconnector').empty();
for (id in response.data) { for (var id in response.data) {
var $option = $('<option value="' + response.data[id]["id"] + '">' + response.data[id]["name"] + '</option>'); var $option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>');
$('#addressbooks-ui-ldapvcardconnector').append($option); $('#addressbooks-ui-ldapvcardconnector').append($option);
} }
var $option = $('<option value="">' + 'Custom connector' + '</option>'); $option = $('<option value="">' + 'Custom connector' + '</option>');
$('#addressbooks-ui-ldapvcardconnector').append($option); $('#addressbooks-ui-ldapvcardconnector').append($option);
}) })
.fail(function(jqxhr, textStatus, error) { .fail(function(jqxhr, textStatus, error) {
@ -27,21 +37,21 @@ function openAddressbookUi() {
defer.reject({error:true, message:error}); defer.reject({error:true, message:error});
}); });
}); });
addressbookUiInit(); this.addressbookUiInit();
} }
function editAddressbookUI(addressbook) { AddressBookDialog.prototype.editAddressbookUI = function(addressbook) {
storage = new OC.Contacts.Storage(); var storage = OC.Contacts.storage;
$('#addressbooks-ui-addressbookid').val(addressbook.id); $('#addressbooks-ui-addressbookid').val(addressbook.id);
$('#addressbooks-ui-backend option[value='+addressbook.backend+']').prop('selected', true); $('#addressbooks-ui-backend option[value='+addressbook.backend+']').prop('selected', true);
$('#addressbooks-ui-backend').prop('disabled', true); $('#addressbooks-ui-backend').prop('disabled', true);
$('#addressbooks-ui-name').val(addressbook.displayname); $('#addressbooks-ui-name').val(addressbook.displayname);
if (addressbook.backend == 'ldap') { if (addressbook.backend === 'ldap') {
$('#addressbooks-ui-uri').val(addressbook.uri); $('#addressbooks-ui-uri').val(addressbook.uri);
$('#addressbooks-ui-description').val(addressbook.description); $('#addressbooks-ui-description').val(addressbook.description);
$('#addressbooks-ui-ldapurl').val(addressbook.ldapurl); $('#addressbooks-ui-ldapurl').val(addressbook.ldapurl);
$('#addressbooks-ui-ldapanonymous').attr('checked', (addressbook.ldapanonymous==true)); $('#addressbooks-ui-ldapanonymous').attr('checked', (addressbook.ldapanonymous===true));
$('#addressbooks-ui-ldapreadonly').attr('checked', (addressbook.ldapreadonly==true)); $('#addressbooks-ui-ldapreadonly').attr('checked', (addressbook.ldapreadonly===true));
$('#addressbooks-ui-ldapuser').val(addressbook.ldapuser); $('#addressbooks-ui-ldapuser').val(addressbook.ldapuser);
$('#addressbooks-ui-ldappass').val('nochange'); $('#addressbooks-ui-ldappass').val('nochange');
$('#addressbooks-ui-ldappass-modified').val('false'); $('#addressbooks-ui-ldappass-modified').val('false');
@ -72,13 +82,13 @@ function editAddressbookUI(addressbook) {
$('#addressbooks-ui-ldapvcardconnector').empty(); $('#addressbooks-ui-ldapvcardconnector').empty();
var custom = true; var custom = true;
console.log('addressbook.ldapconnectorid', addressbook.ldapconnectorid); console.log('addressbook.ldapconnectorid', addressbook.ldapconnectorid);
for (id in response.data) { for (var id in response.data) {
console.log('response.data[id][\'id\']', response.data[id]['id']); console.log('response.data[id][\'id\']', response.data[id].id);
if (response.data[id]['id'] == addressbook.ldapconnectorid) { if (response.data[id].id === addressbook.ldapconnectorid) {
var $option = $('<option value="' + response.data[id]['id'] + '">' + response.data[id]['name'] + '</option>').attr('selected','selected'); var $option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>').attr('selected','selected');
custom = false; custom = false;
} else { } else {
var $option = $('<option value="' + response.data[id]['id'] + '">' + response.data[id]['name'] + '</option>'); $option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>');
} }
$('#addressbooks-ui-ldapvcardconnector').append($option); $('#addressbooks-ui-ldapvcardconnector').append($option);
} }
@ -92,7 +102,7 @@ function editAddressbookUI(addressbook) {
var $option = $('<option value="">' + 'Select connector' + '</option>').attr('selected','selected'); var $option = $('<option value="">' + 'Select connector' + '</option>').attr('selected','selected');
$('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option); $('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option);
for (id in response.data) { for (id in response.data) {
var $option = $('<option value="' + response.data[id]['id'] + '">' + response.data[id]['name'] + '</option>'); $option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>');
$('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option); $('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option);
} }
}) })
@ -102,13 +112,13 @@ function editAddressbookUI(addressbook) {
defer.reject({error:true, message:error}); defer.reject({error:true, message:error});
}); });
$('#addressbooks-ui-ldapvcardconnector-copyfrom').change(function() { $('#addressbooks-ui-ldapvcardconnector-copyfrom').change(function() {
if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() != '') { if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() !== '') {
$.when(storage.getConnectors($('#addressbooks-ui-backend').val())) $.when(storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) { .then(function(response) {
for (id in response.data) { for (id in response.data) {
if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() == response.data[id]['id']) { if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() === response.data[id].id) {
console.log(response.data[id]['id']); console.log(response.data[id].id);
$('#addressbooks-ui-ldapvcardconnector-value').text(response.data[id]['xml']); $('#addressbooks-ui-ldapvcardconnector-value').text(response.data[id].xml);
} }
} }
}) })
@ -132,22 +142,22 @@ function editAddressbookUI(addressbook) {
defer.reject({error:true, message:error}); defer.reject({error:true, message:error});
}); });
} }
addressbookUiInit(); this.addressbookUiInit();
} }
function addressbookUiOk() { AddressBookDialog.prototype.addressbookUiOk = function() {
storage = new OC.Contacts.Storage();
//addressbook = new OC.Contacts.AddressBook();
var defer = $.Deferred(); var defer = $.Deferred();
var storage = OC.Contacts.storage;
var addressbook = OC.Contacts.addressBooks;
$.when(storage.addAddressBook($('#addressbooks-ui-backend').val(), $.when(storage.addAddressBook($('#addressbooks-ui-backend').val(),
{ {
displayname: $('#addressbooks-ui-name').val(), displayname: $('#addressbooks-ui-name').val(),
description: $('#addressbooks-ui-description').val(), description: $('#addressbooks-ui-description').val(),
uri: ($('#addressbooks-ui-uri').val()=='')?$('#addressbooks-ui-name').val():$('#addressbooks-ui-uri').val(), uri: ($('#addressbooks-ui-uri').val()==='')?$('#addressbooks-ui-name').val():$('#addressbooks-ui-uri').val(),
ldapurl: $('#addressbooks-ui-ldapurl').val(), ldapurl: $('#addressbooks-ui-ldapurl').val(),
ldapanonymous: $('#addressbooks-ui-ldapanonymous').prop('checked')==true?'true':'false', ldapanonymous: $('#addressbooks-ui-ldapanonymous').prop('checked')===true?'true':'false',
ldapreadonly: $('#addressbooks-ui-ldapreadonly').prop('checked')==true?'true':'false', ldapreadonly: $('#addressbooks-ui-ldapreadonly').prop('checked')===true?'true':'false',
ldapuser: $('#addressbooks-ui-ldapuser').val(), ldapuser: $('#addressbooks-ui-ldapuser').val(),
ldappass: $('#addressbooks-ui-ldappass').val(), ldappass: $('#addressbooks-ui-ldappass').val(),
ldappagesize: $('#addressbooks-ui-ldappagesize').val(), ldappagesize: $('#addressbooks-ui-ldappagesize').val(),
@ -165,13 +175,13 @@ function addressbookUiOk() {
} }
defer.reject(response); defer.reject(response);
} else { } else {
var book = OC.Contacts.addressBooks.insertAddressBook(response.data); var book = addressbook.insertAddressBook(response.data);
$(document).trigger('status.addressbook.added'); $(document).trigger('status.addressbook.added');
if(typeof cb === 'function') { if(typeof cb === 'function') {
cb({error:false, addressbook: book}); cb({error:false, addressbook: book});
} }
defer.resolve({error:false, addressbook: book}); defer.resolve({error:false, addressbook: book});
$("#addressbooks-ui").dialog('close'); $('#addressbooks-ui').dialog('close');
} }
}) })
.fail(function(jqxhr, textStatus, error) { .fail(function(jqxhr, textStatus, error) {
@ -186,11 +196,9 @@ function addressbookUiOk() {
}); });
} }
function addressbookUiEditOk() { AddressBookDialog.prototype.addressbookUiEditOk = function() {
storage = new OC.Contacts.Storage(); var storage = OC.Contacts.storage;
//addressbook = new OC.Contacts.Addressbook();
var defer = $.Deferred(); var defer = $.Deferred();
console.log($("#addressbooks-ui-addressbookid").val())
$.when(storage.updateAddressBook($('#addressbooks-ui-backend').val(), $('#addressbooks-ui-addressbookid').val(), $.when(storage.updateAddressBook($('#addressbooks-ui-backend').val(), $('#addressbooks-ui-addressbookid').val(),
{ {
@ -198,8 +206,8 @@ function addressbookUiEditOk() {
description: $('#addressbooks-ui-description').val(), description: $('#addressbooks-ui-description').val(),
uri: $('#addressbooks-ui-uri').val(), uri: $('#addressbooks-ui-uri').val(),
ldapurl: $('#addressbooks-ui-ldapurl').val(), ldapurl: $('#addressbooks-ui-ldapurl').val(),
ldapanonymous: $('#addressbooks-ui-ldapanonymous').prop('checked')==true?'true':'false', ldapanonymous: $('#addressbooks-ui-ldapanonymous').prop('checked')===true?'true':'false',
ldapreadonly: $('#addressbooks-ui-ldapreadonly').prop('checked')==true?'true':'false', ldapreadonly: $('#addressbooks-ui-ldapreadonly').prop('checked')===true?'true':'false',
ldapuser: $('#addressbooks-ui-ldapuser').val(), ldapuser: $('#addressbooks-ui-ldapuser').val(),
ldappassmodified: $('#addressbooks-ui-ldappass-modified').val(), ldappassmodified: $('#addressbooks-ui-ldappass-modified').val(),
ldappass: $('#addressbooks-ui-ldappass').val(), ldappass: $('#addressbooks-ui-ldappass').val(),
@ -218,12 +226,6 @@ function addressbookUiEditOk() {
} }
defer.reject(response); defer.reject(response);
} else { } else {
/*var book = addressbook.insertAddressBook(response.data);
$(document).trigger('status.addressbook.added');
if(typeof cb === 'function') {
cb({error:false, addressbook: book});
}
defer.resolve({error:false, addressbook: book});*/
$("#addressbooks-ui").dialog('close'); $("#addressbooks-ui").dialog('close');
} }
}) })
@ -239,12 +241,11 @@ function addressbookUiEditOk() {
}); });
} }
function addressbookUiCancel() { AddressBookDialog.prototype.addressbookUiCancel = function() {
$('#addressbooks-ui').dialog('close'); $('#addressbooks-ui').dialog('close');
} }
function addressbookUiInit() { AddressBookDialog.prototype.addressbookUiInit = function() {
storage = new OC.Contacts.Storage();
if ($('#addressbooks-ui-backend').val() == 'local') { if ($('#addressbooks-ui-backend').val() == 'local') {
$('#addressbooks-ui-uri-p').hide(); $('#addressbooks-ui-uri-p').hide();
@ -314,13 +315,13 @@ function addressbookUiInit() {
$('#addressbooks-ui-ldapvcardconnector-value-p').show(); $('#addressbooks-ui-ldapvcardconnector-value-p').show();
$('#addressbooks-ui-ldapvcardconnector-value').text(''); $('#addressbooks-ui-ldapvcardconnector-value').text('');
$('#addressbooks-ui-ldapvcardconnector-copyfrom-p').show(); $('#addressbooks-ui-ldapvcardconnector-copyfrom-p').show();
$.when(storage.getConnectors($('#addressbooks-ui-backend').val())) $.when(this.storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) { .then(function(response) {
$('#addressbooks-ui-ldapvcardconnector-copyfrom').empty(); $('#addressbooks-ui-ldapvcardconnector-copyfrom').empty();
var $option = $('<option value="">' + 'Select connector' + '</option>').attr('selected','selected'); var $option = $('<option value="">' + 'Select connector' + '</option>').attr('selected','selected');
$('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option); $('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option);
for (id in response.data) { for (id in response.data) {
var $option = $('<option value="' + response.data[id]['id'] + '">' + response.data[id]['name'] + '</option>'); var $option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>');
$('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option); $('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option);
} }
}) })
@ -331,12 +332,12 @@ function addressbookUiInit() {
}); });
$('#addressbooks-ui-ldapvcardconnector-copyfrom').change(function() { $('#addressbooks-ui-ldapvcardconnector-copyfrom').change(function() {
if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() != '') { if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() != '') {
$.when(storage.getConnectors($('#addressbooks-ui-backend').val())) $.when(this.storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) { .then(function(response) {
for (id in response.data) { for (id in response.data) {
if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() == response.data[id]['id']) { if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() == response.data[id].id) {
console.log(response.data[id]['id']); console.log(response.data[id].id);
$('#addressbooks-ui-ldapvcardconnector-value').text(response.data[id]['xml']); $('#addressbooks-ui-ldapvcardconnector-value').text(response.data[id].xml);
} }
} }
}) })
@ -350,3 +351,5 @@ function addressbookUiInit() {
} }
}); });
} }
})(window, jQuery, OC);