/[drupal]/contributions/modules/popups/popups.module
ViewVC logotype

Contents of /contributions/modules/popups/popups.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.11 - (show annotations) (download) (as text)
Thu Jul 17 18:48:42 2008 UTC (16 months, 1 week ago) by starbow
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1, DRUPAL-6--2, DRUPAL-7--1, DRUPAL-5
Changes since 1.10: +2 -1 lines
File MIME type: text/x-php
Fixing menu issue for 6.2
1 <?php
2 // $Id: popups.module,v 1.10 2008/03/06 20:32:50 starbow Exp $
3
4 /**
5 * @file popup.module
6 *
7 * This module uses popup modal dalogs to enhance the Administration Pages by allowing pages
8 * to be shown inside modual dialogs.
9 * It also provides a hook_popups for other pages that want to use this functionality.
10 *
11 * @todo
12 * * Adding Javascript into popups doesn't always work.
13 * * tabledrag onmouse up action.
14 * * user.js and teaser.js bugs.
15 * * Get cursor visible in Firefox 2: Ugly! https://bugzilla.mozilla.org/show_bug.cgi?id=167801
16 * * * Also: http://groups.google.com/group/jquery-ui/browse_thread/thread/7d448f5d1d2abd78/e7abb68dd7325952?#e7abb68dd7325952
17 * * * Might not be solvable before FF 3 comes out.
18 * * * Partial fix is :focus {background-color: #FFA}, but does not good for color-blind folk.
19 * * Cache the results of hook_popups.
20 * * Make the message-in-popup behavior configurable (?).
21 * * Taxonomy > Add vocab. Adding second item to page does not trigger d-n-d transformation.
22 * Might be a problem with Taxonomy. Menus doesn't have problem (adds d-n-d on first item).
23 */
24
25
26 // **************************************************************************
27 // CORE HOOK FUNCTIONS ****************************************************
28 // **************************************************************************
29
30 /**
31 * hook_menu
32 *
33 * @return array of new menu items.
34 */
35 function popups_menu() {
36 $items['admin/settings/popups'] = array(
37 'page callback' => 'drupal_get_form',
38 'page arguments' => array('popups_admin_settings'),
39 'title' => 'Popups',
40 'access arguments' => array('administer site configuration'),
41 'description' => 'Configure the page-in-a-dialog behavior.',
42 );
43 $items['popups/proxy'] = array(
44 'page callback' => '_popups_proxy',
45 'type' => MENU_CALLBACK,
46 'access callback' => TRUE,
47 );
48
49 // Items for testing.
50 $items['popups/test'] = array(
51 'title' => 'Popup Test',
52 'page callback' => '_popups_test_popups',
53 'type' => MENU_CALLBACK,
54 'access callback' => TRUE,
55 );
56 $items['popups/test/response'] = array(
57 'title' => 'Popup Test',
58 'page callback' => '_popups_test_response',
59 'type' => MENU_CALLBACK,
60 'access callback' => TRUE,
61 );
62
63 return $items;
64 }
65
66 /**
67 * hook_init
68 *
69 * Look at the page path and see if popup behavior has been requested for any links in this page.
70 */
71 function popups_init() {
72 $popups = popups_get_popups();
73 if (isset($popups[$_GET['q']])) {
74 popups_add_popups( $popups[$_GET['q']] );
75 }
76
77 // Check and see if the page_override param is in the URL.
78 // Note - the magic happens here.
79 // Need to cache the page_override flag in the session, so it will effect
80 // the results page that follows a form submission.
81 if (isset($_GET['page_override'])) {
82 $_SESSION['page_override'] = $_GET['page_override'];
83 }
84
85 // Move the page_override flag back out of the session.
86 if (isset($_SESSION['page_override'])) {
87 // This call will not return on form submission.
88 $return = menu_execute_active_handler();
89
90 // The call did return, so it wasn't a form request,
91 // so we are returning a result, so clear the session flag.
92 $override = $_SESSION['page_override'];
93 unset($_SESSION['page_override']);
94
95 // Menu status constants are integers; page content is a string.
96 if (isset($return) && !is_int($return) && isset($override)) {
97 print theme ($override. '_page', $return);
98 exit; // Do not continue processing request in index.html.
99 }
100 }
101
102 }
103
104 /**
105 * hook_theme
106 *
107 */
108 function popups_theme($existing, $type) {
109 return array(
110 'popup_page' => array(
111 'arguments' => array('content' => NULL),
112 // 'template' => 'popup-xml-page',
113 ),
114 );
115 }
116
117 function theme_popup_page($content) {
118 return drupal_json(array(
119 'title' => drupal_get_title(),
120 'messages' => theme('status_messages'),
121 'path' => $_GET['q'],
122 'content' => $content,
123 ));
124 }
125
126 /**
127 * hook_form_alter
128 *
129 * Look at the form_id and see if popup behavior has been requested for any links in this form.
130 *
131 * @param form_array $form
132 * @param array $form_state
133 * @param str $form_id:
134 */
135 function popups_form_alter(&$form, $form_state, $form_id) {
136 // print $form_id;
137 // Add popup behavior to the form if requested.
138 $popups = popups_get_popups();
139 if (isset($popups[$form_id])) {
140 popups_add_popups( $popups[$form_id] );
141 }
142 }
143
144 // **************************************************************************
145 // UTILITY FUNCTIONS ******************************************************
146 // **************************************************************************
147
148 /**
149 * Build the list of popup rules from all modules that implement hook_popups.
150 *
151 * @todo - Add some caching so we don't rebuild everytime.
152 */
153 function popups_get_popups() {
154 static $popups = NULL;
155 if (!isset($popups)) {
156 $popups = module_invoke_all('popups');
157 }
158 return $popups;
159 }
160
161 /**
162 * Attach the popup behavior to the page.
163 *
164 * The default behavoir of a popup is to open a form that will modify the original page. The popup submits
165 * the form and reloads the original page with the resulting new content. The popup then replaces
166 * the original page's content area with the new copy of that content area.
167 *
168 * @param array $rule: Array of rules to apply to the page or form, keyed by jQuery link selector.
169 * Options:
170 * noReload: Does the popup NOT modify the original page (Default: false).
171 * updateTitle: Does the popup modify the title of the current page (Default: false).
172 * surpressMessages: Don't show the messages the form returns in a popup (Default: false).
173 * targetSelector: Defines the area on the original page that will be updated (Default: system-wide setting)
174 * resultsSubselector: Defines the resulting new content to put into the targetSelector (Default: use the entire new results)
175 * TODO - come up with a good use cases for resultsSubselector and targetSelector.
176 * singleRow: Array of selectors descripting the elements inside a row to be replaced (Default: replace entire targetSelector)
177 * additionalJavascript: Array of JavaScript files that must be included to correctly run the page in the popup.
178 * additionalCss: Array of CSS files that must be included to correctly style the page in the popup.
179 *
180 * Rule Format Example:
181 * 'admin/content/taxonomy' => array( // Act only on the links on this page.
182 * 'div#tabs-wrapper a:eq(1)', // No options, so use defaults. Note: Selector must select <a> element(s).
183 * 'table td:nth-child(2) a' => array(
184 * 'noReload' => true, // Popup will not modify original page.
185 * ),
186 * )
187 *
188 */
189 function popups_add_popups($rules=null) {
190 static $added = FALSE;
191 if (!$added) {
192 drupal_add_css(drupal_get_path('module', 'popups') .'/popups.css');
193 drupal_add_js(drupal_get_path('module', 'popups') .'/popups.js');
194 drupal_add_js('misc/jquery.form.js');
195 if (is_array($rules)) {
196 $settings = array( 'popups' => array(
197 'defaultTargetSelector' => variable_get('popups_content_selector', 'div.left-corner > div.clear-block:last'),
198 'defaultTitleSelector' => variable_get('popups_title_selector', 'div.left-corner > h2:eq(0)'),
199 'links' => array(),
200 ));
201 foreach ($rules as $popup_selector => $options) {
202 if (is_array($options)) {
203 $settings['popups']['links'][$popup_selector] = $options;
204 if (isset($options['additionalJavascript']) && is_array($options['additionalJavascript'])) {
205 foreach ($options['additionalJavascript'] as $file) {
206 drupal_add_js($file);
207 }
208 }
209 if (isset($options['additionalCss']) && is_array($options['additionalCss'])) {
210 foreach ($options['additionalCss'] as $file) {
211 drupal_add_css($file);
212 }
213 }
214 }
215 else {
216 $settings['popups']['links'][$options] = array();
217 }
218 }
219 drupal_add_js( $settings, 'setting' );
220 }
221
222 $added = TRUE;
223 }
224 }
225
226 /**
227 * hook_popups
228 *
229 * This implements hook_popups, defined in popups_get_popups.
230 * It adds page-in-popup behavior to the core admin pages.
231 * See the comments in popups_add_popups for explination of the options.
232 *
233 * @return: Array of link selectors to apply popup behavior to.
234 * Keyed by path or form_id.
235 */
236 function popups_popups() {
237 // $operations = preg_replace('/[\W]+/', '-', strtolower(t('Operations')));
238
239 return array(
240 'admin/build/block' => array( // Blocks admin page.
241 '#tabs-wrapper a[href$=admin/build/block/add]', // Add Block
242 '#blocks a[href~=admin/build/block/configure]' => array( // configure
243 'additionalJavascript' => array('misc/collapse.js'),
244 ),
245 '#blocks a[href~=admin/build/block/delete]', // delete
246 ),
247 'admin/build/path' => array( // URL aliases admin page.
248 '#tabs-wrapper a[href$=admin/build/path/add]', // Add alias
249 'td:nth-child(3) a[href~=admin/build/path/edit]', // edit alias
250 'td:nth-child(4) a[href~=admin/build/path/delete]', // delete alias
251 ),
252 'admin/content/taxonomy' => array( // Taxonomy admin page.
253 // TODO: If there are not more than one items to start with, d-n-d files aren't loaded into page.
254 // This causes trouble when the 2nd item is added, no d-n-d.
255 // Might be bug in taxonomy table building (or at least inconsistancy).
256 '#tabs-wrapper a[href$=admin/content/taxonomy/add/vocabulary]' => array( // Add vocabulary
257 'additionalJavascript' => array('misc/tabledrag.js'),
258 ),
259 '#taxonomy-overview-vocabularies td a:contains('. t('edit vocabulary') .')', // edit vocabulary
260 '#taxonomy-overview-vocabularies td a:contains('. t('list terms') .')' => array( // list terms
261 'noReload' => true,
262 'additionalJavascript' => array('misc/tabledrag.js'),
263 ),
264 '#taxonomy-overview-vocabularies td a:contains('. t('add terms') .')' => array( // add terms
265 'noReload' => true,
266 'additionalJavascript' => array('misc/collapse.js'),
267 ),
268 ),
269 'admin/content/types' => array( // Content Type admin page
270 '#tabs-wrapper a[href$=admin/content/types/add]' => array( // Add content type
271 'additionalJavascript' => array('misc/collapse.js'),
272 ),
273 'table td:nth-child(4) a, table td:nth-child(5) a' // edit, delete
274 ),
275 'admin/content/node' => array( // Existing Content admin page
276 '#node-admin-content td a:contains('. t('edit') .')' => array( // edit
277 'additionalJavascript' => array('misc/collapse.js'),
278 // TODO: teaser.js not working: Drupal.settings.teaser has no properties
279 // 'additionalJavascript' => array('misc/collapse.js', 'misc/teaser.js'),
280 )
281 ),
282 'page_node_form' => array( // Node edit form
283 'a[href$=filter/tips]' => array( // Fixes insane "More information..." link
284 'noReload' => true,
285 //TODO 'addCloseButton' => true - just an idea.
286 )
287 ),
288 'admin/content/comment' => array( // Comments admin page.
289 'table td:nth-child(2) a' => array( // view (TODO: popup too small)
290 'noReload' => true,
291 'additionalCss' => array(), //TODO: needs some custom css to get #comments to stay in the popup (no -25px margin).
292 ),
293 '#comment-admin-overview td a:contains('. t('edit') .')' => array( // edit
294 'additionalJavascript' => array('misc/collapse.js'),
295 ),
296 ),
297 'admin/user/rules' => array( // Access rules admin page.
298 '#tabs-wrapper a[href$=admin/user/rules/add]', // Add rule
299 'table td:nth-child(4) a, table td:nth-child(5) a', // edit, delete
300 '#tabs-wrapper a[href$=/admin/user/rules/check]' => array( // Check rule
301 'noReload' => true,
302 ),
303 ),
304 'admin/user/user' => array( // Manage all users admin page.
305 //Add user (TODO: Can't test, keeps crashing apache!)
306 '#tabs-wrapper a[href$=admin/user/user/create]' => array(
307 // TODO: "translate has no properties" user.js line 16.
308 'additionalJavascript' => array(drupal_get_path('module', 'user') .'/user.js'),
309 ),
310 '#user-admin-account td:nth-child(2) a' => array( // View the user
311 'noReload' => true,
312 ),
313
314 ),
315 'menu_overview_form' => array( // Menu admin form.
316 // Add Item, , edit, delete
317 '#tabs-wrapper a:eq(1), table#menu-overview td:nth-child(5) a, table#menu-overview td:nth-child(6) a',
318 '#tabs-wrapper a:eq(2)' => array( // Edit menu: update just page title.
319 'updateTitle' => true,
320 'noReload' => true,
321 ),
322 ),
323
324 // CCK - Manage fields page.
325 'content_admin_field_overview_form' => array(
326 'div#tabs-wrapper a:eq(0)' => array( // Edit
327 'updateTitle' => true,
328 'noReload' => true,
329 ),
330 'div#tabs-wrapper a:eq(2)' => array( // Display fields
331 'noReload' => true,
332 ),
333 'div#tabs-wrapper a:eq(3), div#tabs-wrapper a:eq(4)', // Add field, Add group
334 'table td:nth-child(5) a' => array( // configure
335 'singleRow' => array( 'td:eq(0)' ), // Just update the row (still expiremental).
336 ),
337 'table td:nth-child(6) a', // remove
338 ),
339 );
340 }
341
342 // **************************************************************************
343 // ADMIN SETTINGS *********************************************************
344 // **************************************************************************
345
346 function popups_admin_settings() {
347 drupal_set_title("Popups Settings");
348 $form = array();
349
350 $form['popups_title_selector'] = array(
351 '#type' => 'textfield',
352 '#title' => t('Title Selector'),
353 '#default_value' => variable_get('popups_title_selector', 'div.left-corner > h2:eq(0)'),
354 '#description' => t("jQuery selector to define the pag'e title on your Admin theme."),
355 );
356 $form['popups_content_selector'] = array(
357 '#type' => 'textfield',
358 '#title' => t('Content Selector'),
359 '#default_value' => variable_get('popups_content_selector', 'div.left-corner > div.clear-block:last'),
360 '#description' => t('jQuery selector to define the page\'s content area on your Admin theme.'),
361 );
362
363 return system_settings_form($form);
364 }
365
366 // **************************************************************************
367 // TESTING ****************************************************************
368 // **************************************************************************
369
370 function _popups_submit() {
371 // watchdog( "Debug", "_popups_submit" );
372 // drupal_set_message( "_popups_submit" );
373 print theme( 'popups_page', 'Congratulations' );
374 }
375
376 function _popups_test_popups() {
377 popups_add_popups();
378 $output = '';
379 $output .= l("Pop up entire local page.", 'popups/test/response', array('attributes' => array('class' => 'popups'))) ."<br />";
380 // $output .= l("Pop up entire local page.", drupal_get_path('module', 'popups') . '/test.html', array('attributes' => array('class' => 'popups'))) ."<br />";
381 // $output .= l("Pop up Google", 'http://google.com', array('attributes' => array('class' => 'popups-html'))) ."<br />";
382 return $output;
383 }
384
385 function _popups_test_response() {
386 drupal_set_title("A Popup Test");
387 return "<div>Hello World</div>";
388 }
389

  ViewVC Help
Powered by ViewVC 1.1.2