jQuery(function() { // Attach to addressbook links var addressbookpage = jQuery('#davcardAddressbookList').data('addressbookpage'); if(!addressbookpage) return; dw_davcard__modals.page = addressbookpage; jQuery('div.davcardAddressbookAddNew a').each(function() { var $link = jQuery(this); var href = $link.attr('href'); if (!href) return; $link.click( function(e) { dw_davcard__modals.showEditContactDialog(null, false); e.preventDefault(); return ''; } ); } ); }); /** * This holds all modal windows that DAVCal uses. */ var dw_davcard__modals = { $editContactDialog: null, $confirmDialog: null, page: null, uri: null, action: null, completeCb: null, msg: null, showEditContactDialog : function(entry, edit) { if(dw_davcard__modals.$editContactDialog) return; var title = ''; var dialogButtons = {}; if(edit) { title = LANG.plugins.davcard['edit_entry']; dialogButtons[LANG.plugins.davcard['edit']] = function() { var postArray = { }; var pageid = dw_davcard__modals.page; jQuery("input.dw_davcard__editcontact").each(function() { if(jQuery(this).attr('type') == 'checkbox') { postArray[jQuery(this).prop('name')] = jQuery(this).prop('checked') ? 1 : 0; } else { postArray[jQuery(this).prop('name')] = jQuery(this).val(); } }); jQuery('#dw_davcard__ajaxedit').html(''); jQuery.post( DOKU_BASE + 'lib/exe/ajax.php', { call: 'plugin_davcard', id: pageid, page: dw_davcard__modals.page, action: 'editContact', params: postArray, sectok: JSINFO.plugin.davcal['sectok'] }, function(data) { var result = data['result']; var html = data['html']; jQuery('#dw_davcard__ajaxedit').html(html); if(result === true) { dw_davcard__modals.hideEditContactDialog(); location.reload(); } } ); }; dialogButtons[LANG.plugins.davcal['delete']] = function() { dw_davcard__modals.action = 'deleteContact'; dw_davcard__modals.msg = LANG.plugins.davcard['really_delete_this_entry']; dw_davcard__modals.completeCb = function(data) { var result = data['result']; if(result === true) { dw_davcard__modals.hideEditContactDialog(); location.reload(); } }; dw_davcard__modals.showDialog(true); }; } else { title = LANG.plugins.davcard['create_entry']; dialogButtons[LANG.plugins.davcard['create']] = function() { var postArray = { }; var pageid = dw_davcard__modals.page; jQuery("input.dw_davcard__editcontact").each(function() { if(jQuery(this).attr('type') == 'checkbox') { postArray[jQuery(this).prop('name')] = jQuery(this).prop('checked') ? 1 : 0; } else { postArray[jQuery(this).prop('name')] = jQuery(this).val(); } }); jQuery('#dw_davcard__ajaxedit').html(''); jQuery.post( DOKU_BASE + 'lib/exe/ajax.php', { call: 'plugin_davcard', id: pageid, page: dw_davcard__modals.page, action: 'newContact', params: postArray, sectok: JSINFO.plugin.davcard['sectok'] }, function(data) { var result = data['result']; var html = data['html']; jQuery('#dw_davcard__ajaxedit').html(html); if(result === true) { dw_davcard__modals.hideEditContactDialog(); location.reload(); } } ); }; } dialogButtons[LANG.plugins.davcard['cancel']] = function() { dw_davcard__modals.hideEditContactDialog(); }; dw_davcard__modals.$editContactDialog = jQuery(document.createElement('div')) .dialog({ autoOpen: false, draggable: true, // fix for dragging: http://stackoverflow.com/questions/17247486/jquery-ui-dialog-dragging-issues drag: function(event, ui) { var fixPix = jQuery(document).scrollTop(); iObj = ui.position; iObj.top = iObj.top - fixPix; jQuery(this).closest(".ui-dialog").css("top", iObj.top + "px"); }, title: title, resizable: true, buttons: dialogButtons, }) .html( '
' + // FIXME: '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + LANG.plugins.davcal['calendar'] + '
' + LANG.plugins.davcard['firstname'] + '
' + LANG.plugins.davcard['lastname'] + '
' + LANG.plugins.davcard['cellphone'] + '
' + LANG.plugins.davcard['phone'] + '
' + LANG.plugins.davcard['email'] + '
' + LANG.plugins.davcard['street'] + '
' + LANG.plugins.davcard['zipcode'] + '
' + LANG.plugins.davcard['city'] + '
' + LANG.plugins.davcard['country'] + '
' + '' + '
' + '
' ) .parent() .attr('id','dw_davcard__edit') .show() .appendTo('.dokuwiki:first'); jQuery('#dw_davcard__edit').position({ my: "center", at: "center", of: window }); // attach event handlers jQuery('#dw_davcard__edit .ui-dialog-titlebar-close').click(function(){ dw_davcard__modals.hideEditContactDialog(); }); }, hideEditContactDialog : function() { dw_davcard__modals.$editContactDialog.empty(); dw_davcard__modals.$editContactDialog.remove(); dw_davcard__modals.$editContactDialog = null; }, hideDialog: function() { dw_davcard__modals.$dialog.empty(); dw_davcard__modals.$dialog.remove(); dw_davcard__modals.$dialog = null; }, showDialog : function(confirm) { if(dw_davcard__modals.$confirmDialog) return; var dialogButtons = {}; var title = ''; if(confirm) { title = LANG.plugins.davcard['confirmation']; var pageid = dw_davcard__modals.page; dialogButtons[LANG.plugins.davcard['yes']] = function() { jQuery.post( DOKU_BASE + 'lib/exe/ajax.php', { call: 'plugin_davcard', id: pageid, page: dw_davcard__modals.page, action: dw_davcard__modals.action, params: { uri: dw_davcard__modals.uri }, sectok: JSINFO.plugin.davcard['sectok'] }, function(data) { dw_davcard__modals.completeCb(data); } ); dw_davcard__modals.hideDialog(); }; dialogButtons[LANG.plugins.davcard['cancel']] = function() { dw_davcard__modals.hideDialog(); }; } else { title = LANG.plugins.davcard['info']; dialogButtons[LANG.plugins.davcard['ok']] = function() { dw_davcard__modals.hideDialog(); }; } dw_davcard__modals.$dialog = jQuery(document.createElement('div')) .dialog({ autoOpen: false, draggable: true, //fix for dragging: http://stackoverflow.com/questions/17247486/jquery-ui-dialog-dragging-issues drag: function(event, ui) { var fixPix = jQuery(document).scrollTop(); iObj = ui.position; iObj.top = iObj.top - fixPix; jQuery(this).closest(".ui-dialog").css("top", iObj.top + "px"); }, title: title, resizable: true, buttons: dialogButtons, }) .html( '
' + dw_davcard__modals.msg + '
' ) .parent() .attr('id','dw_davcard__confirm') .show() .appendTo('.dokuwiki:first'); jQuery('#dw_davcard__confirm').position({ my: "center", at: "center", of: window }); // attach event handlers jQuery('#dw_davcard__confirm .ui-dialog-titlebar-close').click(function(){ dw_davcard__modals.hideDialog(); }); }, };