Anonymous avatar Anonymous committed 73a62e5

[svn r75] edit inline update

Comments (0)

Files changed (4)

media/js/admin/CollapsedInlineFieldsets.js

     $('div[name="inlinerelated"] h3.collapse-toggle').bind("click", function(e){
         $(this).parent().toggleClass('collapsed');
     });
-    /// STACKEDINLINE / INLINEGROUPS
-    $('div[name="inlinegroup"]').each(function(i) {
+    
+    /// INLINEGROUPS (STACKED & TABULAR)
+    $('div.inline-group').each(function() {
         $(this).addClass("collapsed");
         $(this).find('h2:first').attr("class", "collapse-toggle");
     });
-    $('div[name="inlinegroup"] h2.collapse-toggle:first').bind("click", function(e){
+    $('div[name="inlinegroup"] h2.collapse-toggle:first').bind("click", function(){
         $(this).parent().toggleClass('collapsed');
     });
-    /// TABULARINLINE
-    $('div[name="inlinegrouptabular"]').each(function(i) {
-        $(this).addClass("collapsed");
-        $(this).find('h2:first').attr("class", "collapse-toggle");
-    });
-    $('div[name="inlinegrouptabular"] h2.collapse-toggle').bind("click", function(e){
+    $('div[name="inlinegrouptabular"] h2.collapse-toggle:first').bind("click", function(){
         $(this).parent().toggleClass('collapsed');
     });
+    
     /// OPEN STACKEDINLINE WITH ERRORS
     $('div[name="inlinerelated"]').find('div[class*="errors"]:first').each(function(i) {
         /// toggle each inlinerelated with error-rows inside

media/js/admin/Inline.js

+$(document).ready(function(){
+    
+    /// BEHAVIOUR
+    /// DELETED ITEMS will be moved to the end of the group.
+    /// In case of an Error, deleted stay at this position.
+    /// EXTRA ITEMS stay at their position, if they are not empty.
+    /// In case of an Error, empty extra items are moved to the end of
+    /// the list (just before predeleted items).
+    
+    /// BUTTONS (STACKED INLINE)
+    $('div[name="inlinegroup"] a.closehandler').bind("click", function(){
+        $(this).parent().parent().parent().find('div[name="inlinerelated"]').addClass('collapsed');
+    });
+    $('div[name="inlinegroup"] a.openhandler').bind("click", function(){
+        $(this).parent().parent().parent().removeClass('collapsed');
+        $(this).parent().parent().parent().find('div[name="inlinerelated"]').removeClass('collapsed');
+    });
+
+    /// ADDHANDLER
+    // $('div.inline-group a.addhandler').bind("click", function(){
+    //     new_item = $(this).parent().parent().parent().find('div.items div.inline-related:last').clone(true).appendTo($(this).parent().parent().parent().children('.items'));
+    //     items = $(this).parent().parent().parent().find('div.inline-related').length;
+    //     /// change header
+    //     new_item.find('h3:first').html("<b>" + new_item.find('h3:first').text().split("#")[0] + "#" + parseInt(items) + "</b>");
+    //     /// replace IDs, NAMEs, HREFs & FORs ...
+    //     new_html = new_item.html().replace(/-\d+-/g, "-" + parseInt(items - 1) + "-");
+    //     new_item.html(new_html);
+    //     /// reset all form-fields
+    //     new_item.find(':input').val('');
+    //     /// set TOTAL_FORMS to number of items
+    //     new_item.parent().parent().find('input[id*="TOTAL_FORMS"]').val(parseInt(items));
+    //     /// FILEBROWSER SPECIFIC: remove image preview
+    //     new_item.find('img.preview').each(function(i) {
+    //         $(this).attr('src', '');
+    //         $(this).parent().parent().hide();
+    //     });
+    //     /// remove error-lists and error-classes
+    //     new_item.find('ul.errorlist').remove();
+    //     new_item.find('div[class*="errors"]').removeClass("errors");
+    //     /// remove delete-button and button view on site
+    //     new_item.find('a.deletelink').remove();
+    //     new_item.find('a.viewsitelink').remove();
+    //     /// add collapse-functionality
+    //     new_item.find('h3.collapse-toggle').bind("click", function(e){
+    //         $(this).parent().toggleClass('collapsed');
+    //     });
+    // });
+    
+    /// ADDHANDLER
+    $('div.inline-group a.addhandler').bind("click", function(){
+        new_item = $(this).parent().parent().parent().find('div.items div.inline-related:last').clone(true).appendTo($(this).parent().parent().parent().children('.items'));
+        items = $(this).parent().parent().parent().find('div.inline-related').length;
+        /// change header
+        new_item.find('h3:first').html("<b>" + new_item.find('h3:first').text().split("#")[0] + "#" + parseInt(items) + "</b>");
+        /// replace IDs, NAMEs, HREFs & FORs ...
+        new_html = new_item.html().replace(/-\d+-/g, "-" + parseInt(items - 1) + "-");
+        new_item.html(new_html);
+        /// set TOTAL_FORMS to number of items
+        new_item.parent().parent().find('input[id*="TOTAL_FORMS"]').val(parseInt(items));
+        /// remove error-lists and error-classes
+        new_item.find('ul.errorlist').remove();
+        new_item.find('div[class*="errors"]').removeClass("errors");
+        /// remove delete-button and button view on site
+        new_item.find('a.deletelink').remove();
+        new_item.find('a.viewsitelink').remove();
+        /// add collapse-functionality
+        new_item.find('h3.collapse-toggle').bind("click", function(e){
+            $(this).parent().toggleClass('collapsed');
+        });
+    });
+    
+    /// DELETELINK
+    $('div.inline-group input[name*="DELETE"]').hide();
+    $('div.inline-related a.deletelink').bind("click", function() {
+        $(this).prev('input').attr('checked', !$(this).prev('input').attr('checked'));
+        delete_item = $(this).parent().parent().parent();
+        if (delete_item.parent().hasClass('predelete-items')) {
+            new_item = delete_item.clone(true).appendTo(delete_item.parent().prev());
+        } else {
+            new_item = delete_item.clone(true).appendTo(delete_item.parent().next());
+        }
+        delete_item.remove();
+    });
+    
+    /// REORDER
+    $('div.sortable').each(function(i) {
+        items = new Array();
+        predeleted_items_count = $(this).find('input[name*="DELETE"]:checked').length;
+        empty_counter = $(this).find('input[value][id*="order"]').length - predeleted_items_count;
+        $(this).find('div.inline-related').each(function(i) {
+            /// if order field is not set (which is for empty items), set the counter
+            /// so that these fields are shown before the predeleted_items
+            if ($(this).find('input[id*="order"]').val()) {
+                order_value = $(this).find('input[id*="order"]').val();
+            } else {
+                order_value = empty_counter;
+                empty_counter++;
+            }
+            $(this).find('input[id*="order"]').val(order_value);
+            items[parseInt(order_value)] = $(this);
+        });
+        items.sort();
+        $(this).children('div.inline-related').remove();
+        for (var i = 0; i < items.length; i++) {
+            predelete_flag = $(items[i]).find('input[name*="DELETE"]:checked').length;
+            if (predelete_flag) {
+                $(this).children('.predelete-items').append(items[i]);
+            } else {
+                $(this).children('.items').append(items[i]);
+            }
+        }
+    });
+    
+    /// hide all ORDER inputs and their parent DIV
+    //$('div[name="inlinerelated"] input[name*="order"]').hide();
+    $('div.inline-group div.form-row.order').hide();
+    $('div.inline-group div.form-cell.order').hide();
+    
+    /// DRAG & DROP
+    $('div[name="inlinegroup"] a.draghandler').mousedown(function() {
+        // close all inline-related fieldsets before sorting (only STACKED INLINE)
+        $(this).parent().parent().parent().parent().children('div.inline-related').addClass('collapsed');
+    });
+    $('div.sortable .items').sortable({
+        axis: 'y',
+        items: 'div.inline-related',
+        handle: '.draghandler',
+        placeholder: 'placeholder',
+        tolerance: 'intersect',
+        helper: function(e, el) {
+            $("div.sortablehelper").find('h3:first').text(el.find('h3:first').text());
+            return $("div.sortablehelper")
+                .clone()
+                .width(el.width() + 'px')
+                .height(el.height() + 'px');
+        },
+        update: function(e, ui) {
+            /// remove display:block, generated by UI sortable
+            $(this).removeAttr('style');
+        }
+    });
+    
+    // set ORDER_FIELDS on submit
+    $("form").submit(function() {
+        $('div.sortable').each(function() {
+            counter = 0;
+            predelete_counter = $(this).find('div.inline-related').length - $(this).find('input[name*="DELETE"]:checked').length;
+            //order_values = "INITIAL FORMS: " + $(this).find('input[id*="INITIAL_FORMS"]').val() + " / ";
+            //order_values = order_values + "TOTAL FORMS: " + $(this).find('input[id*="TOTAL_FORMS"]').val() + " / ";
+            //order_values = order_values + "ORDER: "
+            $(this).find('div.inline-related').each(function(i) {
+                input_values = "";
+                fields = $(this).find(':input:not([name*="order"])').serializeArray();
+                $.each(fields, function(i, field) {
+                    input_values += field.value;
+                });
+                predelete_flag = $(this).find('input[name*="DELETE"]:checked').length;
+                if (input_values == "") {
+                    /// clear order-field for empty items
+                    $(this).find('input[id*="order"]').val('');
+                } else if (predelete_flag) {
+                    /// reset order-field for predelete-item
+                    $(this).find('input[id*="order"]').val(predelete_counter);
+                    predelete_counter = predelete_counter + 1;
+                } else {
+                    /// reset order-field
+                    $(this).find('input[id*="order"]').val(counter);
+                    counter = counter + 1;
+                }
+                //$(this).find('input[id*="order"]').val(i);
+                //order_values = order_values + $(this).find('input[id*="order"]').val() + " / ";
+            });
+            //$(this).find('input[id*="TOTAL_FORMS"]').val(counter);
+            //order_values = order_values + "NEW TOTAL FORMS: " + $(this).find('input[id*="TOTAL_FORMS"]').val();
+        });
+        //alert(order_values);
+        //return false;
+    });
+    
+});
+
+
+

media/js/admin/StackedInline.js

     /// In case of an Error, empty extra items are moved to the end of
     /// the list (just before predeleted items).
     
-    /// STACKEDINLINE / BUTTONS
+    /// BUTTONS
     $('div[name="inlinegroup"] a.closehandler').bind("click", function(){
         $(this).parent().parent().parent().find('div[name="inlinerelated"]').addClass('collapsed');
     });
     $('div[name="inlinegroup"] a.openhandler').bind("click", function(){
+        $(this).parent().parent().parent().removeClass('collapsed');
         $(this).parent().parent().parent().find('div[name="inlinerelated"]').removeClass('collapsed');
     });
+    
+    /// ADDHANDLER
     $('div[name="inlinegroup"] a.addhandler').bind("click", function(){
         new_item = $(this).parent().parent().parent().find('.items div[name="inlinerelated"]:last').clone(true).appendTo($(this).parent().parent().parent().children('.items'));
         new_item = $(this).parent().parent().parent().find('.items div[name="inlinerelated"]:last');
         items = $(this).parent().parent().parent().find('div[name="inlinerelated"]').length;
         /// change header
-        header = new_item.find('h2:first').text().split("#");
+        header = new_item.find('h3:first').text().split("#");
         new_header = "<b>" + header[0] + "#" + parseInt(items) + "</b>";
-        new_item.find('h2:first').html(new_header);
+        new_item.find('h3:first').html(new_header);
         /// replace IDs, NAMEs, HREFs & FORs ...
         new_html = new_item.html().replace(/-\d+-/g, "-" + parseInt(items - 1) + "-");
         new_item.html(new_html);
         new_item.find('a.deletelink').remove();
         new_item.find('a.viewsitelink').remove();
         /// add collapse-functionality
-        new_item.find('h2.collapse-toggle').bind("click", function(e){
+        new_item.find('h3.collapse-toggle').bind("click", function(e){
             $(this).parent().toggleClass('collapsed');
         });
     });
         delete_item.remove();
     });
     
-    // REORDER INLINE-RELATED
+    // REORDER
     $('div[name="inlinegroup"].sortable').each(function(i) {
         items = new Array();
         predeleted_items_count = $(this).find('input[name*="DELETE"]:checked').length;
         placeholder: 'placeholder',
         tolerance: 'intersect',
         helper: function(e, el) {
-            $("div.sortablehelper").find('h2:first').text(el.find('h2:first').text());
+            $("div.sortablehelper").find('h3:first').text(el.find('h3:first').text());
             return $("div.sortablehelper")
                 .clone()
                 .width(el.width() + 'px')

media/js/admin/TabularInline.js

     /// In case of an Error, empty extra items are moved to the end of
     /// the list (just before predeleted items).
     
+    /// ADDHANDLER
     $('div[name="inlinegrouptabular"] a.addhandler').bind("click", function(){
-        clone_item = $(this).parent().parent().parent().find('.items tr:last')
-        new_item = $(clone_item).clone(true).insertAfter($(clone_item));
-        /// remove 1 from length because of the table-header
-        items = $(this).parent().parent().parent().find('.items tr').length - 1;
+        new_item = $(this).parent().parent().parent().find('.items div[name="inlinerelatedtabular"]:last').clone(true).appendTo($(this).parent().parent().parent().children('.items'));
+        new_item = $(this).parent().parent().parent().find('.items div[name="inlinerelatedtabular"]:last');
+        items = $(this).parent().parent().parent().find('div[name="inlinerelatedtabular"]').length;
+        /// change header
+        header = new_item.find('h3:first').text().split("#");
+        new_header = "<b>" + header[0] + "#" + parseInt(items) + "</b>";
+        new_item.find('h3:first').html(new_header);
         /// replace IDs, NAMEs, HREFs & FORs ...
         new_html = new_item.html().replace(/-\d+-/g, "-" + parseInt(items - 1) + "-");
         new_item.html(new_html);
         /// reset all form-fields
         new_item.find(':input').val('');
         /// set TOTAL_FORMS to number of items
-        new_item.parent().parent().parent().parent().find('input[id*="TOTAL_FORMS"]').val(parseInt(items));
+        new_item.parent().parent().find('input[id*="TOTAL_FORMS"]').val(parseInt(items));
         /// FILEBROWSER SPECIFIC: remove image preview
         new_item.find('img.preview').each(function(i) {
             $(this).attr('src', '');
         new_item.find('a.viewsitelink').remove();
     });
     
-    // REORDER TBODIES
-    $('div[name="inlinegrouptabular"].sortable table').each(function(i) {
+    /// DELETELINK
+    $('div[name="inlinegrouptabular"] input[name*="DELETE"]').hide();
+    $('div[name="inlinerelatedtabular"] a.deletelink').bind("click", function(){
+        $(this).prev('input').attr('checked', !$(this).prev('input').attr('checked'));
+        delete_item = $(this).parent().parent().parent();
+        if (delete_item.parent().hasClass('predelete-items')) {
+            new_item = delete_item.clone(true).appendTo(delete_item.parent().prev());
+        } else {
+            new_item = delete_item.clone(true).appendTo(delete_item.parent().next());
+        }
+        delete_item.remove();
+    });
+    
+    // REORDER
+    $('div[name="inlinegrouptabular"].sortable').each(function(i) {
         items = new Array();
         predeleted_items_count = $(this).find('input[name*="DELETE"]:checked').length;
         empty_counter = $(this).find('input[value][id*="order"]').length - predeleted_items_count;
-        $(this).find('tbody').each(function(i) {
+        $(this).find('div.inline-related').each(function(i) {
             /// if order field is not set (which is for empty items), set the counter
             /// so that these fields are shown before the predeleted_items
             if ($(this).find('input[id*="order"]').val()) {
             items[parseInt(order_value)] = $(this);
         });
         items.sort();
-        $(this).children('tbody').remove();
+        $(this).children('div.inline-related').remove();
         for (var i = 0; i < items.length; i++) {
             predelete_flag = $(items[i]).find('input[name*="DELETE"]:checked').length;
             if (predelete_flag) {
-                $(items[i]).removeClass('item');
-                $(items[i]).addClass('predelete-item');
+                $(this).children('.predelete-items').append(items[i]);
+            } else {
+                $(this).children('.items').append(items[i]);
             }
-            $(this).append(items[i]);
-        } 
+        }
     });
     
-    /// DELETELINK
-    $('div[name="inlinegrouptabular"] input[name*="DELETE"]').hide();
-    $('div[name="inlinegrouptabular"] a.deletelink').bind("click", function(){
-        $(this).prev('input').attr('checked', !$(this).prev('input').attr('checked'));
-        delete_item = $(this).parent().parent().parent().parent().parent(); // tbody
-        if (delete_item.hasClass('item')) {
-            // append to end of table
-            new_item = delete_item.clone(true).appendTo(delete_item.parent());
-        } else {
-            // insertAfter last item (before the first predelete-item)
-            new_item = delete_item.clone(true).insertAfter(delete_item.parent().find('tbody.item:last'));
-        }
-        new_item.toggleClass('item');
-        new_item.toggleClass('predelete-item');
-        delete_item.remove(); // important: remove before insertAfter
-    });
-    
-    function Hinweis () {
-        alert("xxx");
-    };
-    
     /// DRAG & DROP
-    $('div[name="inlinegrouptabular"].sortable').sortable({
+    $('div[name="inlinegrouptabular"].sortable .items').sortable({
         axis: 'y',
-        items: 'tbody.item',
+        items: 'div.inline-related',
         handle: '.draghandler',
         placeholder: 'placeholder',
-        tolerance: 'guess',
-        containment: 'table',
-        start: function(e, ui) {
-            temp_html = ""
-            ui.item.find('tr:last td').each(function() {
-               temp_html += "<td></td>" 
-            });
-            $('tbody.placeholder').html("<tr>" + temp_html + "</tr>");
-        },
-        //forcePlacehholderSize: true,
+        tolerance: 'intersect',
+        //containment: 'parent',
         helper: function(e, el) {
-            $("div.sortablehelper").find('h2:first').text(el.find('p:first').text());
+            $("div.sortablehelper").find('h3:first').text(el.find('h3:first').text());
             return $("div.sortablehelper")
                 .clone()
-                .width(el.width() + 'px');
+                .width(el.width() + 'px')
+                .height(el.height() + 'px');
         },
         update: function(e, ui) {
             /// remove display:block, generated by UI sortable
     
     // set ORDER_FIELDS on submit
     $("form").submit(function() {
-        $('div[name="inlinegrouptabular"].sortable').each(function() {
+        $('div[name="inlinegroup"].sortable').each(function() {
             counter = 0;
-            predelete_counter = $(this).find('tbody').length - $(this).find('input[name*="DELETE"]:checked').length;;
-            $(this).find('tbody').each(function(i) {
+            predelete_counter = $(this).find('div.inline-related').length - $(this).find('input[name*="DELETE"]:checked').length;;
+            $(this).find('div.inline-related').each(function(i) {
                 input_values = "";
                 fields = $(this).find(':input:not([name*="order"])').serializeArray();
                 $.each(fields, function(i, field) {
     });
     
     
-    
 });
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.