summaryrefslogtreecommitdiffstats
path: root/apps/contacts/js/interface.js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/contacts/js/interface.js')
-rw-r--r--apps/contacts/js/interface.js120
1 files changed, 120 insertions, 0 deletions
diff --git a/apps/contacts/js/interface.js b/apps/contacts/js/interface.js
index eb81e872682..02470d5a767 100644
--- a/apps/contacts/js/interface.js
+++ b/apps/contacts/js/interface.js
@@ -1,3 +1,118 @@
+Contacts={
+ UI:{
+ showCardDAVUrl:function(username, bookname){
+ $('#carddav_url').val(totalurl + '/' + username + '/' + bookname);
+ $('#carddav_url').show();
+ $('#carddav_url_close').show();
+ },
+ Addressbooks:{
+ overview:function(){
+ if($('#chooseaddressbook_dialog').dialog('isOpen') == true){
+ $('#chooseaddressbook_dialog').dialog('moveToTop');
+ }else{
+ $('#dialog_holder').load(OC.filePath('contacts', 'ajax', 'chooseaddressbook.php'), function(){
+ $('#chooseaddressbook_dialog').dialog({
+ width : 600,
+ close : function(event, ui) {
+ $(this).dialog('destroy').remove();
+ }
+ });
+ });
+ }
+ },
+ activation:function(checkbox, bookid)
+ {
+ $.post(OC.filePath('contacts', 'ajax', 'activation.php'), { bookid: bookid, active: checkbox.checked?1:0 },
+ function(data) {
+ /*
+ * Arguments:
+ * data.status
+ * data.bookid
+ * data.active
+ */
+ if (data.status == 'success'){
+ checkbox.checked = data.active == 1;
+ Contacts.UI.Contacts.update();
+ }
+ });
+ },
+ newAddressbook:function(object){
+ var tr = $(document.createElement('tr'))
+ .load(OC.filePath('contacts', 'ajax', 'addbook.php'));
+ $(object).closest('tr').after(tr).hide();
+ /* TODO: Shouldn't there be some kinda error checking here? */
+ },
+ editAddressbook:function(object, bookid){
+ var tr = $(document.createElement('tr'))
+ .load(OC.filePath('contacts', 'ajax', 'editaddressbook.php') + "?bookid="+bookid);
+ $(object).closest('tr').after(tr).hide();
+ },
+ deleteAddressbook:function(bookid){
+ var check = confirm("Do you really want to delete this address book?");
+ if(check == false){
+ return false;
+ }else{
+ $.post(OC.filePath('contacts', 'ajax', 'deletebook.php'), { id: bookid},
+ function(data) {
+ if (data.status == 'success'){
+ $('#chooseaddressbook_dialog').dialog('destroy').remove();
+ Contacts.UI.Contacts.update();
+ Contacts.UI.Addressbooks.overview();
+ } else {
+ alert('Error: ' + data.message);
+ }
+ });
+ }
+ },
+ submit:function(button, bookid){
+ var displayname = $("#displayname_"+bookid).val();
+ var active = $("#edit_active_"+bookid+":checked").length;
+ var description = $("#description_"+bookid).val();
+
+ var url;
+ if (bookid == 'new'){
+ url = OC.filePath('contacts', 'ajax', 'createaddressbook.php');
+ }else{
+ url = OC.filePath('contacts', 'ajax', 'updateaddressbook.php');
+ }
+ $.post(url, { id: bookid, name: displayname, active: active, description: description },
+ function(data){
+ if(data.status == 'success'){
+ $(button).closest('tr').prev().html(data.page).show().next().remove();
+ }
+ });
+ Contacts.UI.Contacts.update();
+ },
+ cancel:function(button, bookid){
+ $(button).closest('tr').prev().show().next().remove();
+ }
+ },
+ Contacts:{
+ update:function(){
+ $.getJSON('ajax/contacts.php',{},function(jsondata){
+ if(jsondata.status == 'success'){
+ $('#contacts').html(jsondata.data.page);
+ }
+ else{
+ alert(jsondata.data.message);
+ }
+ });
+ /*
+ var contactlist = $('#contacts');
+ var contacts = contactlist.children('li').get();
+ //alert(contacts);
+ contacts.sort(function(a, b) {
+ var compA = $(a).text().toUpperCase();
+ var compB = $(b).text().toUpperCase();
+ return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
+ })
+ $.each(contacts, function(idx, itm) { contactlist.append(itm); });
+ */
+ }
+ }
+ }
+}
+
$(document).ready(function(){
/*-------------------------------------------------------------------------
* Event handlers
@@ -79,6 +194,11 @@ $(document).ready(function(){
return false;
});
+ $('#chooseaddressbook').click(function(){
+ Contacts.UI.Addressbooks.overview();
+ return false;
+ });
+
$('#contacts_newcontact').click(function(){
$.getJSON('ajax/showaddcard.php',{},function(jsondata){
if(jsondata.status == 'success'){