From 458af185465d2fb2377b0c2151627e0a9b9eb65a Mon Sep 17 00:00:00 2001 From: brettp Date: Sat, 19 Feb 2011 05:19:31 +0000 Subject: Refs #2916: Moved messageboard js into elgg.messageboard object. Moved forms into forms/messageboard. Can post now, but wow this plugin needs cleaned up. git-svn-id: http://code.elgg.org/elgg/trunk@8320 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/messageboard/actions/add.php | 28 +++++---- mod/messageboard/start.php | 3 +- .../views/default/forms/messageboard/add.php | 21 +++++++ .../views/default/messageboard/forms/add.php | 25 -------- mod/messageboard/views/default/messageboard/js.php | 24 ++++++++ .../views/default/widgets/messageboard/content.php | 70 +++------------------- 6 files changed, 69 insertions(+), 102 deletions(-) create mode 100644 mod/messageboard/views/default/forms/messageboard/add.php delete mode 100644 mod/messageboard/views/default/messageboard/forms/add.php create mode 100644 mod/messageboard/views/default/messageboard/js.php (limited to 'mod/messageboard') diff --git a/mod/messageboard/actions/add.php b/mod/messageboard/actions/add.php index 1058482d9..5a34904d7 100644 --- a/mod/messageboard/actions/add.php +++ b/mod/messageboard/actions/add.php @@ -1,30 +1,32 @@ access_id)) { +if ($owner && !empty($message_content)) { + if (messageboard_add(elgg_get_logged_in_user_entity(), $owner, $message_content, $owner->access_id)) { system_message(elgg_echo("messageboard:posted")); + + // push the newest content out if using ajax + $is_ajax = array_key_exists('HTTP_X_REQUESTED_WITH', $_SERVER) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; + if ($is_ajax) { + $contents = $owner->getAnnotations('messageboard', 1, 0, 'desc'); + $post = elgg_view("messageboard/messageboard_content", array('annotation' => $contents[0])); + echo json_encode(array('post' => $post)); + } + } else { register_error(elgg_echo("messageboard:failure")); } - -} else { +} else { register_error(elgg_echo("messageboard:blank")); - } -// Forward back to the messageboard forward(REFERER); diff --git a/mod/messageboard/start.php b/mod/messageboard/start.php index 4ce631569..a4792d322 100644 --- a/mod/messageboard/start.php +++ b/mod/messageboard/start.php @@ -13,8 +13,9 @@ */ function messageboard_init() { - // Extend system CSS with our own styles, which are defined in the messageboard/css view + // add css and js elgg_extend_view('css/screen', 'messageboard/css'); + elgg_extend_view('js/elgg', 'messageboard/js'); // Register a page handler, so we can have nice URLs elgg_register_page_handler('messageboard', 'messageboard_page_handler'); diff --git a/mod/messageboard/views/default/forms/messageboard/add.php b/mod/messageboard/views/default/forms/messageboard/add.php new file mode 100644 index 000000000..4698abf28 --- /dev/null +++ b/mod/messageboard/views/default/forms/messageboard/add.php @@ -0,0 +1,21 @@ + 'message_content' +)); + +$owner_input = elgg_view('input/hidden', array( + 'name' => 'owner_guid', + 'value' => elgg_get_page_owner_guid() +)); + +$submit = elgg_view('input/submit', array( + 'value' => elgg_echo('post') +)); + +echo $textarea . $owner_input . $submit; \ No newline at end of file diff --git a/mod/messageboard/views/default/messageboard/forms/add.php b/mod/messageboard/views/default/messageboard/forms/add.php deleted file mode 100644 index cacb5712f..000000000 --- a/mod/messageboard/views/default/messageboard/forms/add.php +++ /dev/null @@ -1,25 +0,0 @@ - -
-
- - -
- - - - - - - - - -
-
diff --git a/mod/messageboard/views/default/messageboard/js.php b/mod/messageboard/views/default/messageboard/js.php new file mode 100644 index 000000000..c76040945 --- /dev/null +++ b/mod/messageboard/views/default/messageboard/js.php @@ -0,0 +1,24 @@ +elgg.provide('elgg.messageboard'); + +elgg.messageboard.init = function() { + $('form.elgg-messageboard input[type=submit]').live('click', elgg.messageboard.submit); +} + +elgg.messageboard.submit = function(e) { + var form = $(this).parents('form'); + var data = form.serialize(); + + elgg.action('messageboard/add', { + data: data, + success: function(json) { + form.parent().find('#messageboard_wrapper').prepend(json.output.post); + form.find('textarea').val(''); + } + }); + + e.preventDefault(); +} + + + +elgg.register_event_handler('init', 'system', elgg.messageboard.init); \ No newline at end of file diff --git a/mod/messageboard/views/default/widgets/messageboard/content.php b/mod/messageboard/views/default/widgets/messageboard/content.php index 45d4426a2..5f0cc8676 100644 --- a/mod/messageboard/views/default/widgets/messageboard/content.php +++ b/mod/messageboard/views/default/widgets/messageboard/content.php @@ -1,81 +1,25 @@ num_display)) { $num_display = $vars['entity']->num_display; } -//Just the loggedin user can post messages if (elgg_is_logged_in()) { -?> - - - -
- - - - - - - - - - - -
- -
- - -
- -
- - 'elgg-messageboard')); +} //this for the first time the page loads, grab the latest messages. $contents = $user->getAnnotations('messageboard', $num_display, 0, 'desc'); -//as long as there is some content to display, display it -if (!empty($contents)) { - - echo elgg_view('messageboard/messageboard',array('annotation' => $contents)); - -} else { - - //put the required div on the page for the first message - echo "
"; - -} +if ($contents) { + echo elgg_view('messageboard/messageboard', array('annotation' => $contents)); +} \ No newline at end of file -- cgit v1.2.3