diff --git a/controllers/shopItemController.go b/controllers/shopItemController.go index 7649709..9255607 100644 --- a/controllers/shopItemController.go +++ b/controllers/shopItemController.go @@ -78,6 +78,8 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop image, err := ctx.FormFile("image") dstImage := defaultImagePath printMode := ctx.PostForm("print-mode") + fitToPage := ctx.PostForm("fit-to-page") + customPrintOptions := ctx.PostForm("custom-print-options") if err == nil { dstImage = filepath.Join("static/uploads", image.Filename) @@ -150,18 +152,26 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop }) } + doFit := false + fmt.Println("FitToPage: ", fitToPage) + if fitToPage == "true" { + doFit = true + } + shopItem := models.ShopItem{ - Name: name, - Abstract: abstract, - Description: description, - Category: category, - IsPublic: true, - BasePrice: rc.GetBasePrice(variants), - Image: dstImage, - Pdf: dstPdf, - Variants: variants, - PrintMode: printMode, - WasPrinted: false, + Name: name, + Abstract: abstract, + Description: description, + Category: category, + IsPublic: true, + BasePrice: rc.GetBasePrice(variants), + Image: dstImage, + Pdf: dstPdf, + Variants: variants, + PrintMode: printMode, + WasPrinted: false, + FitToPage: doFit, + CustomPrintOptions: customPrintOptions, } fmt.Println("Creating Shopitem: ", shopItem) @@ -391,17 +401,19 @@ func (rc *shopItemController) AddItemsHandler(c *gin.Context) { } shopItem := models.ShopItem{ - Name: file.Filename, - Abstract: file.Filename, - Description: file.Filename, - Category: category, - IsPublic: true, - BasePrice: rc.GetBasePrice(variants), - Image: dstImage, - Pdf: dstPdf, - Variants: variants, - PrintMode: "CreateBooklet", - WasPrinted: false, + Name: file.Filename, + Abstract: file.Filename, + Description: file.Filename, + Category: category, + IsPublic: true, + BasePrice: rc.GetBasePrice(variants), + Image: dstImage, + Pdf: dstPdf, + Variants: variants, + PrintMode: "CreateBooklet", + WasPrinted: false, + FitToPage: false, + CustomPrintOptions: "", } _, err = repositories.ShopItems.Create(shopItem) @@ -540,6 +552,8 @@ func (rc *shopItemController) EditItemHandler(c *gin.Context) { newShopItem.BasePrice = shopItem.BasePrice newShopItem.IsPublic = shopItem.IsPublic newShopItem.WasPrinted = false + newShopItem.FitToPage = shopItem.FitToPage + newShopItem.CustomPrintOptions = shopItem.CustomPrintOptions if len(shopItem.Tags) != 0 { newShopItem.Tags = shopItem.Tags diff --git a/models/printer.go b/models/printer.go index 98885d1..9ebc7de 100644 --- a/models/printer.go +++ b/models/printer.go @@ -19,6 +19,7 @@ const ( ShortEdge PrintOption = "-o Binding=TopBinding" CreateBooklet PrintOption = "-o Combination=Booklet -o PageSize=A5" TriFold PrintOption = "-o Fold=TriFold -o Binding=TopBinding" + FitToPage PrintOption = "-o fit-to-page" ) type OldPrintJob struct { @@ -101,7 +102,12 @@ func (p *PrintJob) GeneratePrintOptions() []PrintOption { result = append(result, CoverPage) } + if p.ShopItem.FitToPage { + result = append(result, FitToPage) + } + result = append(result, GetPrintMode(p.ShopItem.PrintMode)) + result = append(result, PrintOption(p.ShopItem.CustomPrintOptions)) return result } diff --git a/models/shopItem.go b/models/shopItem.go index 8146878..0b569ed 100644 --- a/models/shopItem.go +++ b/models/shopItem.go @@ -42,16 +42,18 @@ type ItemVariant struct { type ShopItem struct { gorm.Model - Name string `json:"name" binding:"required" gorm:"unique;not null"` - Abstract string `json:"abstract" binding:"required"` - Description string `json:"description" binding:"required"` - Category Category `json:"category"` - Variants []ItemVariant `json:"variant"` - BasePrice float64 `json:"basePrice"` - IsPublic bool `json:"isPublic" gorm:"default:true"` - Tags []Tag `gorm:"many2many:item_tags;"` - Image string - Pdf string - PrintMode string `json:"printMode" gorm:"default:CreateBooklet"` - WasPrinted bool `gorm:"default:false"` + Name string `json:"name" binding:"required" gorm:"unique;not null"` + Abstract string `json:"abstract" binding:"required"` + Description string `json:"description" binding:"required"` + Category Category `json:"category"` + Variants []ItemVariant `json:"variant"` + BasePrice float64 `json:"basePrice"` + IsPublic bool `json:"isPublic" gorm:"default:true"` + Tags []Tag `gorm:"many2many:item_tags;"` + Image string + Pdf string + PrintMode string `json:"printMode" gorm:"default:CreateBooklet"` + CustomPrintOptions string `gorm:"default:''"` + FitToPage bool `gorm:"default:false"` + WasPrinted bool `gorm:"default:false"` } diff --git a/views/edititem.html b/views/edititem.html index aceb630..da9afd4 100644 --- a/views/edititem.html +++ b/views/edititem.html @@ -77,6 +77,20 @@ + + + +
+ + +
+