ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

multiple_line.js
Go to the documentation of this file.
1
6 if( !ultimix )
7 {
8 ultimix = {};
9 }
10
16 if( !ultimix.multiple_line )
17 {
18 ultimix.multiple_line = {};
19 }
20
28 ultimix.multiple_line.CreateMultypleLineControl = function( Object )
29 {
30 jQuery( Object ).wrap( '<div></div>' );
31 jQuery( Object ).css( 'display' , 'none' );
32 }
33
43 ultimix.multiple_line.GetElementCode = function( Control , Object )
44 {
45 var Template = Control.html();
46
47 if( Object )
48 {
49 eval( 'var Data = ' + jQuery( Object ).html() );
50 Template = ultimix.string_utilities.print_record( Template , Data );
51 }
52
53 return( Template );
54 }
55
63 ultimix.multiple_line.ReviseDeleteButtons = function( Selector )
64 {
65 var Container = jQuery( Selector ).parent();
66
67 var Lines = jQuery( Container ).find( 'table.multiple_line_single_line' );
68
69 if( Lines.length == 1 )
70 {
71 Lines.find( 'span.multiple_line_delete_button' ).html( '&nbsp;' );
72 }
73 else
74 {
75 Lines.find( 'span.multiple_line_delete_button' ).html( ultimix.multiple_line.CreateDelButton( Selector ) );
76 }
77 }
78
88 ultimix.multiple_line.OnAddElement = function( Button , Selector )
89 {
90 ultimix.multiple_line.AddLineForSelector(
91 Selector , false , jQuery( Button ).parents( 'table.multiple_line_single_line' )
92 );
93
94 ultimix.multiple_line.ReviseDeleteButtons( Selector );
95 }
96
106 ultimix.multiple_line.OnDelElement = function( Button , Selector )
107 {
108 jQuery( Button ).parents( 'table.multiple_line_single_line' ).remove();
109
110 var Control = jQuery( Selector );
111
112 /* calling event handler */
113 if( jQuery( Control ).attr( 'ondeleteline' ) )
114 {
115 eval( jQuery( Control ).attr( 'ondeleteline' ) );
116 }
117
118 ultimix.multiple_line.ReviseDeleteButtons( Selector );
119 }
120
130 ultimix.multiple_line.GetAddButtonTemplate = function( Selector )
131 {
132 var CustomTemplate = jQuery( Selector ).find( '.add_button_template' ).first();
133
134 if( CustomTemplate.length == 0 )
135 {
136 /* custom template was not found */
137 return(
138 "<span class=\"multiple_line_add_button\"><a class=\"pointer\" style=\"text-decoration: none; " +
139 "font-weight: bold;\" onclick=\"ultimix.multiple_line.OnAddElement( this , '" + Selector +
140 "' );\">+</a></span>"
141 );
142 }
143 else
144 {
145 CustomTemplate = CustomTemplate.html();
146
147 CustomTemplate = ultimix.string_utilities.StrReplace( '[selector]' , Selector , CustomTemplate );
148
149 return( CustomTemplate );
150 }
151 }
152
160 ultimix.multiple_line.CreateAddButton = function( Selector )
161 {
162 return(
163 ultimix.multiple_line.GetAddButtonTemplate( Selector )
164 );
165 }
166
176 ultimix.multiple_line.GetDeleteButtonTemplate = function( Selector )
177 {
178 var CustomTemplate = jQuery( Selector ).find( '.delete_button_template' ).first();
179
180 if( CustomTemplate.length == 0 )
181 {
182 /* custom template was not found */
183 return(
184 "<span class=\"multiple_line_delete_button\"><a class=\"pointer\" style=\"text-decoration: none; " +
185 "font-weight: bold;\" onclick=\"ultimix.multiple_line.OnDelElement( this , '" +
186 Selector + "' );\">-</a></span>"
187 );
188 }
189 else
190 {
191 CustomTemplate = CustomTemplate.html();
192
193 CustomTemplate = ultimix.string_utilities.StrReplace( '[selector]' , Selector , CustomTemplate );
194
195 return( CustomTemplate );
196 }
197 }
198
206 ultimix.multiple_line.CreateDelButton = function( Selector )
207 {
208 return(
209 ultimix.multiple_line.GetDeleteButtonTemplate( Selector )
210 );
211 }
212
226 ultimix.multiple_line.AppendLine = function( Selector , Line , AfterLine )
227 {
228 var Container = jQuery( Selector ).parent();
229 var Code = '<table class="multiple_line_single_line"><tr><td style="width: 10px; font-family:' +
230 'Courier New;">' + ultimix.multiple_line.CreateAddButton( Selector ) + '</td><td style="width: 10px; ' +
231 'font-family: Courier New;">' + ultimix.multiple_line.CreateDelButton( Selector ) + '</td><td style="width: ' +
232 '100%;">' + Line + '</td></tr></table>';
233 var AddedLine = false;
234 if( AfterLine )
235 {
236 jQuery( AfterLine ).after( Code );
237 AddedLine = jQuery( AfterLine ).next();
238 }
239 else
240 {
241 jQuery( Container ).append( Code );
242 AddedLine = jQuery( Container ).find( 'table.multiple_line_single_line' ).last();
243 }
244 jQuery( AddedLine ).find( '.add_button_template,.delete_button_template' ).remove();
245 ultimix.multiple_line.ReviseDeleteButtons( Selector );
246 return( AddedLine );
247 }
248
262 ultimix.multiple_line.AddLineInDOM = function( Selector , Object , AfterLine )
263 {
264 var Control = jQuery( Selector );
265 if( Control.length )
266 {
267 var Line = ultimix.multiple_line.GetElementCode( Control , Object );
268 var AddedLine = ultimix.multiple_line.AppendLine( Selector , Line , AfterLine );
269 if( Object )
270 {
271 jQuery( Object ).remove();
272 }
273 return( AddedLine );
274 }
275 else
276 {
277 if( !Object )return;
278
279 jQuery( Object ).replaceWith(
280 ultimix.get_string( 'dom_element' ) + ' "' + jQuery( Object ).attr( 'control' ) + '" ' +
281 ultimix.get_string( 'was_not_found' )
282 );
283 }
284 }
285
295 ultimix.multiple_line.OnAddLine = function( AddedLine , Data )
296 {
297 for( FieldName in Data )
298 {
299 var Element = jQuery( AddedLine ).find( '[name^=' + FieldName + ']' );
300 if( Element.prop( 'tagName' ) == 'TEXTAREA' )
301 {
302 Element.html( Data[ FieldName ] );
303 }
304 else
305 {
306 Element.val( Data[ FieldName ] );
307 }
308 }
309 }
310
322 ultimix.multiple_line.TriggerOnAddEvent = function( Selector , AddedLine , Data )
323 {
324 var Control = jQuery( Selector );
325
326 /* calling event handler */
327 if( jQuery( Control ).attr( 'onaddline' ) )
328 {
329 eval( jQuery( Control ).attr( 'onaddline' ) + '( AddedLine , Data );' );
330 }
331 else
332 {
333 eval( 'ultimix.multiple_line.OnAddLine( AddedLine , Data );' );
334 }
335 }
336
348 ultimix.multiple_line.AddLineForSelector = function( Selector , Object , AfterLine )
349 {
350 if( Object && jQuery( Object ).html() )
351 {
352 eval( 'var Data = ' + jQuery( Object ).html() );
353 }
354 else
355 {
356 eval( 'var Data = {}' );
357 }
358
359 var AddedLine = ultimix.multiple_line.AddLineInDOM( Selector , Object , AfterLine );
360
361 ultimix.multiple_line.TriggerOnAddEvent( Selector , AddedLine , Data );
362 }
363
371 ultimix.multiple_line.AddLine = function( Object )
372 {
373 ultimix.multiple_line.AddLineForSelector( jQuery( Object ).attr( 'control' ) , Object );
374 }
375
383 ultimix.multiple_line.AddLineInEmptyControl = function( Control )
384 {
385 if( jQuery( Control ).find( 'table.multiple_line_single_line' ).length == 0 )
386 {
387 ultimix.multiple_line.AddLineForSelector( jQuery( Control ).children().first().attr( 'control' ) );
388 }
389 }
390
396 jQuery(
397 function()
398 {
399 jQuery( '.multiple_line_template' ).each(
400 function( Index , Object )
401 {
402 ultimix.multiple_line.CreateMultypleLineControl( Object );
403 }
404 );
405 jQuery( '.multiple_line_element' ).each(
406 function( Index , Object )
407 {
408 ultimix.multiple_line.AddLine( Object );
409 }
410 );
411 jQuery( '.multiple_line_template' ).each(
412 function( Index , Object )
413 {
414 ultimix.multiple_line.AddLineInEmptyControl( jQuery( Object ).parent() );
415 }
416 );
417 }
418 );