better_messages.inc 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. /*
  3. Admin settings menu callback
  4. */
  5. function better_messages_admin() {
  6. $settings = better_messages_get_settings();
  7. $form['position'] = array(
  8. '#type' => 'fieldset',
  9. '#title' => t('Messages positions and basic properties'),
  10. '#weight' => -5,
  11. '#collapsible' => TRUE,
  12. '#collapsed' => False,
  13. );
  14. $form['position']['pos'] = array(
  15. '#type' => 'radios',
  16. '#title' => t('Set position of Message'),
  17. '#default_value' => $settings['position'],
  18. '#description' => t('Position of message relative to screen'),
  19. '#attributes' => array('class' => array('better-messages-admin-radios')),
  20. '#options' => array(
  21. 'center' => t('Center screen'),
  22. 'tl' => t('Top left'),
  23. 'tr' => t('Top right'),
  24. 'bl' => t('Bottom left'),
  25. 'br' => t('Bottom right')
  26. ),
  27. );
  28. $form['position']['fixed'] = array(
  29. '#type' => 'checkbox',
  30. '#default_value' => $settings['fixed'],
  31. '#title' => t('Keep fixed position of message as you scroll.'),
  32. );
  33. $form['position']['width'] = array(
  34. '#type' => 'textfield',
  35. '#title' => t('Custom width'),
  36. '#description' => t('Width in pixel. Example: 400px<br />Or percentage. Example: 100%'),
  37. '#default_value' => $settings['width'],
  38. '#size' => 20,
  39. '#maxlength' => 20,
  40. '#required' => TRUE,
  41. );
  42. $form['position']['horizontal'] = array(
  43. '#type' => 'textfield',
  44. '#title' => t('Left/Right spacing'),
  45. '#description' => t('In active when position is set to "center".<br />In pixel. Example: 10'),
  46. '#default_value' => $settings['horizontal'],
  47. '#size' => 20,
  48. '#maxlength' => 20,
  49. '#required' => TRUE,
  50. );
  51. $form['position']['vertical'] = array(
  52. '#type' => 'textfield',
  53. '#title' => t('Top/Down spacing'),
  54. '#description' => t('Inactive when position is set to "center".<br />In pixel. Example: 10'),
  55. '#default_value' => $settings['vertical'],
  56. '#size' => 20,
  57. '#maxlength' => 20,
  58. '#required' => TRUE,
  59. );
  60. $form['animation'] = array(
  61. '#type' => 'fieldset',
  62. '#title' => t('Messages animation settings'),
  63. '#weight' => -3,
  64. '#collapsible' => TRUE,
  65. '#collapsed' => TRUE,
  66. );
  67. $form['animation']['popin_effect'] = array(
  68. '#type' => 'select',
  69. '#title' => t('Pop-in (show) message box effect'),
  70. '#default_value' => $settings['popin']['effect'],
  71. '#options' => array(
  72. 'fadeIn' => t('Fade in'),
  73. 'slideDown' => t('Slide down'),
  74. ),
  75. );
  76. $form['animation']['popin_duration'] = array(
  77. '#type' => 'textfield',
  78. '#title' => t('Duration of (show) effect'),
  79. '#description' => t('A string representing one of the three predefined speeds ("slow", "normal", or "fast").<br />Or the number of milliseconds to run the animation (e.g. 1000).'),
  80. '#default_value' => $settings['popin']['duration'],
  81. '#size' => 20,
  82. '#maxlength' => 20,
  83. );
  84. $form['animation']['popout_effect'] = array(
  85. '#type' => 'select',
  86. '#title' => t('Pop-out (close) message box effect'),
  87. '#default_value' => $settings['popout']['effect'],
  88. '#options' => array(
  89. 'fadeIn' => t('Fade out'),
  90. 'slideUp' => t('Slide Up'),
  91. ),
  92. );
  93. $form['animation']['popout_duration'] = array(
  94. '#type' => 'textfield',
  95. '#title' => t('Duration of (close) effect'),
  96. '#description' => t('A string representing one of the three predefined speeds ("slow", "normal", or "fast").<br />Or the number of milliseconds to run the animation (e.g. 1000).'),
  97. '#default_value' => $settings['popout']['duration'],
  98. '#size' => 20,
  99. '#maxlength' => 20,
  100. );
  101. $form['animation']['autoclose'] = array(
  102. '#type' => 'textfield',
  103. '#title' => t('Number of seconds to auto close after the page has loaded'),
  104. '#description' => t('0 for never. You can set it as 0.25 for quarter second'),
  105. '#default_value' => $settings['autoclose'],
  106. '#size' => 20,
  107. '#maxlength' => 20,
  108. );
  109. $form['animation']['disable_autoclose'] = array(
  110. '#type' => 'checkbox',
  111. '#title' => t('Disable auto close if messages inculde an error message'),
  112. '#default_value' => $settings['disable_autoclose'],
  113. );
  114. $form['animation']['show_countdown'] = array(
  115. '#type' => 'checkbox',
  116. '#title' => t('Show countdown timer'),
  117. '#default_value' => $settings['show_countdown'],
  118. );
  119. $form['animation']['hover_autoclose'] = array(
  120. '#type' => 'checkbox',
  121. '#title' => t('Stop auto close timer when hover'),
  122. '#default_value' => $settings['hover_autoclose'],
  123. );
  124. $form['animation']['open_delay'] = array(
  125. '#type' => 'textfield',
  126. '#title' => t('Number of seconds to delay message after the page has loaded'),
  127. '#description' => t('0 for never. You can set it as 0.25 for quarter second'),
  128. '#default_value' => $settings['opendelay'],
  129. '#size' => 20,
  130. '#maxlength' => 20,
  131. );
  132. $form['vis_settings'] = array(
  133. '#type' => 'fieldset',
  134. '#title' => t('Better Messages visibility'),
  135. '#weight' => 0,
  136. '#collapsible' => TRUE,
  137. '#collapsed' => TRUE,
  138. );
  139. $options = array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'));
  140. $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
  141. $form['vis_settings']['visibility'] = array(
  142. '#type' => 'radios',
  143. '#title' => t('Show Better Messages on specific pages'),
  144. '#options' => $options,
  145. '#default_value' => $settings['extra']['visibility'],
  146. );
  147. $form['vis_settings']['pages'] = array(
  148. '#type' => 'textarea',
  149. '#title' => t('Pages'),
  150. '#default_value' => $settings['extra']['pages'],
  151. '#description' => $description,
  152. );
  153. $form['jquery_ui'] = array(
  154. '#type' => 'fieldset',
  155. '#title' => t('jQuery UI enhancements'),
  156. '#weight' => 10,
  157. '#description' => t('These settings require !jquery_ui module to be installed and enabled.', array('!jquery_ui' => l('jQuery UI', 'http://drupal.org/project/jquery_ui'))),
  158. '#collapsible' => TRUE,
  159. '#collapsed' => TRUE,
  160. );
  161. (module_exists('jquery_ui')) ? $jquer_ui_disabled = false : $jquer_ui_disabled = true;
  162. $form['jquery_ui']['draggable'] = array(
  163. '#type' => 'checkbox',
  164. '#disabled' => $jquer_ui_disabled,
  165. '#title' => t('Make Better Messages draggable'),
  166. '#default_value' => $settings['jquery_ui']['draggable'],
  167. );
  168. $form['jquery_ui']['resizable'] = array(
  169. '#type' => 'checkbox',
  170. '#disabled' => $jquer_ui_disabled,
  171. '#title' => t('Make Better Messages resizable'),
  172. '#default_value' => $settings['jquery_ui']['resizable'],
  173. );
  174. $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
  175. $form['#theme'] = 'system_settings_form';
  176. $form['#submit'][] = 'better_messages_admin_submit';
  177. return $form;
  178. }
  179. function better_messages_admin_submit($form, &$form_state) {
  180. $settings = array(
  181. 'position' => $form_state['values']['pos'],
  182. 'vertical' => $form_state['values']['vertical'],
  183. 'horizontal' => $form_state['values']['horizontal'],
  184. 'fixed' => $form_state['values']['fixed'],
  185. 'width' => $form_state['values']['width'],
  186. 'autoclose' => $form_state['values']['autoclose'],
  187. 'opendelay' => $form_state['values']['open_delay'],
  188. 'disable_autoclose' => $form_state['values']['disable_autoclose'],
  189. 'show_countdown' => $form_state['values']['show_countdown'],
  190. 'hover_autoclose' => $form_state['values']['hover_autoclose'],
  191. 'popin' => array('effect' => $form_state['values']['popin_effect'], 'duration' => $form_state['values']['popin_duration']),
  192. 'popout' => array('effect' => $form_state['values']['popout_effect'], 'duration' => $form_state['values']['popout_duration']),
  193. 'jquery_ui' => array('draggable' => $form_state['values']['draggable'], 'resizable' => $form_state['values']['resizable']),
  194. 'extra' => array('pages' => $form_state['values']['pages'], 'visibility' => $form_state['values']['visibility'],
  195. )
  196. );
  197. variable_set('better_messages', $settings);
  198. drupal_set_message(t('The configuration options have been saved.'));
  199. cache_clear_all();
  200. }