summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryoung hahn2009-09-25 21:15:16 (GMT)
committer young hahn2009-09-25 21:15:16 (GMT)
commitfc13c716e1e06825f8e4e267ecd5d7838dc5f70c (patch)
tree6e0f617123072185b0792d4898134c4ab6a29f27
parentb49571b76bde8958918d55b7d0275389fc49bac1 (diff)
Rendering a placeholder when no active node is present for replacement upon AJAX selection.
-rw-r--r--data_node/data_node.js13
-rw-r--r--data_node/data_node.module14
-rw-r--r--data_node/views/data_node_views_handler_field_add_remove.inc7
3 files changed, 30 insertions, 4 deletions
diff --git a/data_node/data_node.js b/data_node/data_node.js
index 8cba7a6..74539e2 100644
--- a/data_node/data_node.js
+++ b/data_node/data_node.js
@@ -54,6 +54,19 @@ Drupal.behaviors.data_node = function(context) {
stale_nid = url[1];
}
});
+
+ $('span.data-node-placeholder').each(function() {
+ var classes = $(this).attr('class').split(' ');
+ for (var key in classes) {
+ if (classes[key].indexOf('data_node_link') === 0) {
+ // 0: table, 1: id, 2: nid
+ var split = classes[key].replace('data_node_link-', '').split('-');
+ stale.push(split[1]);
+ break;
+ }
+ }
+ });
+
$.getJSON(ajax_url, {'ajax': 1, 'stale': stale.join('-')}, function(data) {
if (data['status']) {
for (var id in data['refresh']) {
diff --git a/data_node/data_node.module b/data_node/data_node.module
index 010a681..78eff61 100644
--- a/data_node/data_node.module
+++ b/data_node/data_node.module
@@ -414,7 +414,17 @@ function data_node_render_labels($table, $id) {
}
/**
- * Render node-data labels for a given item.
+ * Render a placeholder when there are no active nodes that can be replaced via AJAX.
+ */
+function data_node_render_placeholder_link($table, $id) {
+ drupal_add_css(drupal_get_path('module', 'data_node') . '/data_node.css');
+ drupal_add_js(drupal_get_path('module', 'data_node') . '/data_node.js');
+ $table_name = $table->get('name');
+ return "<span class='data-node-placeholder data_node_link-{$table_name}-{$id}-0'></span>";
+}
+
+/**
+ * Render an add link for a given item..
*/
function data_node_render_add_link($table, $id, $nid) {
drupal_add_css(drupal_get_path('module', 'data_node') . '/data_node.css');
@@ -427,7 +437,7 @@ function data_node_render_add_link($table, $id, $nid) {
}
/**
- * Render node-data labels for a given item.
+ * Render a remove link for a given item.
*/
function data_node_render_remove_link($table, $id, $nid) {
drupal_add_css(drupal_get_path('module', 'data_node') . '/data_node.css');
diff --git a/data_node/views/data_node_views_handler_field_add_remove.inc b/data_node/views/data_node_views_handler_field_add_remove.inc
index 94975c4..c58542c 100644
--- a/data_node/views/data_node_views_handler_field_add_remove.inc
+++ b/data_node/views/data_node_views_handler_field_add_remove.inc
@@ -28,11 +28,14 @@ class data_node_views_handler_field_add_remove extends views_handler_field {
function render($values) {
if (user_access('manage data relations')) {
$id = $values->{$this->id};
+ $table = data_get_table($this->table_name);
+ $node_list = data_node_get_nids($table, $id);
if ($nid = data_node_get_active($this->table_name)) {
- $table = data_get_table($this->table_name);
- $node_list = data_node_get_nids($table, $id);
return in_array($nid, $node_list) ? data_node_render_remove_link($table, $id, $nid) : data_node_render_add_link($table, $id, $nid);
}
+ else {
+ return data_node_render_placeholder_link($table, $id);
+ }
}
}
}