Drag and drop not working

I am using same dhtmlxscheduler.js for my calendar. I have avoided some part of authentication. Now I’m not able to drag and drop.

In Controller

[code]public class CalendarController : BaseController
{
protected void _ConfigureLightbox(DHXScheduler sched, string scenario,int? ObjectId)
{
sched.Lightbox.AddDefaults();
if (scenario == “lead”)
{
var selectLead = new LightboxSelect(“lead_id”, “Lead”);
selectLead.AddOptions(_iManageVacancy.GetLeadsforCalendarddl());
sched.Lightbox.Items.Insert(1, selectLead);

                var selectProperty = new LightboxSelect("property_id", "Property");
                if (ObjectId == null || ObjectId==0)
                    selectProperty.AddOptions(_iManageVacancy.GetPropertiesforCalendarddl());
                else
                    selectProperty.AddOptions(_iManageVacancy.GetInterestedUnits(Convert.ToInt32(ObjectId)));
                sched.Lightbox.Items.Insert(2, selectProperty);        
     
            var selectAgent = new LightboxSelect("agent_id", "Agent");
            selectAgent.AddOptions(_iManageVacancy.GetLeasingAgentforCalendarddl());
            sched.Lightbox.Items.Insert(3, selectAgent);  
        }
    }

    protected void _ConfigureViewsAndTemplates(DHXScheduler sched, string scenario, int? ObjectId)
    {
        if (scenario == "lead")
        {
            var units = new UnitsView("properties", "property_id");
            units.Label = "Properties";
            units.AddOptions(_iManageVacancy.GetPropertiesTrial());//change event to retrieve property wise
            sched.Views.Add(units);

            var units1 = new UnitsView("agents", "agent_id");
            units1.Label = "Agents";
            units1.AddOptions(_iManageVacancy.GetLeasingAgentforCalendarddl());//change event to retrieve property wise
            sched.Views.Add(units1);

            var units2 = new UnitsView("leads", "lead_id");
            units2.Label = "Leads";
            units2.AddOptions(_iManageVacancy.GetLeadsforCalendarddl());//change event to retrieve property wise
            sched.Views.Add(units2);
        }
            sched.Views.Add(new WeekAgendaView());
    }

    protected void _ConfigureScheduler(DHXScheduler sched)
    {
        sched.SetEditMode(EditModes.OwnEventsOnly, EditModes.AuthenticatedOnly);
        sched.Extensions.Add(SchedulerExtensions.Extension.Collision);
        sched.Extensions.Add(SchedulerExtensions.Extension.Limit);

        sched.Config.first_hour = 8;
        sched.Config.last_hour = 19;
        sched.XY.scroll_width = 0;
        sched.Config.time_step = 30;
        sched.Config.multi_day = true;
        sched.Config.limit_time_select = true;

        sched.Config.cascade_event_display = true;

        sched.AfterInit = new List<string>() { "attachRules();" };

        sched.LoadData = true;
        sched.PreventCache();

        if (Request.IsAuthenticated)
        {
            sched.EnableDataprocessor = true;
        }
    }
    protected void _HandleAuthorization(DHXScheduler sched, string scenario, int? ObjectId)
    {
            if (scenario == "lead")
                sched.InitialValues.Add("lead_id", ObjectId);
    }

    public ActionResult Index(string mode, int? ObjectId, DateTime _date, string _mode)
    {
        var sched = new DHXScheduler();
        switch (mode)
        {
            case "lead":
                ViewData["Leads"] = _iManageVacancy.GetLeads();
                sched.Codebase = Url.Content("~/Scripts/dhtmlxSchedulerforLead");
                sched.SaveAction = Url.Content("~/Calendar/Save?mode=" + mode + "&ObjectId=" + ObjectId);
                sched.DataAction = Url.Content("~/Calendar/Data?mode=" + mode + "&ObjectId=" + ObjectId);
                break;
            case "workorder":
                List<Lookup> _lookup = (List<Lookup>)HttpContext.Cache["Lookup"];
                if (HttpContext.Cache["Lookup"] == null)
                    _lookup = _iManageUser.UpdateCache();
                List<User> _assignedTo = _iManageUser.GetUsersByRole((int)EnumsNeeded.Roles.FieldWorker);/*519*/
                _assignedTo.ForEach(x => x.FirstName = x.FirstName + " " + x.LastName);
                _assignedTo.Insert(0, new User { UserId = 0, FirstName = "- Select - " });
                ViewData["AssignedTo"] = _assignedTo;

                sched.Codebase = Url.Content("~/Scripts/dhtmlxSchedulerforMaintenance");
                sched.SaveAction = Url.Content("~/Calendar/Save?mode=" + mode + "&ObjectId=" + ObjectId);
                sched.DataAction = Url.Content("~/Calendar/Data?mode=" + mode + "&ObjectId=" + ObjectId);
                break;
        }

        _ConfigureScheduler(sched);
        _ConfigureViewsAndTemplates(sched, mode, ObjectId);
        _ConfigureLightbox(sched, mode, ObjectId);
        _HandleAuthorization(sched, mode, ObjectId);

        var serializer = new JavaScriptSerializer();

        if (mode == "lead")
        {
            var properties = serializer.Serialize(_iManageVacancy.GetInterestedUnits(Convert.ToInt32(ObjectId)));

            return View(new CalendarModel() { Properties = properties, Scheduler = sched, ObjectID = ObjectId, Mode = mode });
       }
        else 
        {
            return View(new CalendarModel() { Scheduler = sched, ObjectID = ObjectId, Mode = mode });
        }
    }

    public ActionResult Data(string mode, int? ObjectId)
    {
        if (mode == "lead")
            return (new SchedulerAjaxData(_iManageVacancy.GetEventsforLeads(Convert.ToInt32(ObjectId))));
        else if (mode == "workorder" && ObjectId != null)
            return (new SchedulerAjaxData(_iManageMaintanence.GetEventsforFieldWorker(Convert.ToInt32(ObjectId))));
        else
            return (new SchedulerAjaxData(_iManageMaintanence.GetEventsforFieldWorker(0)));
    }

    public ActionResult Save(string mode, int? ObjectId, FormCollection actionValues)
    {
        var action = new DataAction(actionValues);
        var changedEvent = (Event)DHXEventsHelper.Bind(typeof(Event), actionValues);

        int check_exist = _iManageVacancy.CheckExistingProperty(Convert.ToInt32(ObjectId), Convert.ToInt32(changedEvent.property_id));
        action.Type = check_exist == 0 ? DataActionTypes.Insert : DataActionTypes.Update;
            try
            {
                if (mode == "lead")
                {
                    switch (action.Type)
                    {
                        case DataActionTypes.Insert:
                            changedEvent.id = _iManageVacancy.AddNewEvent(changedEvent, Convert.ToInt32(ObjectId), Convert.ToInt32(changedEvent.property_id));
                            break;
                        default:// "update"      
                            if (check_exist != 0)
                                changedEvent.id = check_exist;
                            changedEvent.id = _iManageVacancy.UpdateEvent(changedEvent, Convert.ToInt32(ObjectId), Convert.ToInt32(changedEvent.property_id));
                            break;
                    }
                    action.TargetId = changedEvent.id;
                }
                else if (mode == "workorder")
                {
                    switch (action.Type)
                    {
                        default: // "updated"
                            changedEvent.id = _iManageMaintanence.UpdateEvent(changedEvent);
                            break;
                    }
                }
            }
            catch (Exception a)
            {
                action.Type = DataActionTypes.Error;
            }

        return new AjaxSaveResponse(action);
    }
}

}[/code]

In View

[code]@model WRIPMS_Entities.Models.CalendarModel
@{
ViewBag.Title = “Calendar”;
Layout = “~/Views/Shared/_Layout.cshtml”;
var _properties = Model.Properties;
int ObjectID = Convert.ToInt32(Model.ObjectID);
var mode = Model.Mode.ToString();
var ddlvalue = “”;
}

#footer { display: none; } .dhtmlx_message_area { left: 5px; } #main { height: 600px; }

Calendar View

@Html.Hidden("hdnObjectID", @ObjectID) @Html.Hidden("hdnCalendarMode", @mode) @if (mode == "workorder") {
In-house Vendor : @Html.DropDownList("ddlAssignedTo", new SelectList(ViewData["AssignedTo"] as System.Collections.IEnumerable, "UserId", "FirstName", @ObjectID ==null ? 0 : @ObjectID), new { @style = "width:100%; height:25px;" })
} else if (mode == "lead") {
Lead : @Html.DropDownList("ddlLead", new SelectList(ViewData["Leads"] as System.Collections.IEnumerable, "IDKey", "ValueString", @ObjectID == null ? 0 : @ObjectID), new { @style = "width:100%; height:25px;" })
} [/code]

What is the problem in drag and drop??

Hello,
you can remove the part with ‘isEditable’ function. I think it does not really check anything. When the function returns false(void return is also considered as false), it cancels d’n’d.
I.e. remove this code:

[code]var isEditable = function (event_obj, type, event) {
if (!event_obj) {
var ev = event || window.event;
var date = scheduler.getActionData(ev).date; //getting cursor position
return true;
}

if (typeof event_obj != 'object') {
	event_obj = scheduler.getEvent(event_obj);
	return true;
}

};

scheduler.attachEvent(“onBeforeLightbox”, isEditable);
scheduler.attachEvent(“onBeforeDrag”, isEditable);
scheduler.attachEvent(“onBeforeEventChanged”, isEditable);
scheduler.attachEvent(“onClick”, isEditable);
scheduler.attachEvent(“onDblClick”, isEditable);[/code]

Still It doesn’t works…

Please attach a demo, so we could reproduce the issue locally

Now it works fine… Some issue with js file.

[code]scheduler._on_mouse_down = function (e, src) {
// on Mac we do not get onmouseup event when clicking right mouse button leaving us in dnd state
// let’s ignore right mouse button then
if (e.button == 2)
return;

    if (this.config.readonly || this._drag_mode) return;
    src = src || (e.target || e.srcElement);
    var classname = src.className && src.className.split(" ")[0];

    switch (classname) {
        case "dhx_cal_event_line":
        case "dhx_cal_event_clear":
            if (this._table_view)
                this._drag_mode = "move"; //item in table mode
            break;
        case "dhx_event_move":
        case "dhx_wa_ev_body":
            this._drag_mode = "move";
            break;
        case "dhx_event_resize":
            this._drag_mode = "resize";
            break;
        case "dhx_scale_holder":
        case "dhx_scale_holder_now":
        case "dhx_month_body":
        case "dhx_matrix_cell":
        case "dhx_marked_timespan":
            this._drag_mode = "create";
            break;
          case "":                                 
              if (src.parentNode)
                  return scheduler._on_mouse_down(e, src.parentNode);
        default:
            if (scheduler.checkEvent("onMouseDown") && scheduler.callEvent("onMouseDown", [classname])) {
                if (src.parentNode && src != this) {
                    return scheduler._on_mouse_down(e, src.parentNode);
                }
            }
            this._drag_mode = null;
            this._drag_id = null;
            break;
    }
    if (this._drag_mode) {
        var id = this._locate_event(src);
            if (!this.config["drag_" + this._drag_mode] || this.callEvent("onBeforeDrag", [id, this._drag_mode, e]))
            this._drag_mode = this._drag_id = 0;
        else {
            this._drag_id = id;
            this._drag_event = scheduler._lame_clone(this.getEvent(this._drag_id) || {});
        }
    }
    this._drag_start = null;
};[/code]

if (!this.config[“drag_” + this._drag_mode] || !this.callEvent(“onBeforeDrag”, [id, this.drag_mode, e]))
is changed to
if (!this.config["drag
" + this._drag_mode] || this.callEvent(“onBeforeDrag”, [id, this._drag_mode, e]))

then it works fine…

Please do not change the source code in that way. The initial code has worked as expected.
The original condition condition

if (!this.config["drag_"+this._drag_mode] || !this.callEvent("onBeforeDrag",[id, this._drag_mode, e])) this._drag_mode=this._drag_id=0;
does the following:
"[b]prevent D’n’D if

  1. current type of d’n’d operation is disabled in the config,
    OR
  2. custom handler for onBeforeDragEvent is defined and returns a false value[/b]"

Which is designed behavior. Your modification has inverted the 2nd condition, so it will cancel D’n’D if onBeforeDrag returns true, or if custom handler for that event is not defined.

Please check your code for handler of onBeforeDrag event of the scheduler. The most likely reason why d’n’d is not work for you, is that onBeforeDragEvent handler returns false, or returns nothing, which is also considered as a false value