elgg.provide('elgg.ui.widgets');\r
\r
+/**\r
+ * Widgets initialization\r
+ *\r
+ * @return void\r
+ */\r
elgg.ui.widgets.init = function() {\r
$(".widget_column").sortable({\r
items: 'div.widget',\r
elgg.ui.widgets.equalHeight(".widget_column");\r
};\r
\r
-// insert a widget into the layout\r
+/**\r
+ * Insert a new widget into the layout\r
+ *\r
+ * This always inserts the widget at the top of the first column.\r
+ *\r
+ * @param {String} html The HTML of the widget\r
+ * @return void\r
+ */\r
elgg.ui.widgets.insert = function(html) {\r
$('#widget_col_1').prepend(html);\r
$('#widget_col_1').children(":first").find('a.widget_delete_button').bind('click', elgg.ui.widgets.remove);\r
$('#widget_col_1').children(":first").find('a.widget_edit_button').bind('click', elgg.ui.widgets.editToggle);\r
}\r
\r
-// remove a widget from the layout\r
+/**\r
+ * Removes a widget from the layout\r
+ *\r
+ * Event callback the uses Ajax to delete the widget and removes its HTML\r
+ *\r
+ * @param {Object} event\r
+ * @return void\r
+ */\r
elgg.ui.widgets.remove = function(event) {\r
$(this).parent().parent().parent().parent().remove();\r
elgg.action('widgets/delete', {\r
event.preventDefault();\r
}\r
\r
+/**\r
+ * Toggle the edit panel of a widget\r
+ *\r
+ * Yes, I'm quite bad at selectors.\r
+ *\r
+ * @param {Object} event\r
+ * @return void\r
+ */\r
elgg.ui.widgets.editToggle = function(event) {\r
$(this).parent().parent().parent().parent().find('.widget_edit').slideToggle('medium');\r
event.preventDefault();\r
}\r
\r
+/**\r
+ * Save a widget's settings\r
+ *\r
+ * Uses Ajax to save the settings and updates the HTML.\r
+ *\r
+ * @param {Object} event\r
+ * @return void\r
+ */\r
elgg.ui.widgets.saveSettings = function(event) {\r
$(this).parent().slideToggle('medium');\r
+ var $widgetContent = $(this).parent().parent().children('.widget_content');\r
+ $widgetContent.html('loading');\r
elgg.action('widgets/save', {\r
- data: $(this).serialize()\r
+ data: $(this).serialize(),\r
+ success: function(json) {\r
+ $widgetContent.html(json.output);\r
+ }\r
});\r
event.preventDefault();\r
}\r
\r
+/**\r
+ * Make all elements have the same min-height\r
+ *\r
+ * This addresses the issue of trying to drag a widget into a column that does\r
+ * not have any widgets.\r
+ *\r
+ * @param {String} selector\r
+ * @return void\r
+ */\r
elgg.ui.widgets.equalHeight = function(selector) {\r
var maxHeight = 0;\r
$(selector).each(function() {\r
$(selector).css('min-height', maxHeight);\r
}\r
\r
+elgg.register_event_handler('init', 'system', elgg.ui.widgets.init);\r
+\r
+\r
+// @todo look into removing the below functions - maybe a compatibility plugin\r
+\r
//List active widgets for each page column\r
elgg.ui.widgets.outputList = function(forElement) {\r
return $("input[name='handler'], input[name='guid']", forElement).makeDelimitedList("value");\r
widget_state = elgg.ui.widgets.state,\r
outputWidgetList = elgg.ui.widgets.outputList;\r
\r
-elgg.register_event_handler('init', 'system', elgg.ui.widgets.init);
\ No newline at end of file
$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
<?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>
* @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();
}
?>
<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>