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

In AngularJS, the use of the '+' operator is causing concatenation instead of addition

Looking for assistance with my TypeScript code where I've created a basic calculator. Everything is working as expected except for addition, which seems to be concatenating the numbers instead of adding them together. HTML CODE : <input type="tex ...

Tips for overlapping children in a column flex direction while maintaining the parents' positioning

Currently, I am working with two parent flex items, arranged with flex-direction: column. Within the first parent, there are two children. However, one of the children is optional and may be removed at times. I aim to have the optional child displayed on ...

When calling mongoose.connect(), the initial parameter must be a String but it was found to be

I am facing issues while setting up the test database for testing purposes. The connection error shown when trying to connect to MongoDB using Mongoose is: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' + ^ MongooseEr ...

Using javascript within a PHP file

I'm struggling to implement this JavaScript function within a PHP page (footer.php), but it's not functioning as expected. I've experimented with various approaches, even attempting to include the script within a PHP echo statement, but that ...

Encountering a serialization error when trying to load a JSON file

Below is a JSON file example: [ { "applicationConfig": { "Name": "Name1", "Site": "Site1" }, "pathConfig": { "SourcePath": "C:\\Temp\\Outgoing1", "TargetPath": "C:\\Files" }, "cre ...

Which is more suitable for storing data for boardgame session data: redisJSON or traditional redis?

Recently set up a Redis server for my backend using ioredis. I've discovered that if I want to store data in JSON format, I need to use the redisJSON module because hashes are only string typed and flat. However, since I'm only storing one objec ...

Storing data locally and replacing the current URL with window.location.href

My course mate and I are working on writing a code that saves an order to local storage and redirects to an order page when the order button is clicked. However, we are facing issues where clicking on the order button doesn't register in the applicat ...

The request method 'PUT' is not currently supported

Currently, I am working on a project that involves springboot, angularjs, and restful services. Here is my REST controller: @RequestMapping(value="/updatestructure/{ch}", method = RequestMethod.PUT) public @ResponseBody Structurenotification updateStruct ...

"Efficiently sharing information in a multi-tenant application: strategies for seamless data transfer between front

In my development of a multi tenancy application using Node.js/Mongoose and React, I made the decision to utilize a single database for all users. The main collection, dubbed companies, serves as storage for basic company data and includes a unique compan ...

Is there a way to retrieve the JavaScript Console response code using Python and Selenium's execute_script method?

I am running a JavaScript fetch request in the Chrome developer console using Selenium's execute_script() function. The request performs as expected, but I want to set up a function that can verify if the response is a 403 status code. Is there any Se ...

I wish to adjust the font size as well as resize the table elements simultaneously

Adjusting the height and width of the table should automatically adjust the font size as well. <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI Resizable - Default functiona ...

Column alignment issue detected

Can you help me with aligning the data in my column status properly? Whenever I update the data, it doesn't align correctly as shown in the first image. https://i.stack.imgur.com/300Qt.png https://i.stack.imgur.com/4Dcyw.png $('#btn_edit' ...

Can the installation of Canvas be done on a device with the M1 chip?

When attempting to install canvas on a MacBook Pro M1 using the command: npm install --save-dev canvas An error is displayed: npm ERR! code 1 npm ERR! path /Users/xiaoqiangjiang/source/reddwarf/frontend/js-wheel/node_modules/canvas ... (error message con ...

Use JavaScript to sift through an array and exclusively retrieve items that match a specific value

I am working with an array of objects that contain a phase key, and I want to filter out only the ones that have a specific phase value. Additionally, I need to map some other key/value pairs into the final return. Here is my current code: phaseToBlocks ( ...

Appending an empty <li> tag has no effect

I'm facing an issue with this loop where it always generates empty <li></li> tags. Can anyone help me understand why this is happening and suggest a solution? For reference, the loop runs 2 times (verified). function a(){ for (var i ...

Checking for valid zip code using a regular expression in JavaScript

Thank you for the suggestions, everyone. I have made some modifications to the script based on your advice and it appears to be functioning correctly now. <script src="jquery-1.4.2.min.js" type="text/javascript"></script> <script> $ ...

In JavaScript, the clearTimeout function may not always return a

Could someone please help me troubleshoot the issue in my code snippet below? I am trying to declare a public variable and assign it to a setTimeout function. If the variable is not null, I want to clear the timeout before setting it again. However, when ...

Looking for a more efficient method to pass components with hooks? Look no further, as I have a solution ready for

I'm having trouble articulating this query without it becoming multiple issues, leading to closure. Here is my approach to passing components with hooks and rendering them based on user input. I've stored the components as objects in an array an ...

Make sure to validate onsubmit and submit the form using ajax - it's crucial

Seeking assistance for validating a form and sending it with AJAX. Validation without the use of ''onsubmit="return validateForm(this);"'' is not functioning properly. However, when the form is correct, it still sends the form (page r ...

How to retrieve a value from an Angular form control in an HTML file

I have a button that toggles between map view and list view <ion-content> <ion-segment #viewController (ionChange)="changeViewState($event)"> <ion-segment-button value="map"> <ion-label>Map</ion-label> & ...