0

I want to customize the dialog box in jqx scheduler dialog box title. Instead of 'Create new appointment' i want to display "Create a new business schedule". I work with python django so in the code there are some elements from django template code. So far i create , edit, delete appointments with ajax and django as backend.

     var items;

    function setAvailability(price_data,persons_data,start_date,end_date, id, a_type, description){
      availability_data = {
        pk : "{{form.instance.pk}}",
        csrfmiddlewaretoken: "{{ csrf_token }}",
        price:price_data,
        persons:persons_data,
        from_date:start_date,
        to_date:end_date,
        a_type_data:a_type,
        av_description:description
      }
      if(id) {
        availability_data['event'] = id;
      }

      $.ajax({
        url: "{% url 'set-availability' %}",
        method: "POST",
        data: availability_data,
        dataType: "json",
        success: function(response){
          var source = {
              datatype: "json",
              dataFields: [
                  { name: 'id', type: 'integer' },
                  { name: 'description', type: 'string' },
                  { name: 'location', type: 'string' },
                  { name: 'status', type: 'string' },
                  { name: 'price', type: 'number' },
                  { name: 'persons', type: 'number' },
                  { name: 'subject', type: 'integer' },
                  { name: 'start', type: 'date', format: "yyyy-MM-dd"},
                  { name: 'end', type: 'date', format: "yyyy-MM-dd"}
              ],
              id: 'id',
              url: "{% url 'get-availability' %}?pk={{form.instance.pk}}"
          };
          var adapter = new $.jqx.dataAdapter(source);
          $("#scheduler").jqxScheduler({
            source: adapter
          })
          return response;
        }
      })
    }

    $.ajax({
      url: "{% url 'get-availability' %}",
      method: "GET",
      data: { pk : "{{form.instance.pk}}" },
      dataType: "json",
      success: function(response){
        items = response;
        var source = {
            datatype: "array",
            dataFields: [
                { name: 'id', type: 'integer' },
                { name: 'description', type: 'string' },
                { name: 'location', type: 'string' },
                { name: 'status', type: 'string' },
                { name: 'price', type: 'number' },
                { name: 'persons', type: 'number' },
                { name: 'subject', type: 'integer' },
                { name: 'start', type: 'date', format: "yyyy-MM-dd"},
                { name: 'end', type: 'date', format: "yyyy-MM-dd"}
            ],
            id: 'id',
            localData: items
        };
        var adapter = new $.jqx.dataAdapter(source);
        $("#scheduler").jqxScheduler({
            date: new $.jqx.date(2018, 02, 01),
            width: 850,
            height: 600,
            source: adapter,
            editDialogDateTimeFormatString: 'yyyy-MM-dd',
            editDialogDateFormatString: 'yyyy-MM-dd',
            showLegend: false,
            localization: { editDialogStatuses: {
                available: "Available",
              booked: "Booked"
            }},
            renderAppointment: function(data)
            {
              if (data.appointment.status == "available") {
                    data.style = "#B8E6A3";
              }
              else if (data.appointment.status == "booked") {
                data.style = "#FF0013";
              }
              return data;
            },
            ready: function () {
                $("#scheduler").jqxScheduler('ensureAppointmentVisible', 'id1');
            },
            resources:
            {
                colorScheme: "scheme05",
                dataField: "id",
                source:  new $.jqx.dataAdapter(source)
            },

            appointmentDataFields:
            {
              id: "id",
              description: "description",
              location: "location",
              subject: "subject",
              price: "price",
              persons: "persons",
              status: "status",
              calendar: 'calendar',
              from: "start",
              to: "end",
            },
            view: 'monthView',
            views:
            [
                'monthView'
            ],
            renderAppointment: function (dialog, fields, renderAppointment) {
              console.info('render appointment:', dialog);
            },
            editDialogCreate: function (dialog, fields, editAppointment) {
              fields.repeatContainer.hide();
              fields.subjectContainer.hide();
              fields.timeZoneContainer.hide();
              fields.colorContainer.hide();
              fields.resourceContainer.hide();
              fields.allDayContainer.hide();
              fields.locationContainer.hide();
              fields.fromContainer.hide();
              fields.toContainer.hide();
              fields.fromLabel.html("Start");
              fields.toLabel.html("End");
              var priceField = ''
              var personsField = ""
              priceField += "<div>"
              priceField += "<div class='jqx-scheduler-edit-dialog-label'>Price</div>"
              priceField += "<div class='jqx-scheduler-edit-dialog-field'><input type='number' id='price' step='0.01' /></div>"
              priceField += "</div>"
              personsField += "<div>"
              personsField += "<div class='jqx-scheduler-edit-dialog-label'>Persons</div>"
              personsField += "<div class='jqx-scheduler-edit-dialog-field'><input type='number' id='persons' /></div>"
              personsField += "</div>"

              var i = 0;

              $('#dialogscheduler').children('div').each(function () { // loop trough the div's (only first level childs) elements in dialogscheduler
                  i += 1;
                  if (i == 2) { // places the field in the third position.
                  $(this).after(priceField);
                  $(this).after(personsField);
                  };
              });
            },
            editDialogOpen: function (dialog, fields, editAppointment) {
              console.info(dialog);
              fields.repeatContainer.hide();

            }
        });
        $('#scheduler').on('editDialogOpen', function (event) {

          var args = event.args;
          var appointment = args.appointment;
          if(appointment){
            $('#dialogscheduler > div').find('#price').val(appointment.price);
            $('#dialogscheduler > div').find('#persons').val(appointment.persons);
          }
          else {
            $('#dialogscheduler > div').find('#price').val(0);
            $('#dialogscheduler > div').find('#persons').val(0);
            $('#dialogscheduler > div').find('#from').val('');
            $('#dialogscheduler > div').find('#to').val('');
            $('#dialogscheduler > div').find('#description').val('');
            $('#dialogscheduler > div').find('#status').val();
          }
        });
        $('#scheduler').on('appointmentAdd', function (event) {
            var price_data = $('#dialogscheduler > div').find('#price').val();
            var persons_data = $('#dialogscheduler > div').find('#persons').val();
            var a_type = event.args.appointment.status;
            var description = event.args.appointment.description;
            var start_date = event.args.appointment.from.toString();
            var id = null;
            var end_date = event.args.appointment.to.toString();
            var availability = setAvailability(price_data,persons_data,start_date,end_date,id, a_type, description);
          });
        $('#scheduler').on('appointmentDelete', function (event) {
            var id = event.args.appointment.id;
            deleteEvent(id);
          });
        $('#scheduler').on('appointmentChange', function (event) {
            var id = event.args.appointment.id;
            var price_data = $('#dialogscheduler > div').find('#price').val();
            var persons_data = $('#dialogscheduler > div').find('#persons').val();
            var description = event.args.appointment.description;
            var a_type = event.args.appointment.status;
            var start_date = event.args.appointment.from.toString();
            alert(start_date);
            var end_date = event.args.appointment.to.toString();
            var availability = setAvailability(price_data,persons_data,start_date,end_date,id, a_type,description);

        });
      }
    })

    function deleteEvent(pk) {
        $.ajax({
          url: "{% url 'delete-availability' %}",
          method: "GET",
          data: { pk : pk, business_pk:'{{form.instance.pk}}'},
          dataType: "json",
          success: function(response){
            console.info(response)
          }
        })
    }
Dimitris Kougioumtzis
  • 2,339
  • 1
  • 25
  • 36

3 Answers3

0

I think you need to put the below code snippet in the editDialogOpen() function. This is working for me.

setTimeout(function() {
    dialogRef.find("div").first().find("div").first().html("Create a new business schedule");
}, 10);
AS Mackay
  • 2,831
  • 9
  • 19
  • 25
Sairam Vinjamuri
  • 35
  • 1
  • 1
  • 6
0

You can use the localization to do it. I'm using jqxScheduler with Angular, so:

  1. Add [localization]="localization" into the component definition that should looks like:

    <jqxScheduler #scheduler [editDialogCreate]="editDialogCreate" [localization]="localization">

  2. Add a localization property into the component class. jqxScheduler has different titles for create and edit appointents:

    localization = { editDialogTitleString: 'Edit a business schedule', editDialogCreateTitleString: 'Create a new business schedule' };

jQWidgets has implementation examples to other languages. JQuery here.

Bob Rivers
  • 5,261
  • 6
  • 47
  • 59
0
$("#scheduler").jqxScheduler({    
  localization: {
                 editDialogCreateTitleString: "Create a new business schedule",
  },
});
Muhammad Zakaria
  • 1,269
  • 6
  • 14