2017-11-20 00:10:04 -05:00
|
|
|
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-08-25 00:51:50 -04:00
|
|
|
package form // import "miniflux.app/ui/form"
|
2017-11-20 00:10:04 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2017-11-28 00:30:04 -05:00
|
|
|
|
2018-08-25 00:51:50 -04:00
|
|
|
"miniflux.app/errors"
|
|
|
|
"miniflux.app/model"
|
2017-11-20 00:10:04 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// CategoryForm represents a feed form in the UI
|
|
|
|
type CategoryForm struct {
|
|
|
|
Title string
|
|
|
|
}
|
|
|
|
|
2017-11-28 00:30:04 -05:00
|
|
|
// Validate makes sure the form values are valid.
|
2017-11-20 00:10:04 -05:00
|
|
|
func (c CategoryForm) Validate() error {
|
|
|
|
if c.Title == "" {
|
2018-09-21 21:53:29 -04:00
|
|
|
return errors.NewLocalizedError("error.title_required")
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-28 00:30:04 -05:00
|
|
|
// Merge update the given category fields.
|
2017-11-20 00:10:04 -05:00
|
|
|
func (c CategoryForm) Merge(category *model.Category) *model.Category {
|
|
|
|
category.Title = c.Title
|
|
|
|
return category
|
|
|
|
}
|
|
|
|
|
2017-11-28 00:30:04 -05:00
|
|
|
// NewCategoryForm returns a new CategoryForm.
|
2017-11-20 00:10:04 -05:00
|
|
|
func NewCategoryForm(r *http.Request) *CategoryForm {
|
|
|
|
return &CategoryForm{
|
|
|
|
Title: r.FormValue("title"),
|
|
|
|
}
|
|
|
|
}
|