@@ -10,6 +10,7 @@ interface ItemModel {
1010
1111class BaseModelItem < T extends Item > extends AbstractItem < T > {
1212 adminizer : Adminizer ;
13+ //@ts -ignore
1314 getAddTemplate ( req : ReqType ) : Promise < { type : "component" | "navigation.group" | "navigation.link" | "model" ; data : any ; } > {
1415 throw new Error ( "must be inherited" ) ;
1516 }
@@ -78,27 +79,6 @@ class BaseModelItem<T extends Item> extends AbstractItem<T> {
7879 }
7980
8081
81- public getAddHTML ( ) : Promise < { type : "link" | "html" ; data : string ; } > {
82- let type : 'link' = 'link'
83- let linkMap = this . model === 'dish' ? 'product' : this . model
84- return Promise . resolve ( {
85- type : type ,
86- data : `/admin/model/${ linkMap } s/add?without_layout=true`
87- } )
88- }
89-
90-
91- public async getEditHTML ( id : string | number , parenId ?: string | number ) : Promise < {
92- type : "link" | "html" ;
93- data : string ;
94- } > {
95- let type : 'link' = 'link'
96- let linkMap = this . model === 'dish' ? 'product' : this . model
97- return {
98- type : type ,
99- data : `/admin/model/${ linkMap } s/edit/${ id } ?without_layout=true`
100- }
101- }
10282
10383 public async getChilds ( parentId : string , catalogId : string ) : Promise < Item [ ] > {
10484 const records = await sails . models [ this . model ] . find ( {
@@ -130,18 +110,32 @@ export class Group<GroupProductItem extends Item> extends BaseModelItem<GroupPro
130110 public model : string = "group" ;
131111 public readonly actionHandlers : any [ ] = [ ]
132112
133- public getAddTemplate ( req : ReqType ) : Promise < { type : "component" | "navigation.group" | "navigation.link" | "model" ; data : any ; } > {
134- return Promise . resolve ( {
135- type : "navigation.link" ,
136- data : `/admin/model/groups/add?without_layout=true`
137- } ) ;
138- }
139-
140- public getEditTemplate ( id : string | number , catalogId : string , req : ReqType , modelId ?: string | number ) : Promise < { type : "component" | "navigation.group" | "navigation.link" | "model" ; data : any ; } > {
141- return Promise . resolve ( {
142- type : "navigation.link" ,
143- data : `/admin/model/groups/edit/${ id } ?without_layout=true`
144- } ) ;
113+ async getAddTemplate ( req : any ) : Promise < any > {
114+ return {
115+ type : 'model' ,
116+ data : {
117+ model : this . model ,
118+ labels : {
119+ title : req . i18n . __ ( 'Add Group' ) ,
120+ save : req . i18n . __ ( 'Save' ) ,
121+ } ,
122+ } ,
123+ } ;
124+ }
125+
126+ async getEditTemplate ( id : string | number , catalogId : string , req : any ) : Promise < any > {
127+ const item = await this . find ( id ) ;
128+ return {
129+ type : 'model' ,
130+ data : {
131+ item,
132+ model : this . model ,
133+ labels : {
134+ title : req . i18n . __ ( 'Edit Group' ) ,
135+ save : req . i18n . __ ( 'Save' ) ,
136+ } ,
137+ } ,
138+ } ;
145139 }
146140}
147141
@@ -154,18 +148,29 @@ export class Product<T extends Item> extends BaseModelItem<T> {
154148 public readonly actionHandlers : any [ ] = [ ]
155149 public concept : string = "origin" ;
156150
157- public getAddTemplate ( req : ReqType ) : Promise < { type : "component" | "navigation.group" | "navigation.link" | "model" ; data : any ; } > {
158- return Promise . resolve ( {
159- type : "navigation.link" ,
160- data : `/admin/model/products/add?without_layout=true`
161- } ) ;
151+ public async getAddTemplate ( req : ReqType ) : Promise < { type : "component" | "navigation.group" | "navigation.link" | "model" ; data : any ; } > {
152+ let type : 'model' = 'model'
153+ let itemsDB = await sails . models [ this . model ] . find ( { } )
154+ return {
155+ type : type ,
156+ data : {
157+ model : this . model ,
158+ labels : {
159+ title : req . i18n . __ ( 'Add Product' ) ,
160+ save : req . i18n . __ ( 'Save' ) ,
161+ }
162+ }
163+ }
162164 }
163165
164- public getEditTemplate ( id : string | number , catalogId : string , req : ReqType , modelId ?: string | number ) : Promise < { type : "component" | "navigation.group" | "navigation.link" | "model" ; data : any ; } > {
166+ public async getEditTemplate ( id : string | number , catalogId : string , req : ReqType , modelId ?: string | number ) : Promise < { type : "component" | "navigation.group" | "navigation.link" | "model" ; data : any ; } > {
167+ console . log ( "Product getEditTemplate" , id , catalogId ) ;
165168 return Promise . resolve ( {
166- type : "navigation.link" ,
167- data : `/admin/model/products/edit/${ id } ?without_layout=true`
168- } ) ;
169+ type : 'model' ,
170+ data : {
171+ item : await this . find ( id , catalogId )
172+ }
173+ } )
169174 }
170175}
171176
0 commit comments