We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37521 ☆ A M B ☆
    • 30 Posts
    I created custom resource class and I would to use MODx.panel.Resource in my application. But it is not convenient a bit. As I see at Articles extra all items on Articles.panel.Container/Article are just rewritten. They have same functionality of MODx.panel.Resource but totally rewritten. Where is program code reuse?
    On the other hand, I can use something like
    Ext.extend(myC.panel.Resource,MODx.panel.Resource,{
        getFields: function(config) {
            var fields = myC.panel.Resource.superclass.getFields(config);
            /* Ext.apply here for EVERY item in the fields. This looks horrible and unconvenient too*/
            return fields;
        }
    });

    What is the way of writing not awkward and reusable code in back-end?
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      The example you show is the way I prefer doing it as well (extending the original one, and overriding functions as you need to), tho I don't see why you would need to Ext.apply on every field. Just use fields.push({ field config }) to add fields.

      Also, I'm pretty sure the panel resource has separate functions for different parts of the panel, allowing you to override only specific parts.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 37521 ☆ A M B ☆
        • 30 Posts
        Quote from: markh at Nov 14, 2012, 07:52 AM
        The example you show is the way I prefer doing it as well (extending the original one, and overriding functions as you need to), tho I don't see why you would need to Ext.apply on every field. Just use fields.push({ field config }) to add fields.

        Also, I'm pretty sure the panel resource has separate functions for different parts of the panel, allowing you to override only specific parts.
        Ext.apply is needed for renaming some fields or change other properties like id and classes.