jQuery-gridmanager icon indicating copy to clipboard operation
jQuery-gridmanager copied to clipboard

Request: custom request headers

Open phroggyy opened this issue 10 years ago • 12 comments

I am currently integrating this with a Laravel application, where CSRF protection is enabled by default. I would love to see request headers integrated into gm, for example through an option gm.requestHeaders = {}, where the default is the aforementioned empty object, which can then be overridden with key-value pairs.

phroggyy avatar Jun 10 '15 08:06 phroggyy

Can you give me an example where this is needed? Is it the save function?

neokoenig avatar Jun 10 '15 08:06 neokoenig

Yep, save function. I fixed it locally for myself, I can either fork you and make a PR, or if you have time to add it yourself, that'd be great.

What I did:

  1. Add requestHeaders: {} to defaultOptions
  2. In the $.ajax of the save function, add headers: gm.options.requestHeaders

phroggyy avatar Jun 10 '15 08:06 phroggyy

It would also be cool if you'd add in a saveData attribute to the options, so that users could extend gm with their own request data (such as a page name, or some type of date, really anything)

phroggyy avatar Jun 10 '15 08:06 phroggyy

Yeah, I'm actually rewriting the whole thing from scratch at the moment. In the new version, you can either use the built in controls like it currently is, or disable them and easily build your own - i.e, there's lots of event driven stuff like .get() to get the contents of the grid, .destroy(), .reset() etc. So hopefully with that version it should be much more flexible for those wanting to do something other than the reason I wrote it!

neokoenig avatar Jun 10 '15 08:06 neokoenig

Oh sweet!

phroggyy avatar Jun 10 '15 08:06 phroggyy

Yeah, may be a little while yet though.. I'll flag this ticket as a feature request to make sure I get some of this functionality in the new version.

neokoenig avatar Jun 10 '15 08:06 neokoenig

Is there a branch on which you're developing the next version/another repo where I could contribute?

phroggyy avatar Jun 10 '15 08:06 phroggyy

Not at the moment, I've only just got the core functions working, and I'm still very much deciding on the best way of doing stuff. TBH I'm not really a javascript developer, so I'm sure I'm doing a bunch of stuff in a more complex way than it needs to be :)

I'll see if I can get something up on a branch in the next week or so.

neokoenig avatar Jun 10 '15 09:06 neokoenig

Grand. I'm no major JS developer either, work mainly in backend, but I work pretty closely with a front-end dev here, and sometimes I end up helping her with things, so I guess I'm at least decent :)

phroggyy avatar Jun 10 '15 09:06 phroggyy

Highly experimental beginnings of a rewrite: https://github.com/neokoenig/jQuery-gridmanager/tree/0.4

Check /src/new.html

instance 2 is pretty much the defaults; instance 1 is me playing with trying to get more external control in.

you can now do things like gm.do("destroy") to kill an instance, add rows etc.etc. or gm.do("get") returns the cleaned contents etc.

Very early stages - just trying to build up a list of the various functionalities which people might want!

neokoenig avatar Jun 12 '15 16:06 neokoenig

Gonna have a look later tonight! I'll probably fork you and do some PRs; I've implemented a couple features for my own project which I could just pull in and add to the branch :)

Also, I'm thinking about a feature which could be very useful, although I'm not yet sure of how it'd work: custom overrides; some streamlined way to implement custom functions and overrides for gridmanager globally, without editing the gm source. One thought is some kind of config file, which has a default path. Since most users will follow default, any instance of gm would use the custom config.

One idea I have is completely overriding functions, so that a user could specify their own save or whatever. Of course, this could probably be done already, but it feels a bit messy, so I'd love if we could together work on streamlining the process

phroggyy avatar Jun 12 '15 16:06 phroggyy

Cool - have a look at the gm.do() wrapper function - this is one idea of being able to autowrap events - i.e, beforesave or aftersave without having to manually specify the function call from within every function. Not sure if this is the best design pattern for it yet.

neokoenig avatar Jun 12 '15 17:06 neokoenig