~ubuntu-branches/ubuntu/lucid/libebox/lucid

« back to all changes in this revision

Viewing changes to src/templates/ajax/modelViewer.mas

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2008-02-27 13:19:28 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080227131928-8mefc35x4h4njvr0
Tags: 0.11.99-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<%flags>
 
2
  inherit => undef
 
3
</%flags>
 
4
<%doc>
 
5
  This template establishes the common things that every model viewer
 
6
  will have
 
7
  Parameters:
 
8
     model - <EBox::Model::DataTable> the model to use its name
 
9
     hasChanged - Boolean indicating whether the model has changed or
 
10
                  not
 
11
     action     - String the action be performed. Only if action is
 
12
                  equal to 'view' the whole model viewer will be
 
13
                  loaded, any other action just the body will be
 
14
                  updated. This behaviour could be enhanced just
 
15
                  printing the updated version of needed. *(Optional)*
 
16
                  Default value: 'view'
 
17
</%doc>
 
18
<%args>
 
19
  $model
 
20
  $hasChanged
 
21
  $action => 'view'
 
22
</%args>
 
23
<%init>
 
24
  use EBox::Gettext;
 
25
</%init>
 
26
 
 
27
% if ( $action eq 'view' or $action eq 'presetUpdate') {
 
28
<& SELF:view,
 
29
   model => $model,
 
30
   hasChanged => $hasChanged
 
31
&>
 
32
% } else {
 
33
<& SELF:body,
 
34
   model => $model,
 
35
   onlyBody => 1,
 
36
&>
 
37
% }
 
38
% # Anyway you should call the change menu sub-component to check if
 
39
% # any change has been done
 
40
<& SELF:changeMenu,
 
41
   hasChanged => $hasChanged
 
42
&>
 
43
 
 
44
 
 
45
<%doc>
 
46
  Method: view
 
47
 
 
48
     Prints the model viewer. This method must be called by every
 
49
     component which inherits from this one. The body is not displayed
 
50
     if the precondition is accomplished, if not a fail message is
 
51
     shown instead.
 
52
 
 
53
  Parameters:
 
54
 
 
55
     model - <EBox::Model::DataTable> the model to view
 
56
     hasChanged - Boolean indicating whether the model has changed or not
 
57
 
 
58
</%doc>
 
59
<%method view>
 
60
<%args>
 
61
  $model
 
62
  $hasChanged
 
63
</%args>
 
64
<& SELF:header,
 
65
   model => $model
 
66
&>
 
67
% if ( $model->precondition() ) {
 
68
<div id="<% $model->modelName() %>">
 
69
  <& SELF:body,
 
70
     model      => $model
 
71
  &>
 
72
</div>
 
73
% }
 
74
% else
 
75
% {
 
76
<div class="note">
 
77
  <% $model->preconditionFailMsg() %>
 
78
</div>
 
79
% }
 
80
</%method>
 
81
 
 
82
<%doc>
 
83
  Method: header
 
84
 
 
85
     Include everything that a model view should have
 
86
 
 
87
  Parameters:
 
88
  
 
89
     model - <EBox::Model::DataTable> the model to view
 
90
</%doc>
 
91
<%method header>
 
92
<%args>
 
93
  $model
 
94
</%args>
 
95
<& SELF:headerScriptSection &>
 
96
<!-- Element to hide the elements while Asynchronous request are -->
 
97
<!-- working. Find more information at "table-helper.js"  -->
 
98
<div id="<% 'hiddenDiv_' . $model->name() | h %>" class="hidden"></div>
 
99
 
 
100
% if ($model->help()) {
 
101
<div class="help">
 
102
  <% $model->help() %>
 
103
</div>
 
104
% }
 
105
 
 
106
<div id='error_<% $model->modelName() | hu %>'></div>
 
107
</%method>
 
108
 
 
109
<%method headerScriptSection>
 
110
<script type="text/javascript" src="/data/js/table-helper.js">
 
111
  //
 
112
</script>
 
113
<script type="text/javascript" src="/data/js/fileUpload.js">//</script>
 
114
</%method>
 
115
 
 
116
 
 
117
<%doc>
 
118
  Method: body
 
119
 
 
120
     Set the model viewer body. The message if any is also shown.
 
121
 
 
122
  Parameters:
 
123
  
 
124
     model - <EBox::Model::DataTable> the model to view
 
125
     onlyBody - boolean indicating if just the body is updated
 
126
                *(Optional)* Default value: false
 
127
     
 
128
</%doc>
 
129
<%method body>
 
130
<%args>
 
131
  $model
 
132
  $onlyBody => 0
 
133
</%args>
 
134
<%init>
 
135
  # Get the content from the first called template
 
136
  my $requestCaller = $onlyBody ? 1 : 2;
 
137
  my @childArgs = $m->caller_args($requestCaller);
 
138
</%init>
 
139
% if ( $model->message() ) {
 
140
<& /msg.mas,
 
141
   msg => $model->popMessage()
 
142
&>
 
143
% }
 
144
<& SELF:_body,
 
145
   model => $model,
 
146
   @childArgs
 
147
&>
 
148
</%method>
 
149
 
 
150
<%doc>
 
151
  Method: title
 
152
 
 
153
     Set the view title
 
154
 
 
155
  Parameters:
 
156
 
 
157
     title - String the title
 
158
 
 
159
</%doc>
 
160
<%method title>
 
161
<%args>
 
162
  $title
 
163
</%args>
 
164
<h3>
 
165
  <%
 
166
    $title | h
 
167
  %>
 
168
</h3>
 
169
</%method>
 
170
 
 
171
<%doc>
 
172
  Method: editForm
 
173
 
 
174
    Show the form to edit the fields from a row
 
175
 
 
176
  Parameters:
 
177
 
 
178
    modelName - String the model name
 
179
    formData - array containing <EBox::Types::Abstract> which form the
 
180
    table row
 
181
 
 
182
</%doc>
 
183
<%method editForm>
 
184
<%args>
 
185
  $modelName
 
186
  @formData
 
187
</%args>
 
188
<table class="formTable">
 
189
  <tbody>
 
190
    <& SELF:editRowFields,
 
191
       modelName => $modelName,
 
192
       formData => \@formData
 
193
    &>
 
194
    <tr>
 
195
      <td class="tright" 
 
196
          id="applyChanges">
 
197
      </td>
 
198
      <& SELF:buttons &>
 
199
    </tr>
 
200
  </tbody>
 
201
</table>
 
202
</%method>
 
203
 
 
204
<%doc>
 
205
  Method: editRowFields
 
206
 
 
207
    Show the form to edit the fields from a row
 
208
 
 
209
  Parameters:
 
210
 
 
211
    modelName - String the model name
 
212
    formData - array containing <EBox::Types::Abstract> which form the
 
213
    table row
 
214
 
 
215
</%doc>
 
216
<%method editRowFields>
 
217
<%args>
 
218
  $modelName
 
219
  @formData
 
220
</%args>
 
221
% foreach my $type (grep { defined($_->HTMLSetter())} @formData) 
 
222
% {
 
223
<tr>
 
224
  <td class='tright'>
 
225
    <% $type->printableName() %>:
 
226
  </td>
 
227
  <td>
 
228
    <&
 
229
      $type->HTMLSetter(),
 
230
      'data' => $type,
 
231
      'tableName' => "$modelName"
 
232
    &>
 
233
  </td>
 
234
</tr>
 
235
% }
 
236
</%method>
 
237
 
 
238
<%doc>
 
239
  Method: buttons
 
240
 
 
241
    Show the button to submit the form. It must be overriden. In order
 
242
    to obtain the main arguments used $m->request_args()->{argName}.
 
243
 
 
244
</%doc>
 
245
<%method buttons>
 
246
</%method>
 
247
 
 
248
<%doc>
 
249
  Method: changeMenu
 
250
 
 
251
     Change the CSS class from the changes menu in order to advise the
 
252
     user some changes have been made
 
253
 
 
254
</%doc>
 
255
<%method changeMenu>
 
256
<%args>
 
257
  $hasChanged
 
258
</%args>
 
259
<script>
 
260
<%perl>
 
261
my $className;
 
262
if ($hasChanged) {
 
263
  $className = 'changed';
 
264
} else {
 
265
  $className = 'notChanged';
 
266
}
 
267
</%perl>
 
268
$('changes_menu').className = '<% $className %>';
 
269
</script>
 
270
</%method>
 
271
 
 
272
<%doc>
 
273
  Group: Protected methods
 
274
</%doc>
 
275
 
 
276
<%doc>
 
277
  Method: _body
 
278
 
 
279
     Set the body for the viewer indeed. This method must be
 
280
     overridden by the subclasses in order to show the model content
 
281
     in some way. 
 
282
 
 
283
     The original parameters from the subclass template must appear as
 
284
     well with their own default values.
 
285
     (Protected method)
 
286
 
 
287
  Parameters:
 
288
 
 
289
     model - <EBox::Model::DataTable> the model to view
 
290
 
 
291
     - Additional parameters, see above.
 
292
 
 
293
</%doc>
 
294
<%method _body>
 
295
% # Default empty implementation
 
296
% $m->call_next();
 
297
</%method>