diff --git a/demo/controllers/snippet.js b/demo/controllers/snippet.js new file mode 100644 index 00000000..a06a65b5 --- /dev/null +++ b/demo/controllers/snippet.js @@ -0,0 +1,74 @@ +export default { + + resourceName: 'snippet', + resourceCaption: 'title', + + setupList: function({list}) { + + this.addCreateControl('Create new snippet'); + + // -------------------------------------------------------------- + // Filters + // -------------------------------------------------------------- + list.addFilter('TextFormElement', { + name: 'title', + label: 'Title' + }); + + // -------------------------------------------------------------- + // List items + // -------------------------------------------------------------- + list.addItem('TextListItem', { + caption: 'ID', + mapTo: 'id', + addIf: this.screenIsLarge + }); + + list.addItem('LinkListItem', { + caption: 'Title', + mapTo: 'title', + action: 'editItem' + }); + + list.addItem('TextListItem', { + caption: 'Code', + mapTo: 'code' + }); + + list.addItem('TextListItem', { + caption: 'Content', + mapTo: 'content', + limitCharacters: 130, + stripTags: true + }); + + list.addItem('ContextMenuListItem', { + caption: 'Actions', + items: [{caption: 'Edit', action: 'editItem'}] + }); + + }, + + setupEdit: function({edit}) { + + this.addToIndexControl().addSaveControl(); + + edit.addField('TextareaFormElement', { + label: 'Title', + name: 'title', + attributes: {input: {class: 'inputType2 size2 fontBold'}} + }); + + edit.addField('TextFormElement', { + label: 'Code', + name: 'code' + }); + + edit.addField('CodeFormElement', { + label: 'Content', + name: 'content' + }); + + } + +}; diff --git a/demo/mainNavigation.js b/demo/mainNavigation.js index 2bef6c04..4b91f5a5 100644 --- a/demo/mainNavigation.js +++ b/demo/mainNavigation.js @@ -43,6 +43,12 @@ export default { url: router.url('resource.category.index') }, + { + caption: 'Html snippets', + key: 'snippet', + url: router.url('resource.snippet.index') + }, + { caption: 'Tags', key: 'tag', diff --git a/demo/routes.js b/demo/routes.js index 89279680..1594abbb 100644 --- a/demo/routes.js +++ b/demo/routes.js @@ -7,6 +7,7 @@ export default router => { router.resource('user'); router.resource('tag'); router.resource('category'); + router.resource('snippet'); router.resource({name: 'media', hasCreateRoute: ['image', 'videoEmbed', 'file']}); router.controller('my-settings', 'mySettings', 'MySettings'); diff --git a/demo/services.js b/demo/services.js index dae38f61..022d26f8 100644 --- a/demo/services.js +++ b/demo/services.js @@ -8,5 +8,6 @@ export default { UserController: () => import('./controllers/user'), CategoryController: () => import('./controllers/category'), MediaController: () => import('./controllers/media'), + SnippetController: () => import('./controllers/snippet'), MySettingsController: () => import('./controllers/mySettings') }; diff --git a/server/fakeServerConfig.js b/server/fakeServerConfig.js index fe3d733b..8a86a15d 100644 --- a/server/fakeServerConfig.js +++ b/server/fakeServerConfig.js @@ -291,6 +291,42 @@ module.exports = { } }, + snippet: { + filters: { + title: function(title, query) { + return title.toLowerCase().indexOf(query.toLowerCase()) >= 0; + } + }, + validationRules: { + title: { + rule: function(title) { + return title.length > 0; + }, + message: 'Please enter title.' + }, + code: { + rule: function(code) { + return code.length > 0; + }, + message: 'Please enter code.' + } + }, + data: function(random) { + + return range(1, 50).map(function(index) { + return { + type: 'snippet', + id: String(index), + attributes: { + title: 'Snippet ' + index, + code: 'snippet.code.' + index, + content: '

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

' + } + }; + }); + + } + }, category: { filters: { title: function(title, query) {