root / drupal7 / sites / all / modules / field_group / field_group.field_ui.js @ a84ddea4
1 |
|
---|---|
2 |
(function($) { |
3 |
|
4 |
Drupal.behaviors.fieldUIFieldsOverview = { |
5 |
attach: function (context, settings) { |
6 |
$('table#field-overview', context).once('field-field-overview', function() { |
7 |
Drupal.fieldUIOverview.attach(this, settings.fieldUIRowsData, Drupal.fieldUIFieldOverview);
|
8 |
}); |
9 |
} |
10 |
}; |
11 |
|
12 |
/**
|
13 |
* Row handlers for the 'Manage fields' screen.
|
14 |
*/
|
15 |
Drupal.fieldUIFieldOverview = Drupal.fieldUIFieldOverview || {}; |
16 |
|
17 |
Drupal.fieldUIFieldOverview.group = function(row, data) { |
18 |
this.row = row;
|
19 |
this.name = data.name;
|
20 |
this.region = data.region;
|
21 |
this.tableDrag = data.tableDrag;
|
22 |
|
23 |
// Attach change listener to the 'group format' select.
|
24 |
this.$formatSelect = $('select.field-group-type', row); |
25 |
this.$formatSelect.change(Drupal.fieldUIOverview.onChange); |
26 |
|
27 |
return this; |
28 |
}; |
29 |
|
30 |
Drupal.fieldUIFieldOverview.group.prototype = { |
31 |
getRegion: function () { |
32 |
return 'main'; |
33 |
}, |
34 |
|
35 |
regionChange: function (region, recurse) { |
36 |
return {};
|
37 |
}, |
38 |
|
39 |
regionChangeFields: function (region, element, refreshRows) { |
40 |
|
41 |
// Create a new tabledrag rowObject, that will compute the group's child
|
42 |
// rows for us.
|
43 |
var tableDrag = element.tableDrag;
|
44 |
rowObject = new tableDrag.row(element.row, 'mouse', true); |
45 |
// Skip the main row, we handled it above.
|
46 |
rowObject.group.shift(); |
47 |
|
48 |
// Let child rows handlers deal with the region change - without recursing
|
49 |
// on nested group rows, we are handling them all here.
|
50 |
$.each(rowObject.group, function() { |
51 |
var childRow = this; |
52 |
var childRowHandler = $(childRow).data('fieldUIRowHandler'); |
53 |
$.extend(refreshRows, childRowHandler.regionChange(region, false)); |
54 |
}); |
55 |
} |
56 |
}; |
57 |
|
58 |
|
59 |
/**
|
60 |
* Row handlers for the 'Manage display' screen.
|
61 |
*/
|
62 |
Drupal.fieldUIDisplayOverview = Drupal.fieldUIDisplayOverview || {}; |
63 |
|
64 |
Drupal.fieldUIDisplayOverview.group = function(row, data) { |
65 |
this.row = row;
|
66 |
this.name = data.name;
|
67 |
this.region = data.region;
|
68 |
this.tableDrag = data.tableDrag;
|
69 |
|
70 |
// Attach change listener to the 'group format' select.
|
71 |
this.$formatSelect = $('select.field-group-type', row); |
72 |
this.$formatSelect.change(Drupal.fieldUIOverview.onChange); |
73 |
|
74 |
return this; |
75 |
}; |
76 |
|
77 |
Drupal.fieldUIDisplayOverview.group.prototype = { |
78 |
getRegion: function () { |
79 |
return (this.$formatSelect.val() == 'hidden') ? 'hidden' : 'visible'; |
80 |
}, |
81 |
|
82 |
regionChange: function (region, recurse) { |
83 |
|
84 |
// Default recurse to true.
|
85 |
recurse = (recurse == undefined) || recurse;
|
86 |
|
87 |
// When triggered by a row drag, the 'format' select needs to be adjusted to
|
88 |
// the new region.
|
89 |
var currentValue = this.$formatSelect.val(); |
90 |
switch (region) {
|
91 |
case 'visible': |
92 |
if (currentValue == 'hidden') { |
93 |
// Restore the group format back to 'fieldset'.
|
94 |
var value = 'fieldset'; |
95 |
} |
96 |
break;
|
97 |
|
98 |
default:
|
99 |
var value = 'hidden'; |
100 |
break;
|
101 |
} |
102 |
if (value != undefined) { |
103 |
this.$formatSelect.val(value); |
104 |
} |
105 |
|
106 |
var refreshRows = {};
|
107 |
refreshRows[this.name] = this.$formatSelect.get(0); |
108 |
|
109 |
if (recurse) {
|
110 |
this.regionChangeFields(region, this, refreshRows); |
111 |
} |
112 |
|
113 |
return refreshRows;
|
114 |
}, |
115 |
|
116 |
regionChangeFields: function (region, element, refreshRows) { |
117 |
|
118 |
// Create a new tabledrag rowObject, that will compute the group's child
|
119 |
// rows for us.
|
120 |
var tableDrag = element.tableDrag;
|
121 |
rowObject = new tableDrag.row(element.row, 'mouse', true); |
122 |
// Skip the main row, we handled it above.
|
123 |
rowObject.group.shift(); |
124 |
|
125 |
// Let child rows handlers deal with the region change - without recursing
|
126 |
// on nested group rows, we are handling them all here.
|
127 |
$.each(rowObject.group, function() { |
128 |
var childRow = this; |
129 |
var childRowHandler = $(childRow).data('fieldUIRowHandler'); |
130 |
$.extend(refreshRows, childRowHandler.regionChange(region, false)); |
131 |
}); |
132 |
|
133 |
} |
134 |
|
135 |
}; |
136 |
|
137 |
})(jQuery); |