ultimix
forms.js
Go to the documentation of this file.
1 
6 if( !ultimix )
7 {
8  ultimix = {};
9 }
10 
16 if( !ultimix.forms )
17 {
18  ultimix.forms = {};
19 }
20 
30 ultimix.forms.enter_processor = function( e , Id )
31 {
32  if( e.keyCode == 13 )
33  {
34  document.getElementById( Id ).submit();
35  }
36 }
37 
45 ultimix.forms.enter_was_pressed = function( e )
46 {
47  return( e.keyCode == 13 );
48 
49 }
50 
60 ultimix.forms.triple_set_checkbox_click = function( Id , Name )
61 {
62  var Checkbox = document.getElementById( '_checkbox_' + Id );
63  var Value = document.getElementById( Id );
64 
65  if( Value.value == 0 )
66  {
67  jQuery( Checkbox ).prop( 'checked' , true );
68  Checkbox.disabled = false;
69  Value.value = 1;
70  return;
71  }
72 
73  if( Value.value == 1 )
74  {
75  jQuery( Checkbox ).prop( 'checked' , true );
76  Checkbox.disabled = true;
77  Value.value = 2;
78  return;
79  }
80 
81  if( Value.value == 2 )
82  {
83  jQuery( Checkbox ).prop( 'checked' , false );
84  Checkbox.disabled = false;
85  Value.value = 0;
86  return;
87  }
88 }
89 
99 ultimix.forms.double_set_checkbox_click = function( Id , Name )
100 {
101  var Checkbox = document.getElementById( '_checkbox_' + Id );
102  var Value = document.getElementById( Id );
103 
104  if( Value.value == 0 )
105  {
106  jQuery( Checkbox ).prop( 'checked' , true );
107  Value.value = 1;
108  return;
109  }
110 
111  if( Value.value == 1 )
112  {
113  jQuery( Checkbox ).prop( 'checked' , false );
114  Value.value = 0;
115  return;
116  }
117 }
118 
130 ultimix.forms.set_action_and_method = function( FormId , Action , Method )
131 {
132  if( Action )
133  {
134  document.getElementById( FormId ).setAttribute( 'action' , Action );
135  }
136  if( Method )
137  {
138  document.getElementById( FormId ).setAttribute( 'method' , Method );
139  }
140 }
141 
155 ultimix.forms.submit_form_and_wait = function( FormId , Action , Waiting , Method )
156 {
157  ultimix.forms.set_action_and_method( FormId , Action , Method );
158 
159  document.getElementById( FormId ).submit();
160 
161  if( Waiting )
162  {
163  ultimix.std_dialogs.SimpleWaitingMessageBox();
164  }
165 }
166 
176 ultimix.forms.confirm_submit = function( ConfirmString , Success )
177 {
178  if( ConfirmString )
179  {
180  ultimix.std_dialogs.QuestionMessageBox( ConfirmString , Success );
181  return;
182  }
183 
184  Success( ultimix.std_dialogs.MB_YES );
185 }
186 
196 ultimix.forms.form_exists = function( FormId )
197 {
198  if( document.getElementById( FormId ) == null )
199  {
200  ultimix.std_dialogs.ErrorMessageBox( 'Form ' + FormId + ' was not found' );
201  return( false );
202  }
203  return( true );
204 }
205 
221 ultimix.forms.submit_form_0 = function( FormId , ConfirmString , Action , Waiting , Method )
222 {
223  if( !ultimix.forms.form_exists( FormId ) )
224  {
225  return;
226  }
227  var Success = function( Result )
228  {
229  if( Result == ultimix.std_dialogs.MB_YES )
230  {
231  ultimix.forms.submit_form_and_wait( FormId , Action , Waiting , Method );
232  }
233  }
234  ultimix.forms.confirm_submit( ConfirmString , Success );
235 }
236 
246 ultimix.forms.item_exists = function( Name )
247 {
248  if( document.getElementById( Name ) == null )
249  {
250  ultimix.std_dialogs.ErrorMessageBox( 'Field ' + Name + ' was not found' );
251  return( false );
252  }
253  return( true );
254 }
255 
275 ultimix.forms.submit_form_1 = function( FormId , Param1 , Value1 , ConfirmString , Action , Waiting , Method )
276 {
277  if( !ultimix.forms.form_exists( FormId ) || !ultimix.forms.item_exists( Param1 ) )
278  {
279  return;
280  }
281  var Success = function( Result )
282  {
283  if( Result == ultimix.std_dialogs.MB_YES )
284  {
285  document.getElementById( Param1 ).setAttribute( 'value' , Value1 );
286  ultimix.forms.submit_form_and_wait( FormId , Action , Waiting , Method );
287  }
288  }
289  ultimix.forms.confirm_submit( ConfirmString , Success );
290 }
291 
315 ultimix.forms.submit_form_2 = function( FormId , Param1 , Value1 , Param2 , Value2 ,
316  ConfirmString , Action , Waiting , Method )
317 {
318  if( !ultimix.forms.form_exists( FormId ) || !ultimix.forms.item_exists( Param1 ) ||
319  !ultimix.forms.item_exists( Param2 ) )
320  {
321  return;
322  }
323  var Success = function( Result )
324  {
325  if( Result == ultimix.std_dialogs.MB_YES )
326  {
327  document.getElementById( Param1 ).setAttribute( 'value' , Value1 );
328  document.getElementById( Param2 ).setAttribute( 'value' , Value2 );
329  ultimix.forms.submit_form_and_wait( FormId , Action , Waiting , Method );
330  }
331  }
332  ultimix.forms.confirm_submit( ConfirmString , Success );
333 }
334 
362 ultimix.forms.submit_form_3 = function( FormId , Param1 , Value1 , Param2 , Value2 , Param3 , Value3 ,
363  ConfirmString , Action , Waiting , Method )
364 {
365  if( !ultimix.forms.form_exists( FormId ) || !ultimix.forms.item_exists( Param1 ) ||
366  !ultimix.forms.item_exists( Param2 ) || !ultimix.forms.item_exists( Param3 ) )
367  {
368  return;
369  }
370  var Success = function( Result )
371  {
372  if( Result == ultimix.std_dialogs.MB_YES )
373  {
374  document.getElementById( Param1 ).setAttribute( 'value' , Value1 );
375  document.getElementById( Param2 ).setAttribute( 'value' , Value2 );
376  document.getElementById( Param3 ).setAttribute( 'value' , Value3 );
377  ultimix.forms.submit_form_and_wait( FormId , Action , Waiting , Method );
378  }
379  }
380  ultimix.forms.confirm_submit( ConfirmString , Success );
381 }
382 
392 ultimix.forms.get_item_value = function( Item )
393 {
394  var TagName = jQuery( Item ).prop( 'tagName' ).toLowerCase();
395  switch( TagName )
396  {
397  case( 'textarea' ):
398  case( 'select' ):
399  return( jQuery( Item ).val() );
400  case( 'input' ):
401  var Type = jQuery( Item ).prop( 'type' ).toLowerCase();
402  if( Type == 'checkbox' )
403  {
404  return( jQuery( Item ).prop( 'checked' ) ? 1 : 0 );
405  }
406  if( ( Type == 'radio' && jQuery( Item ).prop( 'checked' ) ) || Type == 'text' ||
407  Type == 'hidden' || Type == 'password' )
408  {
409  return( jQuery( Item ).val() );
410  }
411  }
412 }
413 
423 ultimix.forms.extract_form_data = function( Selector )
424 {
425  var Items = jQuery( Selector ).find( '*' ).andSelf();
426  var Data = new Object();
427 
428  for( var i = 0 ; i < Items.length ; i++ )
429  {
430  if( jQuery( Items[ i ] ).attr( 'name' ) )
431  {
432  Data[ jQuery( Items[ i ] ).attr( 'name' ) ] = ultimix.forms.get_item_value( Items[ i ] );
433  }
434  }
435 
436  return( Data );
437 }
438 
450 ultimix.forms.update_record = function( id , Prefix , Method )
451 {
452  ultimix.forms.submit_form_2(
453  Prefix + '_form' , Prefix + '_context_action' , 'update_record_form' , Prefix + '_record_id' ,
454  id , '' , '' , false , Method
455  );
456 }
457 
467 ultimix.forms.cancel_search = function( ElementId , Speed )
468 {
469  if( document.getElementById( 'search_string' ).value == '' )
470  {
471  ultimix.ToggleElement( ElementId , Speed );
472  }
473  else
474  {
475  document.getElementById( 'search_string' ).value = '';
476  window.location.href = window.location.href;
477  }
478 }
479 
489 ultimix.forms.move_value_to = function( Obj , DestinationObjectId )
490 {
491  document.getElementById( DestinationObjectId ).value = Obj.value;
492 }