|
| 1 | +const fs = require('fs-extra'), |
| 2 | + path = require('path'), |
| 3 | + partialPath = path.join(__dirname, '..', '..', '..','views','pages','partials','create'); |
| 4 | +module.exports = { |
| 5 | + friendlyName: 'View users create', |
| 6 | + description: 'Display "users create" page.', |
| 7 | + exits: { |
| 8 | + success: { |
| 9 | + viewTemplatePath: 'pages/create' |
| 10 | + } |
| 11 | + }, |
| 12 | + fn: async function () { |
| 13 | + let req = this.req, |
| 14 | + res = this.res, |
| 15 | + data = { |
| 16 | + model: 'user', |
| 17 | + header: 'Create New User', |
| 18 | + formItems: { |
| 19 | + displayname: { |
| 20 | + textarea: false, |
| 21 | + text: 'Display Name', |
| 22 | + type: 'text', |
| 23 | + id: 'displayname', |
| 24 | + classes: ['displayname'], |
| 25 | + placeholder: 'Supercool Dude' |
| 26 | + }, |
| 27 | + username: { |
| 28 | + textarea: false, |
| 29 | + text: 'Username', |
| 30 | + type: 'text', |
| 31 | + id: 'username', |
| 32 | + classes: ['username'], |
| 33 | + placeholder: 'sdude' |
| 34 | + }, |
| 35 | + emailaddress: { |
| 36 | + textarea: false, |
| 37 | + text: 'Email Address', |
| 38 | + type: 'text', |
| 39 | + validations: { |
| 40 | + minLength: 5, |
| 41 | + regex: /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ |
| 42 | + }, |
| 43 | + id: 'emailaddress', |
| 44 | + classes: [], |
| 45 | + |
| 46 | + }, |
| 47 | + password: { |
| 48 | + textarea: false, |
| 49 | + text: 'Password', |
| 50 | + type: 'password', |
| 51 | + id: 'password', |
| 52 | + classes: [], |
| 53 | + validations: { |
| 54 | + minLength: 8, |
| 55 | + regex: /(?=.*){8,}/ |
| 56 | + }, |
| 57 | + placeholder: '********' |
| 58 | + }, |
| 59 | + passwordconf: { |
| 60 | + textarea: false, |
| 61 | + text: 'Password (confirm)', |
| 62 | + type: 'password', |
| 63 | + id: 'passwordconf', |
| 64 | + classes: [], |
| 65 | + validations: { |
| 66 | + minLength: 8, |
| 67 | + regex: /(?=.*){8,}/ |
| 68 | + }, |
| 69 | + placeholder: '********' |
| 70 | + } |
| 71 | + }, |
| 72 | + formButtons: { |
| 73 | + Cancel: { |
| 74 | + classes: ['btn-warning','float-left'], |
| 75 | + type: 'submit' |
| 76 | + }, |
| 77 | + Create: { |
| 78 | + classes: ['btn-success','float-right'], |
| 79 | + type: 'submit' |
| 80 | + } |
| 81 | + }, |
| 82 | + partialname: false |
| 83 | + }, |
| 84 | + partial = path.join(partialPath, `${data.model}.js`); |
| 85 | + data.title = `Create New ${data.model.charAt(0).toUpperCase() + data.model.slice(1)}`, |
| 86 | + data.form = await sails.helpers.formGenerator.with({ |
| 87 | + model: data.model, |
| 88 | + method: 'post', |
| 89 | + action: `/${data.model}s/create`, |
| 90 | + id: `${data.model}-create`, |
| 91 | + classes: [`${data.model}-create-form`], |
| 92 | + formItems: data.formItems, |
| 93 | + formButtons: data.formButtons |
| 94 | + }); |
| 95 | + if (fs.existsSync(partial)) { |
| 96 | + data.partialname = partial; |
| 97 | + } |
| 98 | + return data; |
| 99 | + } |
| 100 | +}; |
0 commit comments