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

rewrite fileUpload template #31

Closed
ApayRus opened this issue Aug 20, 2017 · 7 comments
Closed

rewrite fileUpload template #31

ApayRus opened this issue Aug 20, 2017 · 7 comments
Labels

Comments

@ApayRus
Copy link

ApayRus commented Aug 20, 2017

what should I do with template, for add to it some elemets (like Remove button available only for admin etc)? when I just copy it and rename it fires errors. What should I pass to it and how...
fileUpload.html

@dr-dimitru
Copy link
Member

As stated in the docs, you have to set name of the custom template to previewTemplate of defined afFieldInput rule:

picture: {
  type: String,
  autoform: {
    afFieldInput: {
      type: 'fileUpload',
      collection: 'Images',
      previewTemplate: 'myFilePreview'
    }
  }
}

You should be good with next markup:

<template name="myFilePreview">
      <span>{{name}}</span>
      <a data-remove-file href="#">Remove</a>
</template>

when I just copy it and rename it fires errors.

What errors exactly?

@ApayRus
Copy link
Author

ApayRus commented Aug 20, 2017

For just a test I've copied whole fileUpload.html to my file "ArticleUpdate.html" (which contains my autoForm), and renamed it to myFileUpload.

<template name="myFileUpload">
  <input value="{{fileId}}" type="hidden" {{this.atts}}>
  {{#with uploadedFile}}
    {{#if previewTemplate}}
      {{>Template.dynamic template=previewTemplate}}
    {{else}}
      <div>
        {{#if isImage}}
          {{> uploadImageDemo}}
        {{else}}
          {{> uploadFileDemo}}
        {{/if}}
      </div>
      <a data-reset-file href="#" style="display:none">Reset</a>
      <a data-remove-file href="#">Remove</a>
    {{/if}}
  {{else}}
    {{#if uploadTemplate}}
      {{>Template.dynamic template=uploadTemplate data=currentUpload}}
    {{else}}
      {{#with currentUpload}}
        Uploading <b>{{file.name}}</b>:
        <progress value="{{progress.get}}" max="100"></progress>
        &nbsp;
        <span class="progress">{{progress.get}}%</span>
      {{else}}
        <input data-files-collection-upload class="form-control af-file-upload-capture" type="file" />
      {{/with}}
    {{/if}}
  {{/with}}
</template>

Then this new template name I've added to schema:

    picture: {
        type: String,
        optional: true,
        autoform: {
            afFieldInput: {
                type: 'fileUpload',
                collection: 'Images',
                uploadTemplate: 'myFileUpload'
                }
            }
    },

After that when I open page with ArticleUpdate , there are blank page, and errors:
screenshot from 2017-08-20 07-59-25
Sorry if the question is too naive. I'm new in meteor and I even couldn't find this template in my project folder. Currently I'm reading about meteor packages to fix my ignorance.

@dr-dimitru
Copy link
Member

In my previous answer I gave you a template you need to implement your own file preview. No need to copy/paste whole afFileUpload - it wouldn't work.

Once again - template:

<template name="myFilePreview">
  <span>{{name}}</span>
  <a data-remove-file href="#">Remove</a>
</template>

@ApayRus
Copy link
Author

ApayRus commented Aug 21, 2017

@dr-dimitru thanks, it solved my issue.
And one last question, how to allow remove images only to their uploaders?
I've looked at Image object , there are not fields about creator of file

@dr-dimitru
Copy link
Member

If Image was uploaded on behalf of logged in user, userId should be filled.
Anyways I recommend to place all custom fields, like ownerId to meta Object.

See onBeforeRemove hook for more info.
Speaking of meta Object, currently it's not possible to change it in ostrio:autoform-files package, #30 will make it possible to pass custom Object to .insert() method

@ApayRus
Copy link
Author

ApayRus commented Aug 21, 2017

yes, there is userId. I am Inattentive today (
thank you for support! and sorry for disturbing! :)
good plugin. helped me so mach.

@ApayRus ApayRus closed this as completed Aug 21, 2017
@dr-dimitru
Copy link
Member

@Aparus glad to help :)

Please, support this project by:

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

No branches or pull requests

2 participants