kalcifer / ember-dragula

Simple drag and drop with dragula and ember
MIT License
27 stars 17 forks source link

Play with components #19

Closed Swizz closed 8 years ago

Swizz commented 8 years ago

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,

pksjce commented 8 years ago

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?

Swizz commented 8 years ago

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.

pksjce commented 8 years ago

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 https://github.com/kalcifer/ember-dragula/issues/19#issuecomment-212950666

Swizz commented 8 years ago

It depend of the Ember object we talk about.

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

Swizz commented 8 years ago
//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.