]> source.dussan.org Git - nextcloud-server.git/commitdiff
Added UI for selecting/editing address books.
authorThomas Tanghus <thomas@tanghus.net>
Sun, 4 Dec 2011 19:25:46 +0000 (20:25 +0100)
committerThomas Tanghus <thomas@tanghus.net>
Sun, 4 Dec 2011 19:25:46 +0000 (20:25 +0100)
Export, CardDAV link and activation/deactivation of address books done.

apps/contacts/ajax/activation.php [new file with mode: 0644]
apps/contacts/ajax/addbook.php [new file with mode: 0644]
apps/contacts/ajax/chooseaddressbook.php [new file with mode: 0644]
apps/contacts/css/styles.css
apps/contacts/index.php
apps/contacts/js/interface.js
apps/contacts/lib/addressbook.php
apps/contacts/templates/index.php
apps/contacts/templates/part.chooseaddressbook.php [new file with mode: 0644]
apps/contacts/templates/part.chooseaddressbook.rowfields.php [new file with mode: 0644]
apps/contacts/templates/part.editaddressbook.php [new file with mode: 0644]

diff --git a/apps/contacts/ajax/activation.php b/apps/contacts/ajax/activation.php
new file mode 100644 (file)
index 0000000..6e13769
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+/**
+ * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net>
+ * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+require_once ("../../../lib/base.php");
+if(!OC_USER::isLoggedIn()) {
+       die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
+}
+OC_JSON::checkAppEnabled('contacts');
+$bookid = $_POST['bookid'];
+OC_Contacts_Addressbook::setActive($bookid, $_POST['active']);
+$book = OC_Contacts_Addressbook::find($bookid);
+
+/* is there an OC_JSON::error() ? */
+OC_JSON::success(array(
+       'active' => $book['active'],
+       'bookid' => $bookid,
+));
diff --git a/apps/contacts/ajax/addbook.php b/apps/contacts/ajax/addbook.php
new file mode 100644 (file)
index 0000000..ce74ccf
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+/**
+ * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+require_once('../../../lib/base.php');
+$l10n = new OC_L10N('contacts');
+if(!OC_USER::isLoggedIn()) {
+       die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
+}
+OC_JSON::checkAppEnabled('contacts');
+$tmpl = new OC_Template('contacts', 'part.editaddressbook');
+$tmpl->assign('new', true);
+$tmpl->assign('book', $book);
+$tmpl->printPage();
+?>
diff --git a/apps/contacts/ajax/chooseaddressbook.php b/apps/contacts/ajax/chooseaddressbook.php
new file mode 100644 (file)
index 0000000..e150f97
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+/**
+ * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+require_once('../../../lib/base.php');
+$l10n = new OC_L10N('contacts');
+if(!OC_USER::isLoggedIn()) {
+       die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
+}
+OC_JSON::checkAppEnabled('contacts');
+OC_Log::write('contacts','chooseaddressbook.php',OC_Log::DEBUG);
+
+$output = new OC_TEMPLATE("contacts", "part.chooseaddressbook");
+$output -> printpage();
+?>
index f351589fe12e6e32c790d634e77a8491ce829f74..048f4cf9d2d6db1a056081bebb32211623b18178 100644 (file)
@@ -1,3 +1,4 @@
+#chooseaddressbook {margin-right: 170px; float: right; font-size: 12px;}
 #contacts_details_name { font-weight:bold;font-size:1.1em;margin-left:25%;}
 #contacts_details_photo { margin:.5em 0em .5em 25%; }
 
index 29d41d3c4c45b948217ebf3a543d1b8bc1327c34..57c28a5761c5e847edafa688ad7eafb2975917cf 100644 (file)
@@ -79,6 +79,13 @@ $l10n = new OC_L10N('contacts');
 $adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
 $phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
 
+// Include Style and Script
+OC_Util::addScript('contacts','interface');
+OC_Util::addStyle('contacts','styles');
+OC_Util::addStyle('contacts','formtastic');
+OC_Util::addScript('', 'jquery.multiselect');
+OC_Util::addStyle('', 'jquery.multiselect');
+
 // Process the template
 $tmpl = new OC_Template( 'contacts', 'index', 'user' );
 $tmpl->assign('adr_types',$adr_types);
index ba1c0e536c2d3a2c8241ace04ad4432d87fabfca..077bbd2071e5dd5922955eb580ca72c0d8bb9254 100644 (file)
@@ -1,3 +1,106 @@
+Contacts={
+       space:' ',
+       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){
+                                       /*alert('Address books.moveToTop');*/
+                                       $('#chooseaddressbook_dialog').dialog('moveToTop');
+                               }else{
+                                       $('#dialog_holder').load(OC.filePath('contacts', 'ajax', 'chooseaddressbook.php'), function(){
+                                               /*alert('Address books.load');*/
+                                               $('#chooseaddressbook_dialog').dialog({
+                                                       width : 600,
+                                                       close : function(event, ui) {
+                                                               $(this).dialog('destroy').remove();
+                                                       }
+                                               });
+                                       });
+                               }
+                       },
+                       activation:function(checkbox, bookid)
+                       {
+                               /* TODO: 
+                                * Add integer field 'active' to table 'contacts_addressbooks'. See apps/contacts/README.tanghus */
+                               $.post(OC.filePath('contacts', 'ajax', 'activation.php'), { bookid: bookid, active: checkbox.checked?1:0 },
+                                 function(data) {
+                                       /*
+                                        * Arguments:
+                                        * data.status
+                                        * data.bookid
+                                        */
+                                       if (data.status == 'success'){
+                                               checkbox.checked = data.active == 1;
+                                               alert('Update Contacts list.');
+                                               /* TODO: Update Contacts list.
+                                               if (data.active == 1){
+                                                       $('#calendar_holder').fullCalendar('addEventSource', data.eventSource);
+                                               }else{
+                                                       $('#calendar_holder').fullCalendar('removeEventSource', data.eventSource.url);
+                                               }
+                                               */
+                                       }
+                                 });
+                       },
+                       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? */
+                       },
+                       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'){
+                                                       alert('TODO: Update Contacts list.');
+                                                       /* TODO: Update Contacts list.
+                                                       var url = 'ajax/deletebook.php?id='+bookid;
+                                                       $('#calendar_holder').fullCalendar('removeEventSource', url);
+                                                       $('#choosecalendar_dialog').dialog('destroy').remove();*/
+                                                       Contacts.UI.Addressbooks.overview();
+                                               }
+                                         });
+                               }
+                       },
+                       submit:function(button, bookid){
+                               alert('TODO: Add or update address book.');
+                               /* TODO: Add or update address book.
+                               var displayname = $("#displayname_"+calendarid).val();
+                               var active = $("#edit_active_"+calendarid+":checked").length;
+                               var description = $("#description_"+calendarid).val();
+                               var calendarcolor = $("#calendarcolor_"+calendarid).val();
+
+                               var url;
+                               if (calendarid == 'new'){
+                                       url = "ajax/createcalendar.php";
+                               }else{
+                                       url = "ajax/updatecalendar.php";
+                               }
+                               $.post(url, { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor },
+                                       function(data){
+                                               if(data.status == 'success'){
+                                                       $(button).closest('tr').prev().html(data.page).show().next().remove();
+                                                       $('#calendar_holder').fullCalendar('removeEventSource', data.eventSource.url);
+                                                       $('#calendar_holder').fullCalendar('addEventSource', data.eventSource);
+                                               }
+                                       }, 'json');*/
+                       },
+                       cancel:function(button, bookid){
+                               $(button).closest('tr').prev().show().next().remove();
+                       }
+               }
+       }
+}
+
 $(document).ready(function(){
        /*-------------------------------------------------------------------------
         * Event handlers
@@ -79,6 +182,23 @@ $(document).ready(function(){
                return false;
        });
 
+       $('#chooseaddressbook').click(function(){
+               Contacts.UI.Addressbooks.overview();
+               /*
+               $.getJSON('ajax/showaddcard.php',{},function(jsondata){
+                       if(jsondata.status == 'success'){
+                               $('#rightcontent').data('id','');
+                               $('#rightcontent').html(jsondata.data.page)
+                                       .find('select').chosen();
+                       }
+                       else{
+                               alert(jsondata.data.message);
+                       }
+               });
+               */
+               return false;
+       });
+       
        $('#contacts_newcontact').click(function(){
                $.getJSON('ajax/showaddcard.php',{},function(jsondata){
                        if(jsondata.status == 'success'){
index 87477ed7ed41913ad505b9c92641fd76935d8eae..93f069cff2fdb5fde4f257e3ba418177ee86a9a7 100644 (file)
@@ -140,6 +140,26 @@ class OC_Contacts_Addressbook{
                return true;
        }
 
+       /**
+        * @brief Activates an addressbook
+        * @param integer $id
+        * @param integer $name
+        * @return boolean
+        */
+       public static function setActive($id,$active){
+               // Need these ones for checking uri
+               //$addressbook = self::find($id);
+
+               if(is_null($id)){
+                       $id = 0;
+               }
+
+               $stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_addressbooks SET active=?, ctag=ctag+1 WHERE id=?' );
+               $result = $stmt->execute(array($active,$id));
+
+               return true;
+       }
+
        /**
         * @brief removes an address book
         * @param integer $id
index 630dca41b2e91eb126f19f59bd82ac61316dac77..20a1e34eb781eb022f35451674b1a543e300c0ee 100644 (file)
@@ -1,12 +1,10 @@
-<?php // Include Style and Script
-OC_Util::addScript('contacts','interface');
-OC_Util::addStyle('contacts','styles');
-OC_Util::addStyle('contacts','formtastic');
-?>
-
+<script type='text/javascript'>
+       var totalurl = '<?php echo OC_Helper::linkTo('apps/contacts', 'carddav.php', null, true); ?>/addressbooks';
+</script>
 <div id="controls">
        <form>
                <input type="button" id="contacts_newcontact" value="<?php echo $l->t('Add Contact'); ?>">
+               <input type="button" id="chooseaddressbook" value="<?php echo $l->t('Address Books'); ?>">
        </form>
 </div>
 <div id="leftcontent" class="leftcontent">
@@ -17,3 +15,9 @@ OC_Util::addStyle('contacts','formtastic');
 <div id="rightcontent" class="rightcontent" data-id="<?php echo $_['id']; ?>">
        <?php echo $this->inc("part.addcardform"); ?>
 </div>
+<!-- Dialogs -->
+<div id="dialog_holder"></div>
+<div id="parsingfail_dialog" title="Parsing Fail">
+       <?php echo $l->t("There was a fail, while parsing the file."); ?>
+</div>
+<!-- End of Dialogs -->
diff --git a/apps/contacts/templates/part.chooseaddressbook.php b/apps/contacts/templates/part.chooseaddressbook.php
new file mode 100644 (file)
index 0000000..a698a33
--- /dev/null
@@ -0,0 +1,23 @@
+<div id="chooseaddressbook_dialog" title="<?php echo $l->t("Choose active Address Books"); ?>">
+<table width="100%" style="border: 0;">
+<?php
+$option_addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser());
+for($i = 0; $i < count($option_addressbooks); $i++){
+       echo "<tr>";
+       $tmpl = new OC_Template('contacts', 'part.chooseaddressbook.rowfields');
+       $tmpl->assign('addressbook', $option_addressbooks[$i]);
+       $tmpl->printpage();
+       echo "</tr>";
+}
+?>
+<tr>
+       <td colspan="5">
+               <a href="#" onclick="Contacts.UI.Addressbooks.newAddressbook(this);"><?php echo $l->t('New Address Book') ?></a>
+       </td>
+</tr>
+<tr>
+       <td colspan="5">
+               <p style="margin: 0 auto;width: 90%;"><input style="display:none;width: 90%;float: left;" type="text" id="carddav_url" onmouseover="$('#carddav_url').select();" title="<?php echo $l->t("CardDav Link"); ?>"><img id="carddav_url_close" style="height: 20px;vertical-align: middle;display: none;" src="../../core/img/actions/delete.svg" alt="close" onclick="$('#carddav_url').hide();$('#carddav_url_close').hide();"/></p>
+       </td>
+</tr>
+</table>
diff --git a/apps/contacts/templates/part.chooseaddressbook.rowfields.php b/apps/contacts/templates/part.chooseaddressbook.rowfields.php
new file mode 100644 (file)
index 0000000..f6c1131
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+       echo "<td width=\"20px\"><input id=\"active_" . $_['addressbook']["id"] . "\" type=\"checkbox\" onClick=\"Contacts.UI.Addressbooks.activation(this, " . $_['addressbook']["id"] . ")\"" . ($_['addressbook']["active"] ? ' checked="checked"' : '') . "></td>";
+       echo "<td><label for=\"active_" . $_['addressbook']["id"] . "\">" . $_['addressbook']["displayname"] . "</label></td>";
+       echo "<td width=\"20px\"><a href=\"#\" onclick=\"Contacts.UI.showCardDAVUrl('" . OC_User::getUser() . "', '" . $_['addressbook']["uri"] . "');\" title=\"" . $l->t("CardDav Link") . "\" class=\"action\"><img  class=\"svg action\" src=\"../../core/img/actions/public.svg\"></a></td><td width=\"20px\"><a href=\"export.php?bookid=" . $_['addressbook']["id"] . "\" title=\"" . $l->t("Download") . "\" class=\"action\"><img  class=\"svg action\" src=\"../../core/img/actions/download.svg\"></a></td><td width=\"20px\"><a href=\"#\" onclick=\"Contacts.UI.Addressbooks.deleteAddressbook('" . $_['addressbook']["id"] . "');\" title=\"" . $l->t("Delete") . "\" class=\"action\"><img  class=\"svg action\" src=\"../../core/img/actions/delete.svg\"></a></td>";
diff --git a/apps/contacts/templates/part.editaddressbook.php b/apps/contacts/templates/part.editaddressbook.php
new file mode 100644 (file)
index 0000000..4e63ce5
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+?>
+<td id="<?php echo $_['new'] ? 'new' : 'edit' ?>addressbook_dialog" title="<?php echo $_['new'] ? $l->t("New Address Book") : $l->t("Edit Address Book"); ?>" colspan="6">
+<table width="100%" style="border: 0;">
+<tr>
+       <th><?php echo $l->t('Displayname') ?></th>
+       <td>
+               <input id="displayname_<?php echo $_['addressbook']['id'] ?>" type="text" value="<?php echo $_['addressbook']['displayname'] ?>">
+       </td>
+</tr>
+<?php if (!$_['new']): ?>
+<tr>
+       <td></td>
+       <td>
+               <input id="edit_active_<?php echo $_['addressbook']['id'] ?>" type="checkbox"<?php echo $_['addressbook']['active'] ? ' checked="checked"' : '' ?>>
+               <label for="edit_active_<?php echo $_['addressbook']['id'] ?>">
+                       <?php echo $l->t('Active') ?>
+               </label>
+       </td>
+</tr>
+<?php endif; ?>
+</table>
+<input style="float: left;" type="button" onclick="Contacts.UI.Addressbooks.submit(this, <?php echo $_['new'] ? "'new'" : $_['addressbook']['id'] ?>);" value="<?php echo $_['new'] ? $l->t("Save") : $l->t("Submit"); ?>">
+<input style="float: left;" type="button" onclick="Contacts.UI.Addressbooks.cancel(this, <?php echo $_['new'] ? "'new'" : $_['addressbook']['id'] ?>);" value="<?php echo $l->t("Cancel"); ?>">
+</td>