aboutsummaryrefslogtreecommitdiff
path: root/mod
diff options
context:
space:
mode:
Diffstat (limited to 'mod')
-rw-r--r--mod/messageboard/actions/add.php28
-rw-r--r--mod/messageboard/start.php3
-rw-r--r--mod/messageboard/views/default/forms/messageboard/add.php21
-rw-r--r--mod/messageboard/views/default/messageboard/forms/add.php25
-rw-r--r--mod/messageboard/views/default/messageboard/js.php24
-rw-r--r--mod/messageboard/views/default/widgets/messageboard/content.php70
6 files changed, 69 insertions, 102 deletions
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 @@
<?php
-
/**
* Elgg Message board: add message action
*
* @package ElggMessageBoard
*/
-// Get input
-$message_content = get_input('message_content'); // the actual message
-$page_owner = get_input("pageOwner"); // the message board owner
-$user = get_entity($page_owner); // the message board owner's details
-
-// Let's see if we can get a user entity from the specified page_owner
-if ($user && !empty($message_content)) {
+$message_content = get_input('message_content');
+$owner_guid = get_input("owner_guid");
+$owner = get_entity($owner_guid);
- if (messageboard_add(elgg_get_logged_in_user_entity(), $user, $message_content, $user->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 @@
+<?php
+/**
+ * Elgg Message board add form
+ *
+ * @package ElggMessageBoard
+ */
+
+$textarea = elgg_view('input/plaintext', array(
+ 'name' => '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 @@
-<?php
-
-/**
- * Elgg Message board add form
- *
- * @package ElggMessageBoard
- */
-
-?>
-<div id="mb_input_wrapper">
- <form action="<?php echo elgg_get_site_url(); ?>action/messageboard/add" method="post" name="messageboardForm">
-
- <!-- textarea for the contents -->
- <textarea name="message_content" value="" class="elgg-input-textarea"></textarea><br />
-
- <!-- the page owner, this will be the profile owner -->
- <input type="hidden" name="pageOwner" value="<?php echo elgg_get_page_owner_guid(); ?>" />
-
- <?php echo elgg_view('input/securitytoken'); ?>
-
- <!-- submit messages input -->
- <input type="submit" id="postit" value="<?php echo elgg_echo('messageboard:postit'); ?>">
-
- </form>
-</div>
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 @@
<?php
-
/**
- * Elgg messageboard widget view
+ * Elgg messageboard widget view
*
*
* @package ElggMessageBoard
*/
-//get the full page owner entity
$user = elgg_get_page_owner_entity();
-
-//the number of message to display
$num_display = 5;
+
if (isset($vars['entity']->num_display)) {
$num_display = $vars['entity']->num_display;
}
-//Just the loggedin user can post messages
if (elgg_is_logged_in()) {
-?>
-<?php //@todo JS 1.8: no ?>
-<script type="text/javascript">
- $(document).ready(function(){
-
- $("#postit").click(function(){
-
- //display the ajax loading gif at the start of the function call
- //$('#loader').html('<img src="<?php echo elgg_get_site_url(); ?>_graphics/ajax-loader.gif" />');
- $('#loader').html('<?php echo elgg_view('graphics/ajax_loader', array('slashes' => TRUE)); ?>');
-
- //load the results back into the message board contents and remove the loading gif
- //remember that the actual div being populated is determined on views/default/messageboard/messageboard.php
- $("#messageboard_wrapper").load("<?php echo elgg_get_site_url(); ?>mod/messageboard/ajax_endpoint/load.php", {messageboard_content:$("[name=message_content]").val(), pageOwner:$("[name=pageOwner]").val(), numToDisplay:<?php echo $num_display; ?>}, function(){
- $('#loader').empty(); // remove the loading gif
- $('[name=message_content]').val(''); // clear the input textarea
- }); //end
-
- }); // end of the main click function
-
- }); //end of the document .ready function
-</script>
-
-<div id="mb_input_wrapper"><!-- start of mb_input_wrapper div -->
-
- <!-- message textarea -->
- <textarea name="message_content" class="elgg-input-textarea"></textarea>
-
- <!-- the page owner, this will be the profile owner -->
- <input type="hidden" name="pageOwner" value="<?php echo elgg_get_page_owner_guid(); ?>" class="pageOwner" />
-
- <!-- submit button -->
- <input type="submit" id="postit" value="<?php echo elgg_echo('messageboard:postit'); ?>">
-
- <!-- menu options -->
- <div id="messageboard_widget_menu">
- <a href="<?php echo elgg_get_site_url(); ?>pg/messageboard/<?php echo $user->username; ?>"><?php echo elgg_echo("messageboard:viewall"); ?></a>
- </div>
-
- <!-- loading graphic -->
- <div id="loader" class="loading"> </div>
-
-</div><!-- end of mb_input_wrapper div -->
-
- <?php
-} // if(elgg_is_logged_in())
+ echo elgg_view_form('messageboard/add', array('class' => '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 "<div id=\"messageboard_wrapper\"></div>";
-
-}
+if ($contents) {
+ echo elgg_view('messageboard/messageboard', array('annotation' => $contents));
+} \ No newline at end of file