Advertisement
Guest User

Untitled

a guest
Nov 6th, 2012
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. if (Drupal.jsEnabled) {
  2. $(document).ready(function() {
  3. /**
  4. * initialize the form
  5. */
  6. hostingSitePopulate('profile');
  7. $('div.hosting-site-form-site-language-options').parent().hide();
  8. $('input[@name=platform]').change(function() {
  9. hostingSitePopulate('profile');
  10. hostingSitePopulate('port');
  11. $('div.hosting-site-form-site-language-options').parent().hide();
  12. $('div.hosting-site-form-site-port-options').parent().hide();
  13. });
  14.  
  15. $('input[@name=profile]').change(function() {
  16. hostingSitePopulate('site_language');
  17. });
  18. });
  19. }
  20.  
  21. /**
  22. * populate the form elements through ajax
  23. */
  24. function hostingSitePopulate(option) {
  25. // initialize variables
  26. parent_field = ((option == 'profile' || option == 'port') ? 'platform' : 'profile');
  27. obj = _hostingSiteField(parent_field);
  28. value = $('input[@name=' + option + ']:checked').val();
  29.  
  30. // add loading animation gif pic
  31. $(obj).parent().eq(0).append("<div id='hm-processing'></div>");
  32.  
  33. // ajax function
  34. var resultOptions = function (data) {
  35. var result = Drupal.parseJson(data);
  36. if (result['status'] == 'TRUE') {
  37. resultID = 'hosting-site-form-' + option.replace('_', '-') + '-options';
  38. if (result['data']) {
  39. // replace form element options
  40. if ($('div.' + resultID).html()) {
  41. $('div.' + resultID).parent().after(result['data']).remove();
  42. $('div.' + resultID).parent().show();
  43. }
  44. else {
  45. $('input.' + resultID).after(result['data']).remove();
  46. $('div.' + resultID).parent().show();
  47. }
  48. // restore choice of last time
  49. $('input[@name=' + option + '][@value=' + value + ']').attr("checked", "checked");
  50. // bind on-change event
  51. if (option == 'profile') {
  52. if (($('input[@name=profile]:checked').val()) || (result['type'] != 'radios')) {
  53. hostingSitePopulate('site_language');
  54. }
  55. if (result['type'] == 'radios') {
  56. $('input[@name=profile]').change(function() {
  57. hostingSitePopulate('site_language');
  58. });
  59. }
  60. }
  61. }
  62. else {
  63. $('div.' + resultID).parent().hide();
  64. }
  65. }
  66. // remove the gif animation
  67. $('div#hm-processing').remove();
  68. }
  69. // prepare url params
  70. params = (option == 'profile' || option == 'port') ? $(obj).val() : ($(obj).val() + '/' + $(_hostingSiteField('platform')).val());
  71. $.get('/hosting/hosting_site_form_populate/' + option + '/' + params, null, resultOptions);
  72. Drupal.attachBehaviors($('div.' + resultID));
  73. }
  74.  
  75. function _hostingSiteField(name) {
  76. obj = 'input[@name=' + name + ']';
  77. if ($(obj).attr('type') != 'hidden') {
  78. obj = 'input[@name=' + name + ']:checked';
  79. }
  80. return obj;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement