aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/widgets/add.php23
-rw-r--r--engine/lib/widgets.php9
-rw-r--r--js/lib/ui.widgets.js19
-rw-r--r--languages/en.php2
-rw-r--r--views/default/css.php12
-rw-r--r--views/default/layouts/widgets.php21
-rw-r--r--views/default/widgets/add.php26
-rw-r--r--views/default/widgets/add_button.php2
8 files changed, 72 insertions, 42 deletions
diff --git a/actions/widgets/add.php b/actions/widgets/add.php
index 57c331e21..c57e3596a 100644
--- a/actions/widgets/add.php
+++ b/actions/widgets/add.php
@@ -6,25 +6,28 @@
* @subpackage Widgets.Management
*/
-$guid = get_input('user');
+$user_guid = get_input('user');
$handler = get_input('handler');
$context = get_input('context');
-$column = get_input('column');
+$column = get_input('column', 1);
-$result = false;
-
-if (!empty($guid)) {
- if ($user = get_entity($guid)) {
+$guid = false;
+if (!empty($user_guid)) {
+ if ($user = get_entity($user_guid)) {
if ($user->canEdit()) {
- $result = add_widget($user->getGUID(), $handler, $context, 0, $column);
+ $guid = add_widget($user->getGUID(), $handler, $context, 0, $column);
}
}
}
-if ($result) {
- system_message(elgg_echo('widgets:save:success'));
+if ($guid) {
+ system_message(elgg_echo('widgets:add:success'));
+
+ // send widget html for insertion
+ $widget = get_entity($guid);
+ echo elgg_view_entity($widget);
} else {
- register_error(elgg_echo('widgets:save:failure'));
+ register_error(elgg_echo('widgets:add:failure'));
}
forward(REFERER); \ No newline at end of file
diff --git a/engine/lib/widgets.php b/engine/lib/widgets.php
index 1de114833..79a3b37bf 100644
--- a/engine/lib/widgets.php
+++ b/engine/lib/widgets.php
@@ -176,7 +176,7 @@ function display_widget(ElggObject $widget) {
* @param int $column The column to display this widget in (1, 2 or 3)
* @param int $access_id If not specified, it is set to the default access level
*
- * @return bool Depending on success
+ * @return int|false Widget GUID or false on failure
*/
function add_widget($entity_guid, $handler, $context, $order = 0, $column = 1, $access_id = null) {
if (empty($entity_guid) || empty($context) || empty($handler) || !widget_type_exists($handler)) {
@@ -193,17 +193,12 @@ function add_widget($entity_guid, $handler, $context, $order = 0, $column = 1, $
$widget->access_id = get_default_access();
}
- if (!$widget->save()) {
- return false;
- }
-
$widget->handler = $handler;
$widget->context = $context;
$widget->column = $column;
$widget->order = $order;
- // save_widget_location($widget, $order, $column);
- return true;
+ return $widget->save();
}
return false;
diff --git a/js/lib/ui.widgets.js b/js/lib/ui.widgets.js
index f4fa4b256..b1e7b2a99 100644
--- a/js/lib/ui.widgets.js
+++ b/js/lib/ui.widgets.js
@@ -14,9 +14,26 @@ elgg.ui.widgets.init = function() {
event.preventDefault();
});
-
+ $('.widgets_add a').bind('click', function(event) {
+ elgg.action('widgets/add', {
+ data: {
+ handler: $(this).attr('id'),
+ user: elgg.get_loggedin_userid(),
+ context: $("input[name='widget_context']").val()
+ },
+ success: function(json) {
+ elgg.ui.widgets.insert(json.output);
+ }
+ });
+ event.preventDefault();
+ });
};
+// insert a widget into the layout
+elgg.ui.widgets.insert = function(html) {
+ $('.widget_first_col').prepend(html);
+}
+
//List active widgets for each page column
elgg.ui.widgets.outputList = function(forElement) {
return $("input[name='handler'], input[name='guid']", forElement).makeDelimitedList("value");
diff --git a/languages/en.php b/languages/en.php
index e78d01c81..682c43333 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -245,6 +245,8 @@ $english = array(
'widgets:panel:save:failure' => "There was a problem saving your widgets. Please try again.",
'widgets:save:success' => "The widget was successfully saved.",
'widgets:save:failure' => "We could not save your widget. Please try again.",
+ 'widgets:add:success' => "The widget was successfully added.",
+ 'widgets:add:failure' => "We could not add your widget.",
'widgets:handlernotfound' => 'This widget is either broken or has been disabled by the site administrator.',
/**
diff --git a/views/default/css.php b/views/default/css.php
index edb0ebe07..d5b96bf59 100644
--- a/views/default/css.php
+++ b/views/default/css.php
@@ -863,28 +863,28 @@ li.navigation_more ul li {
float: right;
min-height: 15px;
}
-.widget_col_1 {
+.widget_1_columns {
width: 100%;
}
-.widget_col_2 {
+.widget_2_columns {
width: 48%;
margin-right: 4%;
}
-.widget_col_3 {
+.widget_3_columns {
width: 32%;
margin-right: 2%;
}
-.widget_col_4 {
+.widget_4_columns {
width: 23.5%;
margin-right: 2%;
}
-.widget_first_col {
+.widget_col_1 {
margin-right: 0;
}
#widget_add_button {
padding: 0px;
- background-color: transparent;
text-align: right;
+ margin-bottom: 15px;
}
.widgets_add {
width: 100%;
diff --git a/views/default/layouts/widgets.php b/views/default/layouts/widgets.php
index 5d6e42a43..38451d1c1 100644
--- a/views/default/layouts/widgets.php
+++ b/views/default/layouts/widgets.php
@@ -18,12 +18,19 @@ elgg_push_context('widgets');
elgg_get_widgets($owner->guid, $context);
if (elgg_can_edit_widgets()) {
- echo elgg_view('widgets/add', array('widgets' => $widgets));
+ if ($show_add_widgets) {
+ echo elgg_view('widgets/add_button');
+ }
+ $params = array(
+ 'widgets' => $widgets,
+ 'context' => $context,
+ );
+ echo elgg_view('widgets/add', $params);
}
echo $vars['box'];
-$widget_class = "widget_col_$num_columns";
+$widget_class = "widget_{$num_columns}_columns";
for ($column_index = 1; $column_index <= $num_columns; $column_index++) {
$widgets = get_widgets($owner->guid, $context, $column_index);
@@ -34,15 +41,7 @@ for ($column_index = 1; $column_index <= $num_columns; $column_index++) {
$widget2->handler = 'test';
$widgets = array($widget1, $widget2);
- $first = ($column_index == 1) ? 'widget_first_col' : '';
-
- echo "<div class=\"widget_column $widget_class $first\">";
- // button for adding new widgets
- if ($column_index == 1) {
- if ($show_add_widgets && elgg_can_edit_widgets()) {
- echo elgg_view('widgets/add_button');
- }
- }
+ echo "<div class=\"widget_column $widget_class widget_col_$column_index\">";
if (is_array($widgets) && sizeof($widgets) > 0) {
foreach ($widgets as $widget) {
echo elgg_view_entity($widget);
diff --git a/views/default/widgets/add.php b/views/default/widgets/add.php
index 2cc06dab7..9687c5bea 100644
--- a/views/default/widgets/add.php
+++ b/views/default/widgets/add.php
@@ -3,18 +3,32 @@
$widgets = $vars['widgets'];
$widget_types = get_widget_types();
+$context = $vars['context'];
+
?>
<div class="widgets_add hidden">
<p>
<?php echo elgg_echo('widgets:add:description'); ?>
</p>
<ul>
- <?php
- foreach ($widget_types as $widget_type) {
- $link = elgg_view('output/url', array('text' => $widget_type->name, 'href' => '#'));
- echo "<li>$link</li>";
- }
- ?>
+<?php
+ foreach ($widget_types as $handler => $widget_type) {
+ $options = array(
+ 'text' => $widget_type->name,
+ 'href' => '#',
+ 'internalid' => $handler,
+ );
+ $link = elgg_view('output/url', $options);
+ echo "<li>$link</li>";
+ }
+?>
</ul>
+<?php
+ $params = array(
+ 'internalname' => 'widget_context',
+ 'value' => $context
+ );
+ echo elgg_view('input/hidden', $params);
+?>
<div class="clearfloat"></div>
</div>
diff --git a/views/default/widgets/add_button.php b/views/default/widgets/add_button.php
index 8ec36b086..2957513b6 100644
--- a/views/default/widgets/add_button.php
+++ b/views/default/widgets/add_button.php
@@ -1,7 +1,7 @@
<?php
?>
-<div class="widget" id="widget_add_button">
+<div id="widget_add_button">
<?php
$options = array(
'href' => '#',