[CLOSED] creating a custom class?

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] creating a custom class?

    I rummaged around a bit between the forums and the examples, and couldn't really find anything relating to this - how exactly does one go about creating a custom class in Ext.Net that isn't just a quick derivation?

    Assuming it's sensible, I'm looking to implement a custom data class that I can use to access the same information on both the server- and client-sides to store some relatively static user config data from a database. I can easily implement this in ExtJS, but then I can't tell what the next step for the server-side stuff should be. I could come up with something of my own design to take care of this, but I'd prefer to work within the framework as opposed to around it.

    here's some pseudocode somewhat similar to the structure I need (I left a bunch of stuff out, but it's all the same concept)
    class userInfo {
      id : int
      firstName : string
      lastName : string
      location : string
      locationNbr : int
      permissions : store {
        fields: {
          id : int
          name: string
          create : bool
          read : bool
          update : bool
          delete : bool
        }
      }
    }
    I guess I'm just looking for a shove in the right direction or an answer to the effect of "that's not how you should be thinking about solving that problem."
    Last edited by geoffrey.mcgill; Jul 09, 2010 at 9:31 PM.
  2. #2
    Hi userInfo,

    You mentioned you created this in raw extjs, can you post that code?

    Would this class render in the client just as a static client-side object? or are you using this as a config object for passing into a widget constructor?
    Geoffrey McGill
    Founder
  3. #3
    Geoff,

    I haven't created the ExtJS yet, partially because I wanted to see where this thread would go, and partially because I haven't sat down to figure out all of the requirements yet. On the JS side, I don't intend to make any assignments to the properties - I just need to instantiate the object so I can refer to it later.

    I just threw this together to demonstrate - I didn't try running it, so there could be errors.
    Ext.ns('some.namespace');
    
    some.namespace.UserInfo = function(config) {
        var permissionsData = config.permissionsData;
        delete config.permissionsData;
        
        // assuming config contains firstName, lastName, etc...
        Ext.apply(this, config);
        
        this.permissions = new Ext.data.ArrayStore({
            fields: [
                { name: 'id', type: 'int' },
                { name: 'name', type: 'string' },
                { name: 'create', type: 'boolean' },
                { name: 'read', type: 'boolean' },
                { name: 'update', type: 'boolean' },
                { name: 'delete', type: 'boolean' }
            ],
            data: permissionsData
        });
    }
    
    some.namespace.UserInfo.CREATE = 0;
    some.namespace.UserInfo.READ = 1;
    some.namespace.UserInfo.UPDATE = 2;
    some.namespace.UserInfo.DELETE = 3;
    
    some.namespace.UserInfo.prototype = {
        getPermissions: function (name) {
            var ps = this.permissions,
                recIdx = ps.findExact('name', name),
                rec;
            
            if (recIdx === -1) {
                return null;
            }
            
            rec = ps.getAt(recIdx);
            
            return [ rec.get('create'), rec.get('read'), rec.get('update'), rec.get('delete') ];
        }
    }
    In my old world of ASP 3.0, I just would have spewed out the config and fed it to the JS constructor. I then would have been left to do something completely different to validate what was sent back when that happened.

    Some of the unmentioned properties on the object are things like decimal precision preferences for certain things that are used in setting up renderers. The permissions would be for controlling access to certain functions (add/delete/modify) on different elements that I'd like to check again on the server-side when they click save (in case the user circumvented the disabled bits in the JS). So in this case, I suppose it can be static on the client side.
  4. #4
    Hi,

    Please review the following example
    https://examples1.ext.net/#/Combinat.../Simple_Tasks/

    It contains several custom controls are designed for that example
  5. #5
    Simple Tasks has good examples of strapping existing objects into custom JS classes for additional logic, but I didn't see anything regarding creating new Ext.Net classes.

    Further rummaging seems to point to Ext.Net.StateManagedItem as the class to derive from, and the ConfigOptionAttribute tags tell it how to map the values when emitting the JS. I assume it's taking the full name of the class type and expecting that to exist as a JS class?

    I can use Ext.Net.RecordField and Ext.Net.Parameter as examples for the property management - any tips on how to attach a store? I can lift bits from GridPanelBase if that will work. I'll have to revise my example above to expect the store itself in the config instead of just the data, obviously.
  6. #6
    Hi,

    Simple Tasks contains several custom controls: TasksGrid, TasksTree, TasksTopBar, TaskWindow
    See Ext.Net.Examples\Examples\Combination_Samples\Appl ications\Simple_Tasks\Classes\

    Serialized property should be specify in the ConfigOptions property (you have to override that property), SimpleTasks demonstrates it
  7. #7
    Vlad,

    I understand the customizing controls concept - that isn't what I'm trying to do here, however. Each of the classes you listed is still instantiated as its base class on the JS side:

    • TasksGrid produces config with xtype: "netgrid"
    • TasksTree produces config with xtype: "nettreepanel"
    • TasksTopBar produces config with no xtype -> basic panel
    • TaskWindow produces new Ext.Window()


    I'm looking to create a new Ext.Net class (not namespace, but concept) that will emit javascript to the effect of...
    this.UserInfo1 = new some.namespace.UserInfo({
        firstName: 'Scott',
        lastName: 'Miller',
        // more string and int properties...
        permissions: new Ext.net.Store({
            // store config...
        })
    });
    ...so that I can refer to this.UserInfo1 on both the the client and server and access the same properties (more or less - capitalization differences aside) rather than having different constructs on the client and server sides that are really manifestations of the same data.

    Perhaps what I'm looking for isn't clear because it is indeed falling outside the intended use of the framework (as I suspected was a possibility in the opening post), especially since I didn't find any reference to this sort of thing when searching.
  8. #8
    An update:

    I didn't realize before that StateManagedItem didn't derive from WebControl and therefore couldn't be added to a page directly. So RecordField and Parameter aren't good starting points. It looks like XControl is the least common denominator to use something that can be placed on the page, but I wasn't having luck with that so I tried Component and got better results. I note that the methodology seems to revolve around four files per class:

    1. logic
    2. Builder
    3. Config
    4. ConfigOptions

    I think I'm headed down the correct path in that I set up each of these with some dummy properties and included an override for XControl.InstanceOf and it actually emitted JS that attempted to create the object.

    So I guess now all I'm asking is out of the partial Builder/Config/ConfigOptions, which controls what with regards to server and client JS creation, and assuming you have some utility that generates these, is it something I already have in the heaps of code from svn? I can probably figure out the Builder/Config/ConfigOptions by trial and error, but a quick explanation would go a long way. I'm interested in seeing if these can be set up where something isn't a config option on the server but is still a read-only server-side property that is passed to the JS as config since the server will be responsible for determining the value. The other option would be to set up some other class as a config factory, but I'd rather avoid that since that's basically additional overhead unless it's the only way.
  9. #9
    Hi Scott,

    You don't require the .Builder and .Config classes. Yes, we have a tool that autogenerates both.

    You only really need to focus on the main inherited class and what you inherit from obviously depends on your requirements. Generally anything that is going to get rendered to the client (with extjs client-side rendering capabilities) is going to inherit from at least Component.cs.

    The ConfigOptions do not need to be in a separate file. We just add to a separate partial class because they are autogenerated in the main Ext.Net project. You just need to include the ConfigOptions property override in your inherited class. One ConfigOption for each property that should be rendered to the client in the config object.

    The following is taken from the TextField ConfigOptions partial.

    Example

    /// <summary>
    /// 
    /// </summary>
    [Browsable(false)]
    [EditorBrowsable(EditorBrowsableState.Never)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    [XmlIgnore]
    [JsonIgnore]
    public override ConfigOptionsCollection ConfigOptions
    {
        get
        {
            ConfigOptionsCollection list = base.ConfigOptions;
            
            list.Add("listeners", new ConfigOption("listeners", new SerializationOptions("listeners", JsonMode.Object), null, this.Listeners ));
            list.Add("directEvents", new ConfigOption("directEvents", new SerializationOptions("directEvents", JsonMode.Object), null, this.DirectEvents ));
    
            return list;
        }
    }
    Hope this helps.
    Last edited by geoffrey.mcgill; Jan 19, 2015 at 12:36 AM.
    Geoffrey McGill
    Founder
  10. #10
    Yes, that helps, thank you. I also just verified that assuming I want the ability to construct using config, then I keep the Config bits (without the implicit operator for Builder). And I swapped my base class down to Observable, and that seems to work too - this class doesn't have any visual representation, so I don't need the layout capabilities cluttering up the properties. I also don't really need the listeners, but I can live with that.

    Thanks for putting up with my little discovery mission.
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] Creating custom control on server side
    By AnulekhaK in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Feb 21, 2012, 10:15 AM
  2. [CLOSED] Creating a c# component that generates a JavaScript class
    By PLoch in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Aug 04, 2011, 5:11 PM
  3. [CLOSED] Best practive for creating custom/composite controls
    By anup in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 04, 2011, 11:47 AM
  4. [CLOSED] Creating custom control
    By jchau in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Dec 29, 2010, 6:03 PM
  5. How to create custom client component class?
    By jchau in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 24, 2008, 5:17 AM

Posting Permissions