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