]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/ExtendedProfile/js/profiledetail.js
initialize fave, sub, and membership URIs
[quix0rs-gnu-social.git] / plugins / ExtendedProfile / js / profiledetail.js
index c1981323992a3e8816add11d53f407fe800075d8..99a3f78a4332536a45e82c3c5fb6b016321e45bb 100644 (file)
@@ -1,38 +1,37 @@
-var reorder = function(class) {
-    console.log("QQQ Enter reorder");
+var SN_EXTENDED = SN_EXTENDED || {};
 
-    var divs = $.find('div[class=' + class + ']');
-    console.log('divs length = ' + divs.length);
+SN_EXTENDED.reorder = function(cls) {
 
-    $(divs).find('a').hide();
+    var divs = $('div[class=' + cls + ']');
 
     $(divs).each(function(i, div) {
-        console.log("ROW " + i);
+        $(div).find('a.add_row').hide();
         $(div).find('a.remove_row').show();
-        replaceIndex(rowIndex(div), i);
+        SN_EXTENDED.replaceIndex(SN_EXTENDED.rowIndex(div), i);
     });
 
+    var lastDiv = $(divs).last().closest('tr');
+    lastDiv.addClass('supersizeme');
+
     $(divs).last().find('a.add_row').show();
 
     if (divs.length == 1) {
-        $(divs).find('a.remove_row').hide();
+        $(divs).find('a.remove_row').fadeOut("slow");
     }
-
 };
 
-var rowIndex = function(div) {
+SN_EXTENDED.rowIndex = function(div) {
     var idstr = $(div).attr('id');
     var id = idstr.match(/\d+/);
-    console.log("id = " + id);
     return id;
 };
 
-var rowCount = function(class) {
-    var divs = $.find('div[class=' + class + ']');
+SN_EXTENDED.rowCount = function(cls) {
+    var divs = $.find('div[class=' + cls + ']');
     return divs.length;
 };
 
-var replaceIndex = function(elem, oldIndex, newIndex) {
+SN_EXTENDED.replaceIndex = function(elem, oldIndex, newIndex) {
     $(elem).find('*').each(function() {
         $.each(this.attributes, function(i, attrib) {
             var regexp = /extprofile-.*-\d.*/;
@@ -40,59 +39,106 @@ var replaceIndex = function(elem, oldIndex, newIndex) {
             var match = value.match(regexp);
             if (match !== null) {
                 attrib.value = value.replace("-" + oldIndex, "-" + newIndex);
-                console.log('match: oldIndex = ' + oldIndex + ' newIndex = ' + newIndex + ' name = ' + attrib.name + ' value = ' + attrib.value);
             }
         });
     });
 }
 
-var resetRow = function(elem) {
-    $(elem).find('input').attr('value', '');
+SN_EXTENDED.resetRow = function(elem) {
+    $(elem).find('input, textarea').attr('value', '');
+    $(elem).find('input').removeAttr('disabled');
     $(elem).find("select option[value='office']").attr("selected", true);
-}
+    $(elem).find("input:checkbox").attr('checked', false);
+    $(elem).find("input[name$=-start], input[name$=-end]").each(function() {
+        $(this).removeClass('hasDatepicker');
+        $(this).datepicker({ dateFormat: 'd M yy' });
+    });
+};
 
-var addRow = function() {
+SN_EXTENDED.addRow = function() {
     var div = $(this).closest('div');
-    var id = $(div).attr('id');
-    var class = $(div).attr('class');
+    var id = div.attr('id');
+    var cls = div.attr('class');
     var index = id.match(/\d+/);
-    console.log("Current row = " + index + ', class = ' + class);
-    var tr = $(this).closest('tr');
-    var newtr = $(tr).clone();
     var newIndex = parseInt(index) + 1;
-    replaceIndex(newtr, index, newIndex);
-    resetRow(newtr);
-    $(tr).after(newtr);
-    reorder(class);
+    var newtr = $(div).closest('tr').removeClass('supersizeme').clone();
+    SN_EXTENDED.replaceIndex(newtr, index, newIndex);
+    SN_EXTENDED.resetRow(newtr);
+    $(div).closest('tr').after(newtr);
+    SN_EXTENDED.reorder(cls);
 };
 
-var removeRow = function() {
+SN_EXTENDED.removeRow = function() {
+
     var div = $(this).closest('div');
     var id = $(div).attr('id');
-    var class = $(div).attr('class');
+    var cls = $(div).attr('class');
+    var that = this;
+
+    $("#confirm-dialog").dialog({
+        buttons : {
+            "Confirm" : function() {
+                $(this).dialog("close");
+                var target = $(that).closest('tr');
+                target.fadeOut("slow", function() {
+                    $(target).remove();
+                    SN_EXTENDED.reorder(cls);
+                });
+            },
+            "Cancel" : function() {
+                $(this).dialog("close");
+            }
+        }
+    });
+
+    var cnt = SN_EXTENDED.rowCount(cls);
 
-    cnt = rowCount(class);
-    console.debug("removeRow - cnt = " + cnt);
     if (cnt > 1) {
-        var target = $(this).closest('tr');
-        target.remove();
-        reorder(class);
+        $("#confirm-dialog").dialog("open");
     }
 };
 
-var init = function() {
-    reorder('phone-item');
-    reorder('experience-item');
-    reorder('education-item');
-    reorder('im-item');
-}
+$(document).ready(function() {
 
-$(document).ready(
+    $("#confirm-dialog").dialog({
+        autoOpen: false,
+        modal: true
+    });
 
-function() {
-    init();
-    $('.add_row').live('click', addRow);
-    $('.remove_row').live('click', removeRow);
-}
+    $("input#extprofile-manager").autocomplete({
+        source: 'finduser',
+        minLength: 2 });
+
+    $("input[name$=-start], input[name$=-end], #extprofile-birthday").datepicker({ dateFormat: 'd M yy' });
+
+    var multifields = ["phone-item", "experience-item", "education-item", "im-item", 'website-item'];
+
+    for (f in multifields) {
+        SN_EXTENDED.reorder(multifields[f]);
+    }
+
+    $("input#extprofile-manager").autocomplete({
+        source: 'finduser',
+        minLength: 2 });
+
+    $('.add_row').live('click', SN_EXTENDED.addRow);
+    $('.remove_row').live('click', SN_EXTENDED.removeRow);
+
+    $('input:checkbox[name$=current]').each(function() {
+        var input = $(this).parent().siblings('input[id$=-end]');
+        if ($(this).is(':checked')) {
+            $(input).attr('disabled', 'true');
+        }
+    });
+
+    $('input:checkbox[name$=current]').live('click', function()  {
+        var input = $(this).parent().siblings('input[id$=-end]');
+        if ($(this).is(':checked')) {
+            $(input).val('');
+            $(input).attr('disabled', 'true');
+        } else {
+            $(input).removeAttr('disabled');
+        }
+    });
 
-);
\ No newline at end of file
+});