0.1.9 • Published 4 years ago
@mysimpleapp/msa-sheet v0.1.9
msa-sheet
MySimpleApp module offering the possibility to create WYSIWYG sheets.
SERVER API
The following code is available by importing the corresponding node module:
// Example
var msaSheet = Msa.require("msa-sheet")
Function: msaSheet.registerType
From index.js
Register a new sheet type.
Each sheet type has its own configuration (default permissions, default content), its own database collection.
// Simple example
msaSheet.registerType("my_sheet_type")
// Complete example
msaSheet.registerType("my_sheet_type", {
// default content
content: "<div>Hello</div>",
// default permissions
perms: {
create: { group:"admin"}
},
// DB collection
dbCollection: "my_sheet_types"
})
- msaSheet.registerType:
Function(type[, args])
- *type:
String
, new sheet type to create and register. - args:
Object
, possible properties are:- content:
HTML Expr
, default sheet content. - perms:
Object
, default user permissions. The possible properties are:- create:
User Expr
, users hqving permission to create sheets of this type.
- create:
- dbCollection:
String
orCollection
, DB collection where sheets of this tpe will be stored.
- content:
- *type:
Function: msaSheet.registerTemplate
From index.js
Register a piece of html to be insertable in a sheet by the user.
// Simple example
var welUrl = Msa.compsUrl+"/my-custom-element/my-custom-element.html"
msaSheet.registerTemplate("My super element", { wel:welUrl })
// Complex example
msaSheet.registerTemplate("My super element", { wel:welUrl },
{
img:"<img src='/url/of/img.jpg'></img>"
})
- msaSheet.registerTemplate:
Function(name, html [, args])
- *name:
String
, name of the template. - *html:
HTML Expr
, content of the template. - args:
Object
, possible properties are:- img:
HTML Expr
, image used in the template selection menu. - head:
HTML Expr
, associated HEAD dependencies on template (if the template is a web element, this field is automatically filled).
- img:
- *name:
Function: msaSheet.registerHead
From index.js
If a HTML element can be inserted in a sheet (with a template for example), and this element needs to import some external content (such as a web component), then this external content needs to be registered with this function.
// Example
var welUrl = Msa.compsUrl+"/my-custom-element/my-custom-element.html"
msaSheet.registerHead("my-custom-element", { html:welUrl })
- msaSheet.registerHead:
Function(tag, head)
- *tag:
String
, tag of the element to register. - *head:
HTML Expr
, HEAD dependencies associated to element.
- *tag:
Function: msaSheet.getSheet
From index.js
Get a formatted sheet from database.
// Simple example
msaSheet.getSheet("page", "home", function(err, sheet){
if(err) console.error(err)
else if(sheet===null) console.log("The requested sheet does not exist")
else console.log("The requested sheet:", sheet)
})
// Complex example
msaSheet.getSheet("page", "home",
{
user: req.session.user
ifNotExist": "create"
},
function(err, sheet){
if(err===401) console.error("User is not authorized to view this sheet")
else if(err) console.error(err)
else console.log("The requested sheet:", sheet)
}
)
- msaSheet.getSheet:
Function(type, name [, args], next)
- *type:
String
, sheet type. - *name:
String
, sheet name. - args:
Object
, possible properties are:- user:
User Object
. - checkUserPerms:
Boolean
, check if user is authorized to view the sheet (default: true if user is provided, false otherwise). - ifNotExist:
String
orFunction()
, behaviour when requested sheet does not exist.- if "null": returned sheet is null (default value).
- if "error": trigger an error.
- if "create": create the sheet (see msaSheet.createSheet for more details).
- if
Function()
, call this function.
- user:
- next:
Function(err, sheet)
- err: returned error (if any).
- sheet: returned sheet.
- *type:
Function: msaSheet.createSheet
From index.js
Create a sheet in database.
// Simple example
msaSheet.createSheet("page", "home", function(err, sheet){
if(err) console.error(err)
else console.log("The created sheet:", sheet)
})
// Complex example
msaSheet.createSheet("page", "home",
{
user: req.session.user
ifExist: "error",
insertInDb: false
},
function(err, sheet){
if(err===401) console.error("User is not authorized to create this sheet")
else if(err) console.error(err)
else console.log("The created sheet:", sheet)
}
)
- msaSheet.createSheet:
Function(type, name [, args], next)
- *type:
String
, sheet type. - *name:
String
, sheet name. - args:
Object
, possible properties are:- user:
User Object
. - checkUserPerms:
Boolean
, check if user is authorized to create the sheet (default: true if user is provided, false otherwise). - ifExist:
String
orFunction()
, behaviour when sheet already exists in database.- if "get": default value, return the sheet that already exists (see msaSheet.getSheet for more details).
- if "null": returned sheet is null.
- if "error": trigger an error.
- if
Function(sheet)
, call this function. *sheet: the sheet that already exists.
- insertInDb: Do insert the created sheet in database (default: true)
- user:
- next:
Function(err, sheet)
- err: returned error (if any).
- sheet: returned created sheet.
- *type:
Function: msaSheet.updateSheet
From index.js
Update a sheet in database.
// Simple example
msaSheet.updateSheet("page", "home",
{ content:"<div>Coucou</div>" },
function(err, sheet){
if(err) console.error(err)
else console.log("The updated sheet:", sheet)
}
)
// Complex example
msaSheet.updateSheet("page", "home",
{ content:"<div>Coucou</div>" },
{
user: req.session.user
ifNotExist: "error",
insertInDb: false
},
function(err, sheet){
if(err===401) console.error("User is not authorized to update this sheet")
else if(err) console.error(err)
else console.log("The updated sheet:", sheet)
}
)
- msaSheet.updateSheet:
Function(type, name, updates [, args], next)
- *type:
String
, sheet type. - *name:
String
, sheet name. - *updates:
Object
, sheet updates. The possible properties are:- content:
HTML Expr
, the new content of the sheet.
- content:
- args:
Object
, possible properties are:- user:
User Object
. - checkUserPerms:
Boolean
, check if user is authorized to create the sheet (default: true if user is provided, false otherwise). - ifNotExist:
String
orFunction()
, behaviour when sheet does not exist in database.- if "create": default value, create a new sheet and update it (see msaSheet.createSheet for more details).
- if "null": returned sheet is null.
- if "error": trigger an error.
- if
Function()
, call this function.
- insertInDb: Do update the created sheet in database (default: true)
- user:
- next:
Function(err, sheet)
- err: returned error (if any).
- sheet: returned updated sheet.
- *type:
LICENSE
MIT