/[drupal]/contributions/modules/views_savedsearches/views_savedsearches.js
ViewVC logotype

Contents of /contributions/modules/views_savedsearches/views_savedsearches.js

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


Revision 1.4 - (show annotations) (download) (as text)
Tue Jan 27 08:41:51 2009 UTC (9 months, 4 weeks ago) by quicksketch
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +3 -12 lines
File MIME type: text/javascript
Removing firstTime variable, since Views2 positions the form fine already.
1 // $Id: views_savedsearches.js,v 1.3 2009/01/27 07:11:52 quicksketch Exp $
2
3 var ViewsSavedSearches = ViewsSavedSearches || {};
4
5 ViewsSavedSearches.baseContext = function() {
6 var $baseContext;
7
8 if (undefined === $baseContext) {
9 $baseContext = $("div.views-savedsearches-container");
10 }
11 return $baseContext;
12 };
13
14 ViewsSavedSearches.attachBindings = function() {
15 var view_name;
16 var i;
17
18 for (i = 0; i < Drupal.settings.views_savedsearches.view_names.length; i++) {
19 view_name = Drupal.settings.views_savedsearches.view_names[i];
20
21 // Attach the bindings.
22 ViewsSavedSearches.bindings(view_name);
23 }
24 }
25
26 ViewsSavedSearches.bindings = function(view_name) {
27 function ahahDeleteBeforeSubmit(formData, jqForm, options) {
28 // Validate checkboxes: at least one must be checked.
29 if ($('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-list-ahah form:first :checkbox[@checked]').length == 0) {
30 alert("You must select at least one saved search to be deleted!");
31 return false;
32 }
33
34 // The form is validated, it will be submitted. Now let's add the form
35 // data of the views filters form, to be able to check if we should
36 // display the save form.
37 formData.push({ name: 'views_filters_form', value: $('form#views-filters').formSerialize() });
38
39 return true;
40 }
41
42 function ahahSaveBeforeSubmit(formData, jqForm, options) {
43 var $name = $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first input#edit-name');
44
45 // Validate the name field.
46 if ($name.fieldValue()[0].length == 0 || $name.fieldValue()[0].length > 30 ) {
47 alert("You must enter a name for this saved search (maximum 30 characters)!");
48 return false;
49 }
50
51 // The form is validated, it will be submitted. Now let's add the form
52 // data of the views filters form, to save it.
53 formData.push({ name: 'views_filters_form', value: $('form#views-filters').formSerialize() });
54
55 return true;
56 }
57
58 // The target container that will receive the updated filter..
59 var container = $('div#view-'+ view_name +'-savedsearches-container').get(0);
60
61 // List (with delete saved search form).
62 var deleteOptions = {
63 url: Drupal.settings.basePath + Drupal.settings.views_savedsearches.paths.deletePath,
64 beforeSubmit: ahahDeleteBeforeSubmit,
65 target: container,
66 success: function(response, status) {
67 Drupal.attachBehaviors(container);
68 }
69 };
70
71 $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-list-ahah form:first', ViewsSavedSearches.baseContext)
72 .ajaxForm(deleteOptions);
73
74 // Save search form.
75 var saveOptions = {
76 url: Drupal.settings.basePath + Drupal.settings.views_savedsearches.paths.savePath,
77 beforeSubmit: ahahSaveBeforeSubmit,
78 target: container,
79 success: function(response, status) {
80 Drupal.attachBehaviors(container);
81 }
82 };
83 var saveForm = $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first', ViewsSavedSearches.baseContext);
84 $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first', ViewsSavedSearches.baseContext)
85 .ajaxForm(saveOptions);
86 }
87
88 Drupal.behaviors.viewsSavedSearches = function(context) {
89 ViewsSavedSearches.attachBindings();
90 }

  ViewVC Help
Powered by ViewVC 1.1.2