Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8669953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:36:00+00:00 2026-06-12T18:36:00+00:00

I used the examples of this question to create drag-and-drop-script I could use on

  • 0

I used the examples of this question to create drag-and-drop-script I could use on a web application.

After re-designing it for my own purposes, there are some features I’d like to have implemented.
I’ve been trying for myself a while, but I haven’t found the soulution yet…

associated jsfiddle: http://jsfiddle.net/BLLTH/

Features:

  • already added objects should be removed from the available list

  • removing an added object by clicking on an “x”-symbol, which puts it back to the available list

  • objects must be in the same order as they were added

any ideas? =)

templates:

<script type="text/x-handlebars" >  
<b>Available Objects</b><br /><br />
{{#each App.objectsController}}
    {{#view App.ObjectView contentBinding="this"}}
        {{view.content.name}}<br />
    {{/view}}
{{/each}}
<br /><br /><br /><br />
{{#view App.ObjectDropTarget dragContextBinding="App.objectsController.currentDragItem"}}
    {{#each App.cartController}}
        {{#view App.ObjectView contentBinding="this" class="single"}}                
            {{view.content.name}}
        {{/view}}
    {{/each}}  
{{/view}}

​

javascript:

App = Em.Application.create({});
DragNDrop = Em.Namespace.create();
DragNDrop.cancel = function(event) {
    event.preventDefault();
    return false;
};
DragNDrop.Draggable = Em.Mixin.create({
    attributeBindings: 'draggable',
    draggable: 'true',
    dragStart: function(event) {
        var dataTransfer = event.originalEvent.dataTransfer;
        dataTransfer.setData('Text', this.get('elementId'));
    }
});
DragNDrop.Droppable = Em.Mixin.create({
    dragEnter: DragNDrop.cancel,
    dragOver: DragNDrop.cancel,
    drop: function(event) {
        event.preventDefault();
        return false;
    }
});
App.Object = Em.Object.extend({
    name: null,
    isAdded: null
});
App.ObjectView = Em.View.extend(DragNDrop.Draggable, {
    tagName: 'div',
    // .setDragImage (in #dragStart) requires an HTML element as the first argument
    // so you must tell Ember to create the view and it's element and then get the 
    // HTML representation of that element.  
    dragStart: function(event) {
        this._super(event);
        // Let the controller know this view is dragging
        this.setPath('content.isDragging', true);
        // Set the drag image and location relative to the mouse/touch event     
    },
    dragEnd: function(event) {
        // Let the controller know this view is done dragging
        this.setPath('content.isDragging', false);
    }
});
App.ObjectDropTarget = Em.View.extend(DragNDrop.Droppable, {
    tagName: 'div',
    classNames: ['dropTarget'],
    classNameBindings: ['cartAction'],
    // This will determine which class (if any) you should add to
    // the view when you are in the process of dragging an item.
    drop: function(event) {
        var viewId = event.originalEvent.dataTransfer.getData('Text'),
        view = Em.View.views[viewId];
        // Set view properties
        // Must be within `Ember.run.next` to always work
        Em.run.next(this, function() {
            view.setPath('content.isAdded', !view.getPath('content.isAdded'));
        });
        return this._super(event);
    }
});
App.objectsController = Em.ArrayController.create({
    content: [
    App.Object.create({
        name: "Object 1",
        isAdded: false
    }),
    App.Object.create({
        name: "Object 2",
        isAdded: false
    }),
    App.Object.create({
        name: "Object 3",
        isAdded: false
    }),
    App.Object.create({
        name: "Object 4",
        isAdded: false
    })
    ],
    currentDragItem: Em.computed(function(key, value) {
        return this.findProperty('isDragging', true);
    }).property('@each.isDragging').cacheable(),
    objectsInCart: Em.computed(function(key, value) {
        return this.filterProperty('isAdded', true);
    }).property('@each.isAdded').cacheable()
});
App.cartController = Em.ArrayController.create({
    content: Em.computed(function(key, value) {
        var cartItems = this.get('cartItems');
        if (!Em.empty(cartItems)) {
            // Sort desc by name
            return cartItems.sort(function(a, b) {
                 if ((a.get('name').toLowerCase()) < (b.get('name').toLowerCase())) return -1;
                 else return 1;
            });
        }
    }).property('cartItems').cacheable(),
    cartItemsBinding: 'App.objectsController.objectsInCart'
 });​
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:36:02+00:00Added an answer on June 12, 2026 at 6:36 pm

    I’ve implemented the first two features for you here http://jsfiddle.net/QE9CS/

    “already added objects should be removed from the available list” was achieved by creating another computed property on your array.

    “removing an added object by clicking on an “x”-symbol, which puts it back to the available list” just uses a standard Ember {{action}} helper.

    EDIT:

    Full version http://jsfiddle.net/R9hnY/
    I have turned isAdded into a computed property which sets the value on the object and adds or removes the object from the cartController’s content at the right time. Thus giving the cartController an ordered array of objects to render from.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used this code (kind of tutorial) at http://code.google.com/p/gwt-examples/wiki/gwt_hmtl5 ... In this code,
In some ASP.NET examples i see that events are used with delegates like this
This is a Two (2) Part Question about Generics I've got to create several
As this question is hard to describe, that's the best title i could come
I have used this example to create a database that I copy over on
I used this example (http://reecon.wordpress.com/2010/04/25/uploading-files-to-http-server-using-post-android-sdk/) to upload file from android device to server, it
I've used this example to to implement some sort of guestbook, only I'm using
I found this example and used it How do you resize a Bitmap under
Consider this classic example used to explain what not to do with forward declarations:
I created a duplex service ( NetTcpBinding ) like this example : I used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.