Example #1
0
func (d *ItemDatastore) datastoreKey(id uuid.UUID) *datastore.Key {
	return datastore.NewKey(
		d.context,
		kindItems,
		id.String(),
		0,
		d.rootKey)
}
Example #2
0
func (v *HTMLView) addIDToItemTable(id uuid.UUID) {
	t := reflect.TypeOf((*models.ItemData)(nil)).Elem()

	document := js.Global.Get("document")
	table := document.Call("getElementById", "table_items")
	query := fmt.Sprintf("tr[data-%s=\"%s\"]", datasetAttrID, id.String())
	if 1 <= table.Call("querySelectorAll", query).Length() {
		return
	}
	tr := document.Call("createElement", "tr")
	tr.Get("dataset").Set(toDatasetProp(datasetAttrID), id.String())

	for i := 0; i < t.NumField(); i++ {
		f := t.Field(i)
		if f.Type == reflect.TypeOf((*models.Meta)(nil)).Elem() {
			continue
		}
		td := document.Call("createElement", "td")
		td.Get("dataset").Set(toDatasetProp(datasetAttrKey), f.Name)
		if isNumberType(f.Type) {
			td.Get("classList").Call("add", "number")
		}
		tr.Call("appendChild", td)
	}

	a := document.Call("createElement", "a")
	a.Set("textContent", "Delete")
	a.Call("setAttribute", "href", "")
	td := document.Call("createElement", "td")
	td.Call("appendChild", a)
	td.Get("classList").Call("add", "action")
	a.Set("onclick", async(v.onClickToDelete))
	tr.Call("appendChild", td)

	tbody := table.Call("getElementsByTagName", "tbody").Index(0)
	tbody.Call("appendChild", tr)
}
Example #3
0
func (v *HTMLView) SetEditingItem(id uuid.UUID) {
	document := js.Global.Get("document")
	form := document.Call("getElementById", "form_item")
	form.Get("dataset").Set(toDatasetProp(datasetAttrID), id.String())
}