-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnodejs_demo.module
More file actions
123 lines (112 loc) · 3.42 KB
/
nodejs_demo.module
File metadata and controls
123 lines (112 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/**
* Implements hook_permission().
* @return array
*/
function nodejs_permission() {
return array(
'view nodejs_demo demo' => array(
'title' => t('View the nodejs demo'),
),
);
}
/**
* Implements hook_nodejs_handlers_info().
*
* -> ADD NODEJS Callback handlers ...
*/
function nodejs_demo_nodejs_handlers_info() {
// we don't need this, as our js is explicitly included only on one page ...
return array();
/*
// if we wanted it to handle events on any page ...
return array(
drupal_get_path('module', 'nodejs_demo') . '/nodejs_demo.js',
);
*/
}
/**
* Implements hook_nodejs_user_channels().
*
* -> ANY AUTHENTICATED USER ARE ADDED TO CHANNEL *ONCE* AND ONLY *AT* INITIAL AUTHORISATION!
*/
function nodejs_demo_nodejs_user_channels($account) {
// we don't need this - we use tokenChannels
return array();
}
/**
* Implements hook_menu(),
*/
function nodejs_demo_menu() {
return array(
'nodejs_demo/dashboard' => array(
'access arguments' => array('view nodejs_demo demo'),
'page callback' => 'nodejs_demo_dashboard',
'title' => 'Nodejs Demo Dashboard',
),
'_/nodejs_demo/chaos' => array(
'access arguments' => array('view nodejs_demo demo'),
'page callback' => 'nodejs_demo_chaos',
'title' => 'Chaos',
)
);
}
function nodejs_demo_chaos($type = 'ajax') {
nodejs_enqueue_message(
(object) array(
'channel' => 'nodejs_demo_chaos',
'type' => 'something'
)
);
ajax_deliver('Hello');
}
/**
* Page callback for dashboard
* @return array render array
*/
function nodejs_demo_dashboard() {
// load google viz
drupal_add_js('https://www.google.com/jsapi', 'external');
drupal_add_js('google.load("visualization", "1", {packages: ["corechart"]});', 'inline');
// add this here
drupal_add_js(drupal_get_path('module', 'nodejs_demo') . '/nodejs_demo.js', array('type' => 'file'));
// send a content channel token - we would have to check here if the user has access (if it differs from menu)
nodejs_send_content_channel_token('nodejs_demo_broadcast');
// load the dblog overview to piggyback (it subscribes to watchdog_dblog)
module_load_include('inc', 'dblog', 'dblog.admin');
$content = array();
// ugly, ugly, ugly
$content['nodejs_demo_stream'] = array(
'#type' => 'markup',
'#prefix' => '<div id="nodejs-demo-stream-wrapper" style="width: 400px; height: 300px;">',
'#markup' => t('Please wait while we load realtime data ...'),
'#suffix' => '</div>'
);
$content['nodejs_demo_trigger'] = array(
'#type' => 'markup',
'#prefix' => '<div id="nodejs-demo-trigger-wrapper">',
'#markup' => '<a id="nodejs-demo-trigger" href="#">Create chaos!</a>',
'#suffix' => '</div>'
);
// all i want is a little drupal link ...
drupal_add_library('system', 'drupal.ajax');
drupal_add_library('system', 'jquery.form');
$content['nodejs_demo_trigger_drupal'] = array(
'#type' => 'link',
'#prefix' => '<div id="nodejs-demo-trigger-drupal-wrapper">',
'#href' => '_/nodejs_demo/chaos',
'#title' => t('Create chaos via drupal'),
'#ajax' => array(
'callback' => 'nodejs_demo_chaos',
'wrapper' => 'ajax-response-goes-here',
'method' => 'replace',
'effect' => 'fade',
),
'#suffix' => '</div>'
);
$content += dblog_overview();
// remove the filter forms
unset($content['dblog_filter_form']);
unset($content['dblog_clear_log_form']);
return $content;
}