Ejemplo n.º 1
0
func (self *FormFieldFactory) NewInput(withLabel bool, metaData *model.MetaData, form *view.Form) (view.View, error) {
	if imageRef, ok := metaData.Value.Addr().Interface().(*ImageRef); ok {
		thumbnailFrame := &view.Div{
			Class: "thumbnail-frame",
			Style: fmt.Sprintf("width:%dpx;height:%dpx;", self.ThumbnailSize, self.ThumbnailSize),
		}
		if !imageRef.IsEmpty() {
			image, err := imageRef.Image()
			if err != nil {
				return nil, err
			}
			version, err := image.Thumbnail(self.ThumbnailSize)
			if err != nil {
				return nil, err
			}
			thumbnailFrame.Content = version.ViewImage("")
		}
		result := view.DIV(self.ImageWidgetClass,
			thumbnailFrame,
			&view.Button{Content: view.HTML("Change")},
			&view.Button{Content: view.HTML("Remove")},
			// description
			// link
			view.DivClearBoth(),
		)
		if withLabel {
			return view.AddStandardLabel(form, result, metaData), nil
		}
		return result, nil
	}
	return self.FormFieldFactoryWrapper.Wrapped.NewInput(withLabel, metaData, form)
}
Ejemplo n.º 2
0
func (self BlobRefController) NewInput(withLabel bool, metaData *model.MetaData, form *view.Form) (input view.View, err error) {
	blobRef := metaData.Value.Addr().Interface().(*BlobRef)

	hiddenInput := &view.HiddenInput{Name: metaData.Selector(), Value: blobRef.String()}

	uploadList := &view.List{Class: "qq-upload-list"}

	removeButton := &view.Div{
		Class:   "qq-upload-button",
		Content: view.HTML("Remove"),
		OnClick: fmt.Sprintf(
			`jQuery("#%s").attr("value", "");
			jQuery("#%s").empty();`,
			hiddenInput.ID(),
			uploadList.ID(),
		),
	}

	chooseList := view.Views{
		view.JQueryUIAutocompleteFromURL(".gostart-select-blob", API.AllBlobs, 2),
	}

	uploadButton := UploadBlobButton(
		"",
		"#"+uploadList.ID(),
		fmt.Sprintf(
			`function(id, fileName, responseJSON) {
				jQuery("#%s").attr("value", responseJSON.blobID);
			}`,
			hiddenInput.ID(),
		),
	)

	editor := view.DIV(Config.BlobRefController.Class,
		view.RequireScriptURL("/media/media.js", 0),
		view.RequireStyle(
			`.qq-upload-button {
				margin: 0 0 5px 10px;
				cursor: pointer;
			}
			.qq-upload-button:hover {
				background-color: #cc0000;
			}`,
			10,
		),
		hiddenInput,
		view.DIV(Config.BlobRefController.ActionsClass, chooseList, removeButton, uploadButton),
		uploadList,
		view.DivClearBoth(),
	)

	if withLabel {
		return view.AddStandardLabel(form, editor, metaData), nil
	}
	return editor, nil
}
Ejemplo n.º 3
0
func (self BlobRefController) NewInput(withLabel bool, metaData *model.MetaData, form *view.Form) (input view.View, err error) {
	blobRef := metaData.Value.Addr().Interface().(*BlobRef)
	// _, _, err = blobRef.TryGet()
	// if err != nil {
	// 	return nil, err
	// }

	selectModel := &view.ValueLabelSelectModel{
		ValuesAndLabels: []string{"", ""},
		SelectedValue:   blobRef.String(),
	}
	var b Blob
	for i := BlobIterator(); i.Next(&b); {
		label := fmt.Sprintf("%s (%d kb)", b.Title, b.Size.Get()/1024)
		selectModel.ValuesAndLabels = append(selectModel.ValuesAndLabels, b.ID.Get(), label)
	}
	selector := &view.Select{
		Name:  metaData.Selector(),
		Model: selectModel,
		Size:  1,
	}

	uploadList := &view.List{Class: "qq-upload-list"}

	removeButton := &view.Div{
		Class:   "qq-upload-button",
		Content: view.HTML("Remove"),
		OnClick: fmt.Sprintf(
			`jQuery("#%s").attr("value", "");
			jQuery("#%s").empty();`,
			selector.ID(),
			uploadList.ID(),
		),
	}

	uploadButton := UploadBlobButton(
		"",
		"#"+uploadList.ID(),
		fmt.Sprintf(
			`function(id, fileName, responseJSON) {
				var select = jQuery("#%s");
				select.append("<option value='"+ responseJSON.blobID +"'>" + fileName + " (" + Math.floor(responseJSON.blobSize / 1024) + " kb)</option>");
				select.attr("value", responseJSON.blobID);
			}`,
			selector.ID(),
		),
	)

	editor := view.DIV(Config.BlobRefController.Class,
		view.RequireScriptURL("/media/media.js", 0),
		view.RequireStyle(
			`.qq-upload-button {
				margin: 0 0 5px 10px;
				cursor: pointer;
			}
			.qq-upload-button:hover {
				background-color: #cc0000;
			}`,
			10,
		),
		view.DIV(
			Config.BlobRefController.ActionsClass,
			selector,
			removeButton,
			uploadButton),
		uploadList,
		view.DivClearBoth(),
	)

	if withLabel {
		return view.AddStandardLabel(form, editor, metaData), nil
	}
	return editor, nil
}
Ejemplo n.º 4
0
func (self *FormFieldFactory) NewInput(withLabel bool, metaData *model.MetaData, form *view.Form) (view.View, error) {
	if imageRef, ok := metaData.Value.Addr().Interface().(*ImageRef); ok {
		thumbnailSize := Config.ImageRefEditor.ThumbnailSize
		removeButton := &view.Button{Content: view.HTML("Remove"), OnClick: ""}

		var img view.View
		if imageRef.IsEmpty() {
			removeButton.Disabled = true
			img = view.IMG(Config.dummyImageURL, thumbnailSize, thumbnailSize)
		} else {
			image, err := imageRef.GetImage()
			if err != nil {
				return nil, err
			}
			version, err := image.Thumbnail(thumbnailSize)
			if err != nil {
				return nil, err
			}
			img = version.ViewImage("")
		}

		hiddenInput := &view.HiddenInput{Name: metaData.Selector(), Value: imageRef.String()}

		thumbnailFrame := &view.Div{
			Class:   Config.ImageRefEditor.ThumbnailFrameClass,
			Style:   fmt.Sprintf("width:%dpx;height:%dpx;", thumbnailSize, thumbnailSize),
			Content: img,
		}

		const onCompleteSrc = `function(id, fileName, responseJSON) {
			alert(JSON.stringify(responseJSON));
			var img = "<img src='" + responseJSON.thumbnailURL + "' width='%d' height='%d'/>";
			jQuery("#%s").empty().html(img);
			jQuery("#%s").attr("value", responseJSON.imageID);
		}`
		onComplete := fmt.Sprintf(
			onCompleteSrc,
			thumbnailSize,
			thumbnailSize,
			thumbnailFrame.ID(),
			hiddenInput.ID(),
		)
		// onComplete = ""

		editor := view.DIV(Config.ImageRefEditor.Class,
			hiddenInput,
			thumbnailFrame,
			view.DIV(Config.ImageRefEditor.ActionsClass,
				view.HTML("&larr; drag &amp; drop files here"),
				removeButton,
				UploadImageButton(thumbnailSize, onComplete),
			),
			view.DivClearBoth(),
		)

		if withLabel {
			return view.AddStandardLabel(form, editor, metaData), nil
		}
		return editor, nil
	}

	return self.FormFieldFactoryWrapper.Wrapped.NewInput(withLabel, metaData, form)
}
Ejemplo n.º 5
0
func (self ImageRefController) NewInput(withLabel bool, metaData *model.MetaData, form *view.Form) (input view.View, err error) {
	imageRef := metaData.Value.Addr().Interface().(*ImageRef)
	thumbnailSize := Config.ImageRefController.ThumbnailSize

	var img view.View
	if imageRef.IsEmpty() {
		img = view.IMG(Config.dummyImageURL, thumbnailSize, thumbnailSize)
	} else {
		image, found, err := imageRef.TryGet()
		if err != nil {
			return nil, err
		}
		if found {
			version, err := image.Thumbnail(thumbnailSize)
			if err != nil {
				return nil, err
			}
			img = version.View("")
		} else {
			imageRef.Set(nil)
			img = view.IMG(Config.dummyImageURL, thumbnailSize, thumbnailSize)
		}
	}

	hiddenInput := &view.HiddenInput{Name: metaData.Selector(), Value: imageRef.String()}

	thumbnailFrame := &view.Div{
		Class:   Config.ImageRefController.ThumbnailFrameClass,
		Style:   fmt.Sprintf("width:%dpx;height:%dpx;", thumbnailSize, thumbnailSize),
		Content: img,
	}

	uploadList := &view.List{Class: "qq-upload-list"}

	removeButton := &view.Div{
		Class:   "qq-upload-button",
		Content: view.HTML("Remove"),
		OnClick: fmt.Sprintf(
			`jQuery("#%s").attr("value", "");
			jQuery("#%s").empty().append("<img src='%s' width='%d' height='%d'/>");
			jQuery("#%s").empty();`,
			hiddenInput.ID(),
			thumbnailFrame.ID(),
			Config.dummyImageURL,
			thumbnailSize,
			thumbnailSize,
			uploadList.ID(),
		),
	}

	chooseDialogThumbnails := view.DIV("")
	chooseDialogThumbnailsID := chooseDialogThumbnails.ID()
	chooseDialog := &view.ModalDialog{
		Style: "width:600px;height:400px;",
		Content: view.Views{
			view.H3("Choose Image:"),
			chooseDialogThumbnails,
			view.ModalDialogCloseButton("Close"),
		},
	}

	chooseButton := view.DynamicView(
		func(ctx *view.Context) (view.View, error) {
			return &view.Div{
				Class:   "qq-upload-button",
				Content: view.HTML("Choose existing"),
				OnClick: fmt.Sprintf(
					`gostart_media.fillChooseDialog('#%s', '%s', function(value){
						jQuery('#%s').attr('value', value.id);
						var img = '<img src=\"'+value.url+'\" alt=\"'+value.title+'\"/>';
						jQuery('#%s').empty().append(img);
						%s
					});
					%s;`,
					chooseDialogThumbnailsID,
					AllThumbnailsAPI.URL(ctx.ForURLArgsConvert(Config.ImageRefController.ThumbnailSize)),
					hiddenInput.ID(),
					thumbnailFrame.ID(),
					view.ModalDialogCloseScript,
					chooseDialog.OpenScript(),
				),
			}, nil
		},
	)

	uploadButton := view.DIV("")
	uploadButtonID := uploadButton.ID()
	uploadButton.Content = UploadImageButton(
		"#"+uploadButtonID,
		"#"+thumbnailFrame.ID(),
		"#"+uploadList.ID(),
		thumbnailSize,
		fmt.Sprintf(
			`function(id, fileName, responseJSON) {
				var img = "<img src='" + responseJSON.thumbnailURL + "' width='%d' height='%d'/>";
				jQuery("#%s").empty().html(img);
				jQuery("#%s").attr("value", responseJSON.imageID);
			}`,
			thumbnailSize,
			thumbnailSize,
			thumbnailFrame.ID(),
			hiddenInput.ID(),
		),
	)

	editor := view.DIV(Config.ImageRefController.Class,
		view.RequireScriptURL("/media/media.js", 0),
		view.RequireStyle(
			`.qq-upload-button {
				margin: 0 0 5px 10px;
				cursor: pointer;
			}
			.qq-upload-button:hover {
				background-color: #cc0000;
			}`,
			10,
		),
		chooseDialog,
		hiddenInput,
		thumbnailFrame,
		&view.Div{
			Class: Config.ImageRefController.ActionsClass,
			Style: fmt.Sprintf("margin-left: %dpx", thumbnailSize+10),
			Content: view.Views{
				removeButton,
				chooseButton,
				uploadButton,
			},
		},
		uploadList,
	)

	if withLabel {
		return view.AddStandardLabel(form, editor, metaData), nil
	}
	return editor, nil
}