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 = “”;
}
Calendar View
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;" }) |
Lead : | @Html.DropDownList("ddlLead", new SelectList(ViewData["Leads"] as System.Collections.IEnumerable, "IDKey", "ValueString", @ObjectID == null ? 0 : @ObjectID), new { @style = "width:100%; height:25px;" }) |
What is the problem in drag and drop??