hello
I would like to create a module to integrate with ModalFrame PrivateMsg http://drupal.org/project/privatemsg . I created an issue in PMS but without success.
So I started a piece of code and if you could help me create this module I would be very grateful ...
I am no expert in PHP
It starts with the file zmodal_privatemsg.module
/**** Private Message ***/
function zmodal_privatemsg_init() {
if (!empty($_COOKIE['has_js']) && preg_match('`^messages(?:/list(?:/.*))?$`', $_GET['q'])) {
modalframe_parent_js();
drupal_add_js(drupal_get_path('module', 'zmodal_privatemsg') .'/zmodal_privatemsg.js');
}
}
function zmodal_privatemsg_list($form) {
if (!empty($_COOKIE['has_js']) && !empty($_GET['modalframe']) && in_array($form_id, array('edit-archive', 'edit-delete'))) {
modalframe_child_js();
$form['list'] = array('#value' => theme('table', $headers, $themed_rows, array('class' => 'privatemsg-list')), '#weight' => 5);
return drupal_render($form);
}
}
function zmodal_privatemsg_form_submit_redirect($form, &$form_state){
if ($form_state['values']['op'] == t('Save')) {
modalframe_close_dialog();
}
}
and zmodal_privatemsg.js
(function ($) {
Drupal.behaviors.ZmodalPrivatemsg = function(context) {
var $links = $([])
.add($('.tabs a[href*="messages/"]:not(.modalframe-path-processed)', context))
.add($('table td a[href*="messages/"]:not(.modalframe-path-processed)', context));
$links.addClass('modalframe-path-processed').each(function() {
var $link = $(this), url = $link.attr('href');
var regExp = new RegExp('^'+ Drupal.settings.basePath +'(?:[-a-z]+/)?messages/(?:/[0-9]+)?.*$');
var urlParts = regExp.exec(url);
if (urlParts) {
var action = urlParts[1];
// onSubmit callback for the modal frame.
var onSubmitCallback = function(args) {
if (args.redirect) {
setTimeout(function() { window.location = args.redirect; }, 1);
}
else {
window.location.reload();
}
};
// Modal frame options.
var modalFrameOptions = {
url: url + (url.indexOf('?') == -1 ? '?' : '&') +'modalframe=1',
width: 800,
height: 800,
onSubmit: onSubmitCallback
};
// Attach click event handler to the link.
$link.click(function() {
Drupal.modalFrame.open(modalFrameOptions);
return false;
});
}
});
};
})(jQuery)
The method works, but it displays the complete body and not just the form or list.
Then when you click on "Write a message" from a block or another location it does not open the Modal Frame.
Try my code and show the improvements we can make.
Comments
Comment #1
markus_petrux commentedRe: "if you could help me create this module"
I'¡m afraid I do not have the time for this level of support. Too busy. Please, check out the documentation linked from the project page and/or study the Contribs Packake or other modules using the Modal Frame API.
Comment #2
Berliner-dupe commentedHi charlie836,
have you found a working Code for integrate PrivateMsg in Modal Frame?
Regards Matthias
Comment #3
rv0 commented"The method works, but it displays the complete body and not just the form or list."
to avoid that, use hook_form_alter to call modalframe_child_js() on the privatemsg_new form..
Comment #4
Michsk commentedThis shows the form in the modal window. Tough i'm having problems with sending the form and closing the modalwindow. That should be handled by modalframe_close_dialog(), but it doesn't. After upgrading privatemsg it stoped working. Now after the messages has been send the complete body loads in the modal, i think this has got to do with drupal_goto() which is used in privatemsg:
http://drupal.org/node/1103210
http://drupal.org/node/1108720
Javascript
Comment #5
Michsk commentedFinally got it working with privatemsg_new form. Don't know why but for privatemsg to close after submit we need to use:
Comment #6
rv0 commented@lasac
You forgot the '' around submit.
But I have to thank you BIGTIME... I was searching for hours why my code wouldn't work with Private Messages and your snippet saved me :D
Comment #7
Michsk commentedyou're welcome, happy i found it myself, this was a very annoying issue. Thanx for the pointer.
Comment #8
dsnopekLooks like @Lasac found the solution to the issue! Closing.