profiledetail.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. var SN_EXTENDED = SN_EXTENDED || {};
  2. SN_EXTENDED.reorder = function (cls) {
  3. var divs = $('div[class=' + cls + ']');
  4. $(divs).each(function (i, div) {
  5. $(div).find('a.add_row').hide();
  6. $(div).find('a.remove_row').show();
  7. SN_EXTENDED.replaceIndex(SN_EXTENDED.rowIndex(div), i);
  8. });
  9. var lastDiv = $(divs).last().closest('tr');
  10. lastDiv.addClass('supersizeme');
  11. $(divs).last().find('a.add_row').show();
  12. if (divs.length == 1) {
  13. $(divs).find('a.remove_row').fadeOut("slow");
  14. }
  15. };
  16. SN_EXTENDED.rowIndex = function (div) {
  17. var idstr = $(div).attr('id');
  18. var id = idstr.match(/\d+/);
  19. return id;
  20. };
  21. SN_EXTENDED.rowCount = function (cls) {
  22. var divs = $.find('div[class=' + cls + ']');
  23. return divs.length;
  24. };
  25. SN_EXTENDED.replaceIndex = function (elem, oldIndex, newIndex) {
  26. $(elem).find('*').each(function () {
  27. $.each(this.attributes, function (i, attrib) {
  28. var regexp = /extprofile-.*-\d.*/;
  29. var value = attrib.value;
  30. var match = value.match(regexp);
  31. if (match !== null) {
  32. attrib.value = value.replace("-" + oldIndex, "-" + newIndex);
  33. }
  34. });
  35. });
  36. }
  37. SN_EXTENDED.resetRow = function (elem) {
  38. $(elem).find('input, textarea').attr('value', '');
  39. $(elem).find('input').removeAttr('disabled');
  40. $(elem).find("select option[value='office']").attr("selected", true);
  41. $(elem).find("input:checkbox").attr('checked', false);
  42. $(elem).find("input[name$=-start], input[name$=-end]").each(function () {
  43. $(this).removeClass('hasDatepicker');
  44. $(this).datepicker({ dateFormat: 'd M yy' });
  45. });
  46. };
  47. SN_EXTENDED.addRow = function () {
  48. var div = $(this).closest('div');
  49. var id = div.attr('id');
  50. var cls = div.attr('class');
  51. var index = id.match(/\d+/);
  52. var newIndex = parseInt(index) + 1;
  53. var newtr = $(div).closest('tr').removeClass('supersizeme').clone();
  54. SN_EXTENDED.replaceIndex(newtr, index, newIndex);
  55. SN_EXTENDED.resetRow(newtr);
  56. $(div).closest('tr').after(newtr);
  57. SN_EXTENDED.reorder(cls);
  58. };
  59. SN_EXTENDED.removeRow = function () {
  60. var div = $(this).closest('div');
  61. var id = $(div).attr('id');
  62. var cls = $(div).attr('class');
  63. var that = this;
  64. $("#confirm-dialog").dialog({
  65. buttons : {
  66. "Confirm" : function () {
  67. $(this).dialog("close");
  68. var target = $(that).closest('tr');
  69. target.fadeOut("slow", function () {
  70. $(target).remove();
  71. SN_EXTENDED.reorder(cls);
  72. });
  73. },
  74. "Cancel" : function () {
  75. $(this).dialog("close");
  76. }
  77. }
  78. });
  79. var cnt = SN_EXTENDED.rowCount(cls);
  80. if (cnt > 1) {
  81. $("#confirm-dialog").dialog("open");
  82. }
  83. };
  84. $(document).ready(function () {
  85. $("#confirm-dialog").dialog({
  86. autoOpen: false,
  87. modal: true
  88. });
  89. $("input#extprofile-manager").autocomplete({
  90. source: 'finduser',
  91. minLength: 2 });
  92. $("input[name$=-start], input[name$=-end], #extprofile-birthday").datepicker({ dateFormat: 'd M yy' });
  93. var multifields = ["phone-item", "experience-item", "education-item", "im-item", 'website-item'];
  94. for (f in multifields) {
  95. SN_EXTENDED.reorder(multifields[f]);
  96. }
  97. $("input#extprofile-manager").autocomplete({
  98. source: 'finduser',
  99. minLength: 2 });
  100. $(document).on('click', '.add_row', SN_EXTENDED.addRow);
  101. $(document).on('click', '.remove_row', SN_EXTENDED.removeRow);
  102. $('input:checkbox[name$=current]').each(function () {
  103. var input = $(this).parent().siblings('input[id$=-end]');
  104. if ($(this).is(':checked')) {
  105. $(input).attr('disabled', 'true');
  106. }
  107. });
  108. $(document).on('click', 'input:checkbox[name$=current]', function () {
  109. var input = $(this).parent().siblings('input[id$=-end]');
  110. if ($(this).is(':checked')) {
  111. $(input).val('');
  112. $(input).attr('disabled', 'true');
  113. } else {
  114. $(input).removeAttr('disabled');
  115. }
  116. });
  117. });