aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-19 21:23:20 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-19 21:23:20 +0000
commit9d810a6331a025c28052eadcbfe7e6e77b8a7334 (patch)
treed8a1c9348344d6b2b5b9a0740623d5df1ac5f248
parent3b46665b3f4ee10e9d2778033ea7180cca7571eb (diff)
downloadelgg-9d810a6331a025c28052eadcbfe7e6e77b8a7334.tar.gz
elgg-9d810a6331a025c28052eadcbfe7e6e77b8a7334.tar.bz2
updating widget contents when settings are changed
git-svn-id: http://code.elgg.org/elgg/trunk@7351 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--actions/widgets/save.php5
-rw-r--r--js/lib/ui.widgets.js61
-rw-r--r--views/default/widgets/editwrapper.php12
-rw-r--r--views/default/widgets/wrapper.php27
4 files changed, 78 insertions, 27 deletions
diff --git a/actions/widgets/save.php b/actions/widgets/save.php
index 4af60c7de..13ea90e85 100644
--- a/actions/widgets/save.php
+++ b/actions/widgets/save.php
@@ -13,6 +13,11 @@ $result = elgg_save_widget_settings($guid, $params);
if (!$result) {
register_error(elgg_echo('widgets:save:failure'));
+} else {
+ // send back the widget contents
+ $widget = get_entity($guid);
+ $view = "widgets/$widget->handler/view";
+ echo elgg_view($view, array('entity' => $widget));
}
forward(REFERER); \ No newline at end of file
diff --git a/js/lib/ui.widgets.js b/js/lib/ui.widgets.js
index f20ac19c2..bee4b2126 100644
--- a/js/lib/ui.widgets.js
+++ b/js/lib/ui.widgets.js
@@ -1,5 +1,10 @@
elgg.provide('elgg.ui.widgets');
+/**
+ * Widgets initialization
+ *
+ * @return void
+ */
elgg.ui.widgets.init = function() {
$(".widget_column").sortable({
items: 'div.widget',
@@ -45,14 +50,28 @@ elgg.ui.widgets.init = function() {
elgg.ui.widgets.equalHeight(".widget_column");
};
-// insert a widget into the layout
+/**
+ * Insert a new widget into the layout
+ *
+ * This always inserts the widget at the top of the first column.
+ *
+ * @param {String} html The HTML of the widget
+ * @return void
+ */
elgg.ui.widgets.insert = function(html) {
$('#widget_col_1').prepend(html);
$('#widget_col_1').children(":first").find('a.widget_delete_button').bind('click', elgg.ui.widgets.remove);
$('#widget_col_1').children(":first").find('a.widget_edit_button').bind('click', elgg.ui.widgets.editToggle);
}
-// remove a widget from the layout
+/**
+ * Removes a widget from the layout
+ *
+ * Event callback the uses Ajax to delete the widget and removes its HTML
+ *
+ * @param {Object} event
+ * @return void
+ */
elgg.ui.widgets.remove = function(event) {
$(this).parent().parent().parent().parent().remove();
elgg.action('widgets/delete', {
@@ -64,19 +83,49 @@ elgg.ui.widgets.remove = function(event) {
event.preventDefault();
}
+/**
+ * Toggle the edit panel of a widget
+ *
+ * Yes, I'm quite bad at selectors.
+ *
+ * @param {Object} event
+ * @return void
+ */
elgg.ui.widgets.editToggle = function(event) {
$(this).parent().parent().parent().parent().find('.widget_edit').slideToggle('medium');
event.preventDefault();
}
+/**
+ * Save a widget's settings
+ *
+ * Uses Ajax to save the settings and updates the HTML.
+ *
+ * @param {Object} event
+ * @return void
+ */
elgg.ui.widgets.saveSettings = function(event) {
$(this).parent().slideToggle('medium');
+ var $widgetContent = $(this).parent().parent().children('.widget_content');
+ $widgetContent.html('loading');
elgg.action('widgets/save', {
- data: $(this).serialize()
+ data: $(this).serialize(),
+ success: function(json) {
+ $widgetContent.html(json.output);
+ }
});
event.preventDefault();
}
+/**
+ * Make all elements have the same min-height
+ *
+ * This addresses the issue of trying to drag a widget into a column that does
+ * not have any widgets.
+ *
+ * @param {String} selector
+ * @return void
+ */
elgg.ui.widgets.equalHeight = function(selector) {
var maxHeight = 0;
$(selector).each(function() {
@@ -87,6 +136,11 @@ elgg.ui.widgets.equalHeight = function(selector) {
$(selector).css('min-height', maxHeight);
}
+elgg.register_event_handler('init', 'system', elgg.ui.widgets.init);
+
+
+// @todo look into removing the below functions - maybe a compatibility plugin
+
//List active widgets for each page column
elgg.ui.widgets.outputList = function(forElement) {
return $("input[name='handler'], input[name='guid']", forElement).makeDelimitedList("value");
@@ -162,4 +216,3 @@ var toggleContent = elgg.ui.widgets.toggleContent,
widget_state = elgg.ui.widgets.state,
outputWidgetList = elgg.ui.widgets.outputList;
-elgg.register_event_handler('init', 'system', elgg.ui.widgets.init); \ No newline at end of file
diff --git a/views/default/widgets/editwrapper.php b/views/default/widgets/editwrapper.php
index cf985445b..73166b718 100644
--- a/views/default/widgets/editwrapper.php
+++ b/views/default/widgets/editwrapper.php
@@ -11,15 +11,15 @@ $widget = $vars['widget'];
$edit_view = "widgets/$widget->handler/edit";
$custom_form_section = elgg_view($edit_view, array('entity' => $widget));
+$access_text = elgg_echo('access');
$access = elgg_view('input/access', array('internalname' => 'params[access_id]','value' => $widget->access_id));
-$hidden = elgg_view('input/hidden', array('internalname' => 'guid', 'value' => $widget->guid)) .
-$hidden .= elgg_view('input/hidden', array('internalname' => 'noforward', 'value' => 'true'));
-$submit = elgg_view('input/submit', array('internalname' => "submit$guid", 'value' => elgg_echo('save')));
+$hidden = elgg_view('input/hidden', array('internalname' => 'guid', 'value' => $widget->guid));
+$submit = elgg_view('input/submit', array('value' => elgg_echo('save')));
$body = <<<___END
$custom_form_section
<p>
- <label>Access:</label> $access
+ <label>$access_text:</label> $access
</p>
<p>
$hidden
@@ -32,10 +32,8 @@ ___END;
<?php
$params = array(
'body' => $body,
- 'action' => "action/widgets/save",
- 'internalid' => "widgetform$guid"
+ 'action' => "action/widgets/save"
);
echo elgg_view('input/form', $params);
-// _<?php echo $widget->guid;
?>
</div>
diff --git a/views/default/widgets/wrapper.php b/views/default/widgets/wrapper.php
index 52ca87cab..a113d114e 100644
--- a/views/default/widgets/wrapper.php
+++ b/views/default/widgets/wrapper.php
@@ -6,24 +6,20 @@
* @subpackage Core
*/
-$widgettypes = get_widget_types();
-
$widget = $vars['entity'];
-
-if ($vars['entity'] instanceof ElggObject && $vars['entity']->getSubtype() == 'widget') {
- $handler = $vars['entity']->handler;
- $title = $widgettypes[$vars['entity']->handler]->name;
- if (!$title) {
- $title = $handler;
- }
-} else {
- $handler = "error";
- $title = elgg_echo("error");
+if (!elgg_instanceof($widget, 'object', 'widget')) {
+ return true;
}
-$title = "Widget Title";
+// @todo catch for disabled plugins
+$widgettypes = get_widget_types();
+
+$handler = $widget->handler;
-$display_view = "widgets/$handler/view";
+$title = $widget->title;
+if (!$title) {
+ $title = $widgettypes[$handler]->name;
+}
$can_edit = $widget->canEdit();
@@ -43,7 +39,6 @@ $can_edit = $widget->canEdit();
}
?>
<div class="widget_content">
- <?php echo elgg_view($display_view, $vars); ?>
- <p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
+ <?php echo elgg_view("widgets/$handler/view", $vars); ?>
</div>
</div>