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

Contents of /contributions/modules/saveguard/saveguard.module

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


Revision 1.7 - (show annotations) (download) (as text)
Sat Aug 22 06:00:14 2009 UTC (3 months ago) by deekayen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +8 -7 lines
File MIME type: text/x-php
Works on 7.x
1 <?php
2 // $Id: saveguard.module,v 1.6 2008/12/12 21:43:13 deekayen Exp $
3
4 /**
5 * @file
6 * Warn user when they are leaving a page with unsaved changes.
7 *
8 * Adds a onBeforeUnload event to all modified forms.
9 */
10
11 /**
12 * Implement hook_menu().
13 */
14 function saveguard_menu() {
15 $items['admin/settings/saveguard'] = array(
16 'title' => 'SaveGuard',
17 'description' => 'Set the popup message text.',
18 'page callback' => 'drupal_get_form',
19 'page arguments' => array('saveguard_admin_settings'),
20 'access callback' => 'user_access',
21 'access arguments' => array('administer site configuration')
22 );
23
24 return $items;
25 }
26
27 /**
28 * Define a settings form.
29 */
30 function saveguard_admin_settings() {
31 $form = array();
32
33 $form['saveguard_message'] = array(
34 '#type' => 'textfield',
35 '#title' => t('Popup Message'),
36 '#default_value' => variable_get('saveguard_message', NULL),
37 );
38
39 return system_settings_form($form);
40 }
41
42
43 /**
44 * Implement hook_form_alter().
45 *
46 * Just add javascript to all forms.
47 *
48 * @param $form_id
49 * name of the form being acted on
50 * @param $form
51 * array with form structure
52 */
53 function saveguard_form_alter(&$form, &$form_state, $form_id) {
54 drupal_add_js(drupal_get_path('module', 'saveguard') . '/saveguard.js');
55 static $done;
56 if (!$done) {
57 $settings['saveguard'] = array(
58 'msg' => variable_get('saveguard_message', NULL),
59 );
60 drupal_add_js($settings, array('type' => 'setting'));
61 $done = TRUE;
62 }
63 }

  ViewVC Help
Powered by ViewVC 1.1.2