ncrossland / ManagerManager

Customise the ModX Evo (1.x) Manager
9 stars 4 forks source link

Problem with moving Custom TVs to tab #8

Open kulmjens opened 11 years ago

kulmjens commented 11 years ago

I came across a problem in ManagerManager 0.3.9 in MODX Evolution 1.0.7. I wanted to use the function mm_moveFieldsToTab to move some TVs to another tab. Some of them are custom TVs and contain select-fields and they weren't moved. :-(

In mm.inc.php there is a function filling the variable $mm_fields. It goes through the TVs an assigns the name and type. Unfortunately there is no case for custom TVs and the default type "input" is used. So it only works for custom TVs with an input textfield.

I added the following to the switch on line 131:

case 'custom_tv':
    $t = 'custom_tv';
break;

Then in fields_inc.php I had to change the default case of the switch in the function mm_moveFieldsToTab on line 268 from

// What type is this field?
if (isset($mm_fields[$field])) {
    $fieldtype = $mm_fields[$field]['fieldtype'];
    $fieldname = $mm_fields[$field]['fieldname'];
    $output .= '
    var toMove = $j("'.$fieldtype.'[name='.$fieldname.']").parents("tr:not(.urltv)"); // Identify the table row to move
    toMove.next("tr").find("td[colspan=2]").parents("tr").remove(); // Get rid of line after, if there is one
    var movedTV = toMove.appendTo("#tab'.$newtab.'>table:first"); // Move the table row
    movedTV.after(ruleHtml); // Insert a rule after 
    movedTV.find("td[width]").attr("width","");  // Remove widths from label column
    $j("[name^='.$fieldname.']:first").parents("td").removeAttr( "style" );  // This prevents an IE6/7 bug where the moved field would not be visible until you switched tabs
    ';
}

to

// What type is this field?
if (isset($mm_fields[$field])) {
    $fieldtype = $mm_fields[$field]['fieldtype'];
    $fieldname = $mm_fields[$field]['fieldname'];
    if($fieldtype == 'custom_tv') {
        $output .= 'var toMove = $j("*[name^='.$fieldname.']").parents("tr:not(.urltv)"); // Identify the table row to move';
    } else {
        $output .= 'var toMove = $j("'.$fieldtype.'[name='.$fieldname.']").parents("tr:not(.urltv)"); // Identify the table row to move';
    }
    $output .= '
    toMove.next("tr").find("td[colspan=2]").parents("tr").remove(); // Get rid of line after, if there is one
    var movedTV = toMove.appendTo("#tab'.$newtab.'>table:first"); // Move the table row
    movedTV.after(ruleHtml); // Insert a rule after 
    movedTV.find("td[width]").attr("width","");  // Remove widths from label column
    $j("[name^='.$fieldname.']:first").parents("td").removeAttr( "style" );  // This prevents an IE6/7 bug where the moved field would not be visible until you switched tabs
    ';
}

Because one doesn't know what kind of input-field a custom TV has, could also be a select or textarea, I used the * to match any element with a name starting with $fieldname. And using [name^= is because selects, checkboxed and radios have a fieldname suffixed with [].

This workaround works for me. Hopefully it will be integrated in the next version of ManagerManager.

kulmjens commented 11 years ago

Oh, I just realized that you can leave out the * before the [name^='.$fieldname.'] statement. :-)