kalcifer / ember-dragula

Simple drag and drop with dragula and ember

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Play with components

Swizz opened this issue · comments

Hi,

I want to use ember-dragula in a project.

But, I use dragula to copy element from a deck to a workbench.
Each element is an ember component and deal with own actions.

Unfortunatly, dragula copy all the DOM without the component logic.
When I call an action from a component inside the workbench, the component emitter is finally the deck one.

So, How can I use ember-dragula to create an unique component after copying ?

Thanks for advance,

Hi,

Can you post your code?
In dragula, you have access to drag/drop events. Maybe you could use them to copy the component instances?

The code is really basic as

{{#ember-dragula-container id="playground"}}
{{/ember-dragula-container}}

{{#ember-dragula-container}}
    {{draggable-table title="SomeTitle"}}
{{/ember-dragula-container}}

And the DraggableTable component as own template and actions.

So when I drag/drop the DraggableTable to the playground, it whill copy the dom of the component, not the component itself.

So, call action from the DraggableTable component iside the playground will call infact action inside the original one.


Drap/drop events give only dom elements. And I do not know the way to retrieve a component instance from a dom element.


So, I am considering to play with lists, and use component only for visual stuff.
And using events to serialize/unserialize datas to dom.

Would it help if I passed the ember object instance as argument for the
events?

Regards,
Pavithra.K

On Thu, Apr 21, 2016 at 8:10 PM, Quentin Gerodel notifications@github.com
wrote:

The code is really basic as

{{#ember-dragula-container id="playground"}}
{{/ember-dragula-container}}

{{#ember-dragula-container}}
{{draggable-table title="SomeTitle"}}
{{/ember-dragula-container}}

And the DraggableTable component as own template and actions.

So when I drag/drop the DraggableTable to the playground, it whill copy
the dom of the component, not the component itself.

So, call action from the DraggableTable component iside the playground

will call infact action inside the original one.

Drap/drop events give only dom elements. And I do not know the way to

retrieve a component instance from a dom element.

So, I am considering to play with lists, and use component only for visual
stuff.
And using events to serialize/unserialize datas to dom.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#19 (comment)

It depend of the Ember object we talk about.

In this case, I request the el parameter of events.

//app/utils.js

export const getComponentFromId = (id) => {
  return FrontEmber.__container__.lookup('-view-registry:main')[id];
};

export const getComponentFromEl = (el) => {
  return getComponentFromId(el.id);
};
//app/editor/controller.js

//[...]

    didDrop(el, target) {
      let table = getComponentFromEl(el),
          playground = getComponentFromEl(target);

      playground.tables.addObject(table.model);
      Ember.$(el).remove();
    }

//[...]

Give me all I need.

Thanks for your time.