Giter Club home page Giter Club logo

fakese / genericjquery Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 16 KB

This is a JQuery library which I created in one of my projects and now it's used by all the Team. I'm sharing it for developers to avoid writing tons of code by using ready to use methods from this library. I have also add a description of the architecture that I use to keep my scripts organized and allow any developer to understand easy and fast my projects, you will find that in the README.

JavaScript 100.00%
generic jquery library jquery-library form datatable datatable-serverside events ajax crm pattern architecture

genericjquery's Introduction

GenericJQuery

This is a JQuery library which I created in one of my projects and now it's used by all the Team. I'm sharing it for developers to avoid writing tons of code by using ready to use methods from this library.

If you want, you can use this architecture which I created to organize the JQuery Code in my projects :

  • In you public folder under the JS folder create a folder named "Pages" and for every view create a folder under "Pages" with the same name of the View.
  • For every view create 3 JS files : Crud.js, Constants.js and index.js
  • Crud.js : Will contain all your methods that : ADD/EDIT/DELETE data from servers.
  • Constants.js : Will contain the defenitions of your Routes (URL), Tables Ids (for example: the Id of the table that you will turn it into a DataTable) and any other element Id/Route/Constant that you need in the hole LifeCycle of the view.
  • Index.js : Will contain the rest : Elements to handle, Events to Listent to...

Now let's return to our Library :

  • Most of projects have view that show the details of an entity, the route is generaly in this form : /blabla/.../balala/{id} To avoid making requests or using the server to store the Id of the current record : getDetailId() will return the {id} value from the URL.

  • You have a DataTable and you want to let the user Select rows ? use : InitializeSelection() you can add the class .delete-selection to the delete button so it will stay disabled while the user didn't select a row.

  • You want more ? deleteItems(table, url) : "table" is the DataTable object that you initialized and "url" is the Route to your delete Method : this function will create a list of integer with the IDs of the selected ROWS in the given table and send them to the given URL.

  • This is the best function for me : ajax(data, url, method) : you call it like this : var request = ajax(JSON.stringify(theData), "/your/route", "POST"); request.success(function(result) {/Handle the result/}) / request.fail(function() {/* Handle the fail*/})

  • autoSubmit(button) : Are you lazy ? create a normal form, with it action/Method and submit button, give an Id for your button then for the form give an Id with this form : buttonId+'-form' then use this method just like you use the ajax method ! Example : var addForm = autoSubmit($("#buttonId")); addForm.success(function(result){}) / addForm.fail(function(result){})

  • Everytime you must copy and past the definition of DataTable for each Table you create ? well, this is a lot of code ! just use this :

  • @param {the id of the table that you want to make it a DataTable} id
  • @param {The columnDefs of the DataTable} columnDefs //The definition of the columns (in your Constans file, you will find an example)
  • @param {The URL from where you want to populate the DataTable} url
  • @param {The column Id of the records} rowId //Example : for the products Table, the ID is ProductId so the rowId = "ProductId" which is the name of the Primary Key column, it's usefull for getting informations or deleting
  • @param {Addtional filters you want to add for the DataTable} /Example : filters = [ { id, isList, ignoreOnChange }, { ... }, ... ]

var productsTable = addDataTable(id, columnDefs, url, rowId, filters);

  • check(elementId) : make a normal form with html attributes like : required, max, min... then give that form an Id or if you have multiple forms put them in a single element (a div for example) and give it an Id, then call check(containerId) : this method will validate the form for you ! example of use : if(!check("AddProductForm")) {return;}

I highlited the most used things, the library contain other functions that will make you happy while developing and it's well documented, don't forget to contribute !

genericjquery's People

Contributors

fakese avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.