Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

photo/image not saved as serverAttribute using mobile action - take photo #132

Open
t0mZ4 opened this issue Aug 26, 2024 · 1 comment
Open

Comments

@t0mZ4
Copy link

t0mZ4 commented Aug 26, 2024

Hi
trying to use mobile action -> take photo

the camera opens, takes picture, picture is displayed, but not saved as serverAttribute on the device.

using default code

`// Function body to process image obtained as a result of mobile action (take photo, take image from gallery, etc.). 
// - imageUrl - image URL in base64 data format

showImageDialog('Photo', imageUrl);
//saveEntityImageAttribute('image', imageUrl);

function showImageDialog(title, imageUrl) {
    setTimeout(function() {
        widgetContext.customDialog.customDialog(imageDialogTemplate, ImageDialogController, {imageUrl: imageUrl, title: title}).subscribe();
    }, 100);
}

function saveEntityImageAttribute(attributeName, imageUrl) {
    if (entityId) {
        let attributes = [{
            key: attributeName, value: imageUrl
        }];
        widgetContext.attributeService.saveEntityAttributes(entityId, "SERVER_SCOPE", attributes).subscribe(
           function() {
               widgetContext.showSuccessToast('Image attribute saved!');
           },
           function(error) {
               widgetContext.dialogs.alert('Image attribute save failed', JSON.stringify(error));
           }
        );
    }
}

var
  imageDialogTemplate =
    '<div aria-label="Image">' +
    '<form #theForm="ngForm">' +
    '<mat-toolbar fxLayout="row" color="primary">' +
    '<h2>{{title}}</h2>' +
    '<span fxFlex></span>' +
    '<button mat-icon-button (click)="close()">' +
    '<mat-icon>close</mat-icon>' +
    '</button>' +
    '</mat-toolbar>' +
    '<div mat-dialog-content>' +
    '<div class="mat-content mat-padding">' +
    '<div fxLayout="column" fxFlex>' +
    '<div style="padding-top: 20px;">' +
    '<img [src]="imageUrl" style="height: 300px;"/>' +
    '</div>' +
    '</div>' +
    '</div>' +
    '</div>' +
    '<div mat-dialog-actions fxLayout="row">' +
    '<span fxFlex></span>' +
    '<button mat-button (click)="close()" style="margin-right:20px;">Close</button>' +
    '</div>' +
    '</form>' +
    '</div>';

function ImageDialogController(instance) {
  let vm = instance;
  vm.title = vm.data.title;
  vm.imageUrl = vm.data.imageUrl;
  vm.close = function ()
  {
    vm.dialogRef.close(null);
  }
}
`
@vvlladd28
Copy link
Member

Hi @t0mZ4,
To save the attribute, you need to uncomment the line of code:
//saveEntityImageAttribute('image', imageUrl);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants