Customize Your Lightbox Fields with DHXScheduler

In my JSP application for exam timetabling, I have integrated DHXScheduler and customized the lightbox to display additional information about exams using my own fields.

The EventsManager class is responsible for managing events by saving, creating, and retrieving them. It extends the DHXEventsManager class.

public class EventsManager extends DHXEventsManager {

public EventsManager(HttpServletRequest request) {          
    super(request);
}

public Iterable getEvents() {

    Connection conn = null;
    DHXEventsManager.date_format = "yyyy-MM-dd HH:mm:ss";
    List<Event> events = new ArrayList<Event>();

    try {

        conn = SQLHelper.getConnection();
        Statement statement = conn.createStatement();

        StringBuffer query = new StringBuffer();
        query.append("SELECT * FROM ");
        query.append(TimetableEvent.TBL_EVENTS);
        query.append(" e JOIN ");
        query.append(StudyUnit.TBL_STUDYUNITS);
        query.append(" s ON e.");
        query.append(TimetableEvent.FLD_UNITCODE);
        query.append(" = s.");
        query.append(StudyUnit.FLD_UNITCODE);

        ResultSet rs = statement.executeQuery(query.toString());

        while (rs.next()) {

            Event e = new Event(); // extends DHXEvent and contains additional fields

            e.setId(Integer.parseInt(rs.getString(TimetableEvent.FLD_ID)));
            e.setText(rs.getString(TimetableEvent.FLD_UNITCODE));
            e.setStart_date(rs.getString(TimetableEvent.FLD_STARTDATE));
            e.setEnd_date(rs.getString(TimetableEvent.FLD_ENDDATE));
            e.setUnitCode(rs.getString(StudyUnit.FLD_UNITCODE));
            e.setTitle(rs.getString(StudyUnit.FLD_TITLE));
            e.setYear(rs.getString(StudyUnit.FLD_YEAR));
            e.setSemester(rs.getShort(StudyUnit.FLD_SEMESTER));
            e.setExamLength(rs.getFloat(StudyUnit.FLD_EXAMLENGTH));
            e.setNoOfStudents(rs.getShort(StudyUnit.FLD_NOOFSTUDENTS));
            e.setDepartment(rs.getString(StudyUnit.FLD_DEPARTMENT));
            e.setCredits(rs.getShort(StudyUnit.FLD_CREDITS));
            e.setEvening(rs.getBoolean(StudyUnit.FLD_EVENING));

            events.add(e);
            }

        } catch (SQLException e) {
            System.out.println("[EventsManager.getEvents()]: " + e.getMessage());

        } finally {
            SQLHelper.closeConnection(conn);
        }

        DHXEventsManager.date_format = "MM/dd/yyyy HH:mm";
        return events;
    }

    @Override
    public DHXStatus saveEvent(DHXEv event, DHXStatus status) {
    Connection conn = SQLHelper.getConnection();
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    Event ev = (Event) event;

    try {

        if (status == DHXStatus.UPDATE) {
            pstmt = TimetableEvent.updateEvent(conn, ev);

        } else if (status == DHXStatus.INSERT) {
            System.out.println("SAVE");
            pstmt = TimetableEvent.insertEvent(conn, ev);

        } else if (status == DHXStatus.DELETE) {
            pstmt = TimetableEvent.deleteEvent(conn, event);
        }

        if (pstmt != null) {
            pstmt.executeUpdate();
            rs = pstmt.getGeneratedKeys();

            if (rs.next()) {
                event.setId(rs.getInt(1));
                ev.setId(rs.getInt(1));
            }
        }

    } catch (SQLException e) {
        System.out.println("[EventsManager.saveEvent() - " + status.name() + "]: " + e.getMessage());
        e.printStackTrace();

    } finally {

        if (rs != null) SQLHelper.closeResultSet(rs);
        if (pstmt != null) SQLHelper.closePreparedStatement(pstmt);
        if (conn != null) SQLHelper.closeConnection(conn);
    }

    return status;
}

    @Override
public DHXEv createEvent(String id, DHXStatus status) {
    return new Event();
}
}

The Event class, which extends DHXEvent, includes getters and setters for additional fields. However, there is an issue when casting from DHXEv to Event, causing the additional fields to become null since the saveEvent method only accepts DHXEv as a parameter.

Within the events.jsp file, the getEvents() method of EventsManager is invoked to retrieve JSON objects containing events.

<%@ page contentType="application/json" 
         import="com.dhtmlx.planner.*,servlets.*,events.EventsManager"
%>

<%= getEvents(request) %>
<%!
    String getEvents(HttpServletRequest request) throws Exception {
        EventsManager evs = new EventsManager(request);
        return evs.run();
    }
%>

Currently, the JSON object being returned only includes fields from the DHXEv object like

id, start_date, end_date, and text
.

{id:7, text:CIS3087, end_date:03/27/2014 13:00, start_date:03/27/2014 10:00}

I am seeking guidance on how to incorporate those additional fields into the JSON object, specifically including study unit title, department, etc.

Additionally, here is some relevant client-side code for the scheduler, including its configuration and methods such as save_form() and show_lightbox:

scheduler.config.api_date = "%Y-%m-%d %H:%i";
scheduler.config.details_on_dblclick = true;
scheduler.config.details_on_create = true;
scheduler.config.first_hour = "8";  
scheduler.config.last_hour = "22";
scheduler.config.drag_lightbox = true;
scheduler.config.show_loading = true;
scheduler.config.mark_now = true;

scheduler.init('scheduler_here', new Date(), "week");
scheduler.load("events.jsp", "json");

var dp = new dataProcessor("events.jsp");
dp.init(scheduler);

function save_form() {
      var ev = scheduler.getEvent(scheduler.getState().lightbox_id);

      ev.text = html("studyunit_code").value;
      ev.start_date = setDate("start_date", "starttime");
      ev.end_date = setDate("start_date", "endtime");

      scheduler.endLightbox(true, html("custom_form"));

      $("#form1").submit(); // submits all the other fields and saves them to a db table
}

scheduler.showLightbox = function(id) {

    var ev = scheduler.getEvent(id);
    scheduler.startLightbox(id, html("custom_form"));

    html("studyunit_code").value = ev.text;
    html("studyunit_code").focus();
    html("studyunit_title").value = ev.studyunit_title;

    var startDate = ev.start_date;
    getDate(startDate, "start_date", "starttime");

    var endDate = ev.end_date;
    getDate(endDate, "start_date", "endtime");              
};

I believe a minor adjustment is required to include the fields in the JSON object and display them in the lightbox.

If you have any suggestions on resolving this issue, I would greatly appreciate it. Thank you!

Answer №1

To ensure proper functionality, ensure that any additional fields in the Event class are declared as public. The DHXEventsManager relies on Class.getFields() to retrieve event properties. If a property is marked as private, it will not be included in the generated JSON output.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

modify the values of directive elements using a templateUrl

HTML Template: I have an element in the template file seats.tpl.html like this: <select id="guest_table"> <option tables="emptySeats" ng-repeat="table in emptySeats" value="{{table.tableId}}">{{table.tableNumber}}</option& ...

Utilizing Dropwizard for hosting static HTML files

I'm in the process of developing an application using dropwizard and angularjs. I have configured my AssetsBundle as follows: bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.html")); The challenge I am facing is that I want multiple page ...

What strategies can be employed to maintain reliable datetime management for a reservation system operating in diverse time zones?

Looking at the big picture: An interesting scenario arises when a hotel owner specifies a time frame for booking reservations at a restaurant (5pm - 10pm). Along with this information, there is also a timezone provided to ensure that dates are displayed i ...

The GWT plugin seems to be missing when using chromedriver

Trying to run Selenium tests on a GWT Java application and utilizing the ChromeDriver for this purpose. Requiring the GWT Plugin in the settings, here's the process I follow: @Provides @Singleton protected WebDriver getDefaultWebDriver() throws IOEx ...

Issues with Formik sign-up

Working on a study project involving React, Typescript, Formik, and Firebase presents a challenge as the code is not functioning correctly. While authentication works well with user creation in Firebase, issues exist with redirection, form clearing, and da ...

Transitioning to PDF Embed Window with Selenium

Is there a way to check if a new window pops up when the 'Generate PDF' link is clicked? I'm not concerned with the PDF content, I just want to make sure a new window appears when the link is clicked. I attempted to use the window handles c ...

Troubleshooting Routing Issues in a Next.js Website Tutorial

After going through the next.js tutorial at https://github.com/zeit/next-learn-demo.git, I encountered an issue starting from stage 3 "dynamic routing". Despite the tutorial indicating that dynamic routing should be working from stages 3 to 8, it wasn&apos ...

Utilizing a switch statement for form validation

Currently, I am in the process of creating a form validation that involves two conditions for validation. I'm considering using a combination of switch case and if else statements. Would this be an appropriate approach or is it generally discouraged? ...

Inserting an HTML element into Handlebars.js during a specific iteration of an each loop

I have a channel.json file containing 7 objects of data which are iterated in hb. I am looking for a way to insert a date between these iterations without modifying the .json file. How can I add an html tag to display after the 3rd iteration within the loo ...

Using jQuery to iterate through a JSON array and extract key/value pairs in a loop

I want to create a loop that can go through a JSON array and show the key along with its value. I found a post that seems similar to what I need, but I can't quite get the syntax right: jQuery 'each' loop with JSON array Another post I cam ...

Is it possible to retrieve the complete HTTP response text using Node.js from a HTTP module's .get response?

I have a straightforward web server set up: const ws = require('http'); ws.createServer( function(req,res) { console.log('request received'); res.write('Hello world'); res.end(); }) ...

Transfer a Sencha Touch application from iOS to Android and Windows devices

I am a dedicated Android developer who is diving into the world of Sencha Touch, Windows app development, and VisualStudio environments for the first time. Please excuse the detailed explanation of my problem, as I want to make sure all crucial details are ...

Adding conditional href based on a specific criteria to an <a> tag in AngularJs

I have been working on a menu list where some menus contain URLs and others do not. When a menu item includes a URL, the href attribute is displayed, otherwise just the span tag is shown. I tried checking it like this but ended up with href="#" when the me ...

Use `jq` to select the initial element following a sort for uniqueness

My task involves managing an array of wireless access points along with their signal levels. I need to extract unique SSIDs with the highest signal strength. # cat aps.json { "AP" : [ { "SSID" : "Bart", "Signal" : -20 }, { "SSID" : "Lisa", "Si ...

JavaScript guide: Deleting query string arrays from a URL

Currently facing an issue when trying to remove query string arrays from the URL. The URL in question looks like this - In Chrome, it appears as follows - Var url = "http://mywebsite.com/innovation?agenda%5B%5D=4995&agenda%5B%5D=4993#ideaResult"; ...

Creating various media types with Spring and Jersey

Recently introduced to REST and tasked with creating a Rest Controller that requires a file name as a parameter to display its contents. See the code snippet below: @RequestMapping(value = "/paths", method = RequestMethod.GET, produces = "application/pdf" ...

Discovering the earliest and latest dates within an array of date strings

My data consists of an array filled with objects like this data = [ { mas_name: (...), mas_plan_end: (...) // 'YYYY-MM-DD' eg: '2021-03-19' mas_plan_start: (...) // 'YYYY-MM-DD' eg: '2021-03-19' ... }, { ...

How can one conditionally UPDATE/INSERT data following a DELETE operation that does not return any matching rows?

I'm currently working on updating a table after deleting a value from a different table. Below is the simplified function query I am using for this purpose: create function updateoutfit(_id uuid, _title text DEFAULT NULL::text, _garments json) re ...

Is there a way to send an AJAX request to an MVC action from a JavaScript file?

In a file named job.js, there is code that works perfectly when run on localhost but results in a 404 error when run on an intranet server with an application name. Job.updateJob = function () { $.post('/Builder/ListJobItems', function (dat ...

What is the best way to handle JSONp response parsing using JavaScript?

I'm relatively new to working with Javascript and I am currently attempting to retrieve data from an External API located on a different website. My goal is to extract the information, parse it, and then display specific parts of it within my HTML pag ...