softinline/jcrud

使用 JSON 文件定义的 crud 方法,用于 datatables、编辑和添加操作


README

关于 Softinline jCrud

Softinline jCrud 是一个用于 CRUD 数据表和表单生成的包,您可以直接在 JSON 文件中定义,这些文件直接与控制器/模型链接,支持导出、选择行、添加更多按钮,所有这些功能都使用相同的样式。

组件

Softinline jCrud 是一组组件

  • jConfig (加载配置文件) 并提供实时访问配置的 get/set 方法
  • jTable (从 JSON 定义文件生成,可以显示不同的数据表,设置列、可排序、可搜索等...), 一个定义文件可以在不同的名称下存储多个列表,默认我们使用 'index' 列表
  • jForm,这个类提供了关于准备具有不同标签、行和多种输入类型(文本、数字、日期时间、电子邮件、密码、编辑器、自定义、查看等...)的表单的功能
  • jcrud.js(这个 JS 存储有关创建的表格、选择的行、在提交表单之前验证的功能等信息...)

jForm 字段类型

- custom -> call method in controller parent to show some div or HTML code
- file
- date
- datetime
- text
- number
- password
- email
- button -> execute the 'action' key on json defines (normally javascript onclick event)
- checkbox
- textarea
- editor -> replaced with ckeditor needed the plugin installed and initialized
- select -> call controller method defined in 'selector' key on json defines see samples
- select-multiple -> call controller allow multiple selection, controller must return array with 'all' and 'selected' elements
- checkbox-multiple -> same as select-multiple but in checkbox format
- json -> displays information in json field (array) using <pre>
- view -> call view and load, view receives the $config, $item, etc vars with information (see documentation)

*** 
- childrens -> if field element has a children method, the fields inside can be displayed using a validation method that returns true or not, for example if you want to display more fields depends on select response.

一些示例

您可以在 app/Defines (示例) 中定义您的文件,在您的控制器中,您可以使用 jConfig 类来加载您的定义文件,如下所示

var $_jconfig;

/**
* Create a new controller instance.
* @return void
*/
public function __construct() {
    $this->_jconfig = new \Softinline\JCrud\JConfig();
    $this->_jconfig->load(app_path().'/Defines/admin-users.json', 'admin-users');
}
This is a simple basic sample define for table users:
                                
{
    "admin-users":{
        "model":"User",            
        "title":"users",
        "titleCustom":false,        
        "url":"admin/users",
        "layout":"layouts.other",
        "lists":{
            "index":{
                "wrapper":false,
                "datatable":true,
                "class":false,
                "name":"admin-users",
                "cols":[                    
                    {
                        "name":"id",
                        "field":"id",
                        "orderable":true,
                        "searchable":true
                    },
                    {
                        "name":"created_at",
                        "field":"created_at",
                        "orderable":true,
                        "searchable":true
                    },
                    {
                        "name":"email",
                        "field":"email",
                        "orderable":true,
                        "searchable":true
                    },
                    {                        
                        "name":"actions",
                        "field":"actions",
                        "orderable":false,
                        "searchable":false
                    }
                ],                
                "actions":{
                    "add":true,
                    "export":true,
                    "selector":true
                },
                "options":[
                    ["export", "fa fa-file", "js:crud.export"],
                    ["reports", "fa fa-list", "link:admin/users/reports"]
                ],
                "rowCallBack":false,
                "drawCallBack":false
            }
        },
        "forms":{
            "add":{
                "wrapper":false,
                "tabs":{
                    "general":{                    
                        "key":"general",
                        "title":"general",
                        "type":"form",
                            "fields":[                            
                            {
                                "type":"email",
                                "required":true,
                                "title":"email",
                                "field":"email"
                            },
                            {
                                "type":"password",
                                "required":false,
                                "title":"password",
                                "field":"password"
                            }          
                        ],
                        "extraButtons":[]
                    },
                    "advanced":{
                        "key":"advanced",
                        "title":"advanced",
                        "type":"form",
                            "fields":[                            
                            {
                                "type":"textarea",
                                "required":true,
                                "title":"advanced1",
                                "field":"advanced2"
                            }
                        ],
                        "extraButtons":[]
                    },
                    "images":{
                        "key":"images",
                        "title":"images",
                        "type":"form",
                            "fields":[                            
                            {
                                "type":"file",
                                "required":true,
                                "title":"file",
                                "field":"file"
                            }
                        ],
                        "extraButtons":[]
                    }
                }
            },
            "edit":{
                "wrapper":false,
                "field_title":"email",
                "tabs":{
                    "general":{                    
                        "key":"general",
                        "title":"general",
                        "type":"form",
                            "fields":[                            
                            {
                                "type":"email",
                                "required":true,
                                "title":"email",
                                "field":"email"
                            },
                            {
                                "type":"password",
                                "required":false,
                                "title":"password",
                                "field":"password"
                            }                            
                        ],
                        "extraButtons":[]
                    }                    
                }
            }
        }
    }
}

如果您想根据 Bootstrap 使用行和列,您可以使用特殊类型字段 'row',如下所示,每个都可以有 n 个不同类型的字段(文本、密码、编辑器、日期等...)

{
    "type":"row",
    "fields":[
        {
            "type":"text",
            "required":false,
            "title":"field1",
            "field":"field1"
        },
        {
            "type":"text",
            "required":false,
            "title":"field2",
            "field":"field2"
        },
    ]
}

许可

Softinline/JCrud 是开源软件,根据 MIT 许可证 许可。