profiledetail.js 4.2 KB

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