Devextreme

// ──────────────────────────────────

// **********************************************************************
// An event fired by the application when a command is passed via the URL
// **********************************************************************
event Devextreme.OnCommand(
  string Command // It is a string containing the value of the URL parameter named CMD
)
{
   
  if (DXCommunicator.isDXCommand(Command))
  {
    string paramContent = Devextreme.getURLParam("content")
    Devextreme.DXCommunicator.HandleCommand(paramContent)
  }
}


// ──────────────────────────────────

// ***************************************************************************
// returns a subform (this is needed to avoid runtime component naming issues)
// ***************************************************************************
public IDForm Devextreme.getDevextremeSubformInstance(
  string:devextremeSubformTypes subformType // 
)
{
  IDForm result = null
  switch (subformType)
  {
    case html:
      result = HTMLEditor.newInstance(SubForm, ...)
    break
     
    default:
      Devextreme.DTTLogMessage(formatMessage("subformType |1 not supported", subformType, ...), ..., DTTError)
    break
  }
   
  return result
}


// ──────────────────────────────────

// ***********************************************
// Event raised to the form when loading in memory
// ***********************************************
event Scheduler.Load()
{
  this.hasCloseButton = false
  this.hasCaption = false
  this.SchedulerController = SchedulerController.create(IDForm())
  Devextreme.DXCommunicator.addForm(this.IDForm())
}


// ──────────────────────────────────

// ********************************************
// Event raised by the form before it is closed
// ********************************************
event Scheduler.Unload(
  inout int Cancel // If set to True, closure of the form is canceled.
  boolean Confirm  // Represents the user's selection for closing modal forms. True if the user confirms their choice, otherwise False.
)
{
  // update the DX Communicator
  Devextreme.DXCommunicator.removeForm(this.IDForm())
}


// ──────────────────────────────────

// ************************************************************************
// Event raised when a form sends a message using the SendMessage procedure
// ************************************************************************
event Scheduler.OnSendMessage(
  string Message // Indicates the name of the message
  IDForm Sender  // Identifies the form that sent the message. IDForm type object.
  IDDocument Doc // Optional. Document associated with the message.
  string Par1    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par2    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par3    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par4    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
)
{
  switch (Message)
  {
    case addEvent:
      SchedulerEvent event = (SchedulerEvent)Doc
      this.addEvent(event)
    break
    case deleteEvent:
      SchedulerEvent event = (SchedulerEvent)Doc
      this.deleteEvent(event)
    break
    case configuration:
      SchedulerConfiguration configuration = (SchedulerConfiguration)Doc
      if (configuration)
      {
         this.SchedulerController.setConfiguration(configuration)
      }
      IDMap schedulerConfig = this.SchedulerController.getConfigurationToJson()
      Scheduler.configuration = schedulerConfig
    break
    case changeOption:
      MessageData m = (MessageData)Doc
      this.updateOption(m)
    break
    case setLocale:
      MessageData md = (MessageData)Doc
      string newLocale = md.getTag(data)
      Scheduler.setLocale(newLocale)
    break
    case refresh:
      this.reloadSchedulerData()
    break
    case appointmentClick:
      MessageData md = (MessageData)Doc
      string eventId = md.Content.getValue(data)
      this.notifyAppointmentClick(eventId)
    break
    case appointmentDoubleClick:
      MessageData md = (MessageData)Doc
      string eventId = md.Content.getValue(data)
      this.notifyAppointmentDoubleClick(eventId)
    break
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
private void Scheduler.deleteEvent(
  SchedulerEvent sEvent // 
)
{
  IDMap idm = new()
  idm.setValue(ID, sEvent.ID)
  Scheduler.deleteEvent(idm)
  this.SchedulerController.deleteEvent(sEvent)
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
private void Scheduler.ReloadEventsInScheduler()
{
  IDCollection coll of SchedulerEvent = this.SchedulerController.getEvents()
  for each SchedulerEvent se in coll
  {
    Scheduler.addEvent(se.toJson())
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
private void Scheduler.updateDim(
  float height // 
  float width  // 
)
{
  IDArray ida = new()
  IDMap height = new()
  height.setValue("name", "height")
  height.setValue("value", height)
  ida.setObject(0, height)
   
  IDMap width = new()
  width.setValue("name", "width")
  width.setValue("value", width)
  ida.setObject(1, width)
   
   
   
   
   
  Scheduler.setOptions(ida)
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
private void Scheduler.reloadSchedulerData()
{
  // reset the configuration
  IDMap configuration = this.SchedulerController.getConfigurationToJson()
  Scheduler.configuration = configuration
   
  // realod the events
  this.ReloadEventsInScheduler()
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
private void Scheduler.notifyAppointmentDoubleClick(
  string eventId // 
)
{
  if (eventId != "")
  {
    IDForm parentForm = this.getParentForm()
    parentForm.sendMessage(appointmentDoubleClick, null, eventId, ...)
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
private void Scheduler.notifyAppointmentClick(
  string eventId // 
)
{
  if (eventId != "")
  {
    IDForm parentForm = this.getParentForm()
    parentForm.sendMessage(appointmentClick, null, eventId, ...)
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
private void Scheduler.actuallyNotUsedHandleAppointmentDeletedInDxScheduler(
  IDMap info // 
//)
//{
//  string idDeletedEvent = toString(info.getValue(ID))
//  if (idDeletedEvent != "")
//  {
//    SchedulerEvent deletedEvent = new()
//    deletedEvent.ID = idDeletedEvent
//    this.SchedulerController.deleteEvent(deletedEvent)
//  }
//}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
private void Scheduler.addEvent(
  SchedulerEvent sEvent // 
)
{
  this.SchedulerController.addEvent(sEvent)
  Scheduler.addEvent(sEvent.toJson())
}


// ──────────────────────────────────

// **************************************************************************************************************************************************
// this procedure extracts the option request data and share it with the Scheduler Controller
// In that step we store the changed configuration to be used in the future (if we don't to this, after the user refreshed the browser the information
// will be lost)
// After that we call the setOptions function defined in the dxScheduler wrapper
// **************************************************************************************************************************************************
private void Scheduler.updateOption(
  MessageData messageData // 
)
{
  IDMap appOptionRequest = messageData.Content // 
  IDArray requestDxSchedulerChange = this.SchedulerController.prepareOptionChangeRequest(appOptionRequest)
  Scheduler.setOptions(requestDxSchedulerChange)
}


// ──────────────────────────────────

// ***********************************************
// Event raised to the form when loading in memory
// ***********************************************
event Gantt.Load()
{
  this.hasCloseButton = false
  this.hasCaption = false
  this.GanttController = new()
  this.GanttController.init()
   
   
  // notify DX Communicator that the form is being instantiated
  Devextreme.DXCommunicator.addForm(this.IDForm())
  this.GanttController.storeFormIndex(this.IDForm())
}


// ──────────────────────────────────

// ************************************************************************
// Event raised when a form sends a message using the SendMessage procedure
// ************************************************************************
event Gantt.OnSendMessage(
  string Message // Indicates the name of the message
  IDForm Sender  // Identifies the form that sent the message. IDForm type object.
  IDDocument Doc // Optional. Document associated with the message.
  string Par1    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par2    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par3    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par4    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
)
{
  switch (Message)
  {
    case configuration:
      MessageData md = (MessageData)Doc
      IDCollection tasks of GanttTask = (IDCollection)md.Content.getObject("tasks")
      IDMap configurationMessage = new()
      this.GanttController.setTasks(tasks)
      configurationMessage.setObject("tasks", this.GanttController.getTasksAsArray())
       
      configurationMessage.setValue("indeFormIndex", this.GanttController.getFormIndex())
       
      configurationMessage.setValue("focusOnDate", md.Content.getValue("focusOnDate"))
       
      GanttConfiguration ganttConfiguration = (GanttConfiguration)md.Content.getObject("configuration")
      this.GanttController.SetupConfiguration(ganttConfiguration)
      IDMap configuration = this.GanttController.getConfigurationToJson()
      configurationMessage.setObject("configuration", configuration)
      if (tasks != null)
      {
         Gantt.configuration = configurationMessage
      }
    break
    case focusOnToday:
      Gantt.focusOnToday()
    break
    case initialized:
      // da rivedere
      this.ganttIsInitialized()
    break
  }
}


// ──────────────────────────────────

// ***********
// Initialized
// ***********
event Gantt.Gantt.Initialized()
{
}


// ──────────────────────────────────

// ****************************************************************************************************
// this procedure has to reload the Resource Array if it has been customized in the SchedulerController
// 
// ****************************************************************************************************
private void Gantt.ReloadResourcesInTheScheduler()
{
  IDArray resources = null
  if (resources)
  {
    if (resources.length() > 0)
    {
    }
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
private void Gantt.ganttIsInitialized()
{
  IDMap configurationMessage = new() // 
  configurationMessage.setObject("configuration", this.GanttController.getConfigurationToJson())
  configurationMessage.setObject("tasks", this.GanttController.getTasksAsArray())
  Gantt.configuration = this.GanttController.getConfigurationToJson()
}


// ──────────────────────────────────

// ************************************************************************
// Event raised when a form sends a message using the SendMessage procedure
// ************************************************************************
event HTMLEditor.OnSendMessage(
  string Message // Indicates the name of the message
  IDForm Sender  // Identifies the form that sent the message. IDForm type object.
  IDDocument Doc // Optional. Document associated with the message.
  string Par1    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par2    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par3    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par4    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
)
{
  switch (Message)
  {
    case configuration:
      HTMLEditorConfiguration configuration = (HTMLEditorConfiguration)Doc
      this.HTMLEditorController = HTMLEditorController.create(configuration)
      this.HTMLEditorController.storeFormIndex(this.IDForm())
      IDMap htmlEditorConfig = this.HTMLEditorController.getConfigurationToJson()
      DevextremeHTMLEditor.configuration = htmlEditorConfig
       
    break
    case valueChanged:
      MessageData md = (MessageData)Doc
      string base64Content = md.Content.getValue("data")
      string actualContent = base64Decode(base64Content)
      this.HTMLEditorController.updateOriginalObjectWithUpdatedValue(actualContent)
    break
  }
}


// ──────────────────────────────────

// ***********************************************
// Event raised to the form when loading in memory
// ***********************************************
event HTMLEditor.Load()
{
  Devextreme.DXCommunicator.addForm(this.IDForm())
  this.hasCaption = false
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string HTMLEditor.getContent()
{
  string content = this.HTMLEditorController.getHtmlValue()
  return content
}


// ──────────────────────────────────

// ************************************************************************
// Event raised when a form sends a message using the SendMessage procedure
// ************************************************************************
event Datagrid.OnSendMessage(
  string Message // Indicates the name of the message
  IDForm Sender  // Identifies the form that sent the message. IDForm type object.
  IDDocument Doc // Optional. Document associated with the message.
  string Par1    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par2    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par3    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par4    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
)
{
  if (Message == setData)
  {
    DGController dc = (DGController)Doc
    if (dc)
    {
      IDMap idm = dc.getConfiguration()
      Iddxdatagrid.data = idm
    }
  }
}


// ──────────────────────────────────

// **********
// Save
// **********
event Datagrid.Iddxdatagrid.Save(
  IDMap data // What is this parameter for?
)
{
  if (data)
  {
    string data = JSON.stringify(data)
    Devextreme.messageBox(data)
  }
}


// ──────────────────────────────────

// ************************************************************************
// Event raised when a form sends a message using the SendMessage procedure
// ************************************************************************
event Piechart.OnSendMessage(
  string Message // Indicates the name of the message
  IDForm Sender  // Identifies the form that sent the message. IDForm type object.
  IDDocument Doc // Optional. Document associated with the message.
  string Par1    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par2    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par3    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par4    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
)
{
  switch (Message)
  {
    case setData:
      PieChartDataController controller = (PieChartDataController)Doc
      this.PieChartDataController = controller
      IDMap data = controller.getConfiguratioin()
      Iddxpiechart.data = data
    break
  }
}


// ──────────────────────────────────

// ***********************************************
// Event raised to the form when loading in memory
// ***********************************************
event Piechart.Load()
{
  this.hasCloseButton = false
  this.hasCaption = false
}


// ──────────────────────────────────

// ***********************************************
// Event raised to the form when loading in memory
// ***********************************************
event Calendar.Load()
{
  this.hasCaption = false
  this.hasCloseButton = false
  this.RD3CalendarController.init()
}


// ──────────────────────────────────

// ************************************************************************
// Event raised when a form sends a message using the SendMessage procedure
// ************************************************************************
event Calendar.OnSendMessage(
  string Message // Indicates the name of the message
  IDForm Sender  // Identifies the form that sent the message. IDForm type object.
  IDDocument Doc // Optional. Document associated with the message.
  string Par1    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par2    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par3    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par4    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
)
{
//  switch (Message)
//  {
//    case configuration:
//      MessageData md = (MessageData)Doc
//      IDMap idm = (IDMap)md.getObjectTag(data)
//      this.RD3CalendarController.SetupConfiguration(idm)
//      Iddxcalendar.setOptions(data)
//    break
//    case setLocale:
//      MessageData md = (MessageData)Doc
//      string newLocale = md.getTag(data)
//      Iddxcalendar.setLocale(newLocale)
//    break
//  }
}


// ──────────────────────────────────

// ************************************************************************
// Event raised when a form sends a message using the SendMessage procedure
// ************************************************************************
event Pivot.OnSendMessage(
  string Message // Indicates the name of the message
  IDForm Sender  // Identifies the form that sent the message. IDForm type object.
  IDDocument Doc // Optional. Document associated with the message.
  string Par1    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par2    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par3    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par4    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
)
{
  switch (Message)
  {
    case setData:
      PivotDataController controller = (PivotDataController)Doc
      this.PivotDataController = controller
      Iddxpivot.data = controller.getConfiguratioin()
    break
    case changeType:
      MessageData md = (MessageData)Doc
      this.PivotDataController.setChartType(md.getTag(data))
      string script = this.PivotDataController.computeChartScript()
      Iddxpivot.changeChartType(script)
    break
    case setLocale:
      MessageData md = (MessageData)Doc
      string locale = md.getTag(data)
      Iddxpivot.setLocale(locale)
    break
    case hidePivot:
      this.PivotDataController.sethidePivot(true)
      this.applyChartPivotVisibility()
    break
    case hideChart:
      this.PivotDataController.SetHideChart(true)
      this.applyChartPivotVisibility()
    break
    case showPivot:
      this.PivotDataController.sethidePivot(false)
      this.applyChartPivotVisibility()
    break
    case showChart:
      this.PivotDataController.SetHideChart(false)
      this.applyChartPivotVisibility()
    break
  }
}


// ──────────────────────────────────

// ***********************************************
// Event raised to the form when loading in memory
// ***********************************************
event Pivot.Load()
{
  this.hasCaption = false
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void Pivot.applyChartPivotVisibility()
{
  if (this.PivotDataController)
  {
    boolean hidePivot = this.PivotDataController.GetHidePivot()
    string pivotDiv = this.PivotDataController.getPivotDivID()
    string contentVisibilityPivot = if(hidePivot, "hidden", "auto")
    string scriptForPivot = formatMessage("$('#|1').css("content-visibility", "|2");", pivotDiv, contentVisibilityPivot, ...)
    Devextreme.executeOnClient(scriptForPivot)
     
    boolean hideChart = this.PivotDataController.GetHideChart()
    string chartDiv = this.PivotDataController.getChartDivID()
    string contentVisibilityChart = if(hideChart, "hidden", "auto")
    string scriptForChart = formatMessage("$('#|1').css("content-visibility", "|2");", chartDiv, contentVisibilityChart, ...)
    Devextreme.executeOnClient(scriptForChart)
     
  }
}


// ──────────────────────────────────

// ***********************************************
// Event raised to the form when loading in memory
// ***********************************************
event SchedulerWithDatePicker.Load()
{
  this.hasCloseButton = false
  this.hasCaption = false
  Devextreme.SchedulerWithDatePickerHook.Scheduler = Scheduler.IDForm()
  Devextreme.SchedulerWithDatePickerHook.SchedulerDatePicker = DatePicker.IDForm()
  Devextreme.SchedulerWithDatePickerHook.SchedulerWithDatePicker = this.IDForm()
}


// ──────────────────────────────────

// ************************************************************************
// Event raised when a form sends a message using the SendMessage procedure
// ************************************************************************
event SchedulerWithDatePicker.OnSendMessage(
  string Message // Indicates the name of the message
  IDForm Sender  // Identifies the form that sent the message. IDForm type object.
  IDDocument Doc // Optional. Document associated with the message.
  string Par1    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par2    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par3    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par4    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
)
{
  switch (Message)
  {
    case "updateCurrentView":
      Devextreme.SchedulerWithDatePickerHook.Scheduler.sendMessage("updateCurrentView", Doc, ...)
    break
    case "schedulerConfiguration":
      Scheduler.sendMessage(configuration, Doc, ...)
    break
    case "datePickerConfiguration":
      DatePicker.sendMessage(configuration, Doc, ...)
    break
    case addEvent:
      Scheduler.sendMessage(addEvent, Doc, ...)
      DatePicker.sendMessage(addEvent, Doc, ...)
    break
  }
}


// ──────────────────────────────────

// ******************
// CurrentDateChanged
// ******************
event DatePicker.Idcalendarrangepicker.CurrentDateChanged(
  string optionName // What is this parameter for?
  date optionValue  // What is this parameter for?
)
{
  if (SchedulerWithDatePicker.isOpen())
  {
    MessageData m = new()
    m.setTag(data, optionValue)
    SchedulerWithDatePicker.sendMessage("updateCurrentView", m, ...)
  }
}


// ──────────────────────────────────

// **************
// selectionRange
// **************
event DatePicker.Idcalendarrangepicker.selectionRange(
  string optionName // What is this parameter for?
  date startDate    // startDate
  date endDate1     // endDate
)
{
  MessageData m = new()
  m.setTag(data, startDate)
  Devextreme.SchedulerWithDatePickerHook.SchedulerWithDatePicker.sendMessage("updateCurrentView", m, ...)
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DiagramForm.Save()
{
  Diagram.getDataFromDiagram()
   
}


// ──────────────────────────────────

// ****************************************
// Describe the purpose of this function...
// ****************************************
event DiagramForm.Diagram.OnSaveDiagram(
  string data // What is this parameter for?
)
{
  Devextreme.DTTLogMessage(data, ...)
}


// ──────────────────────────────────

// ****************************************
// Describe the purpose of this function...
// ****************************************
event DiagramForm.Diagram.onInserting(
  IDMap value // What is this parameter for?
)
{
  MessageData md = new()
  md.setObjectTag(data, value)
  this.ParentForm.sendMessage(onInsertingStep, md, ...)
   
   
}


// ──────────────────────────────────

// ****************************************
// Describe the purpose of this function...
// ****************************************
event DiagramForm.Diagram.onItemDblClick(
  IDMap Info // What is this parameter for?
)
{
  MessageData md = new()
  md.setObjectTag(data, Info)
  this.ParentForm.sendMessage(onItemDblClick, md, ...)
   
}


// ──────────────────────────────────

// ***********
// onItemClick
// ***********
event DiagramForm.Diagram.onItemClick(
  IDMap Info // Info
)
{
  MessageData md = new()
  md.setObjectTag(data, Info)
  this.ParentForm.sendMessage(onItemClick, md, ...)
}


// ──────────────────────────────────

// **********
// print
// **********
event DiagramForm.Diagram.print(
  string Info // Info
)
{
  MessageData md = new()
  md.setTag(data, Info)
  this.ParentForm.sendMessage("printResponse", md, ...)
}


// ──────────────────────────────────

// **********
// export
// **********
event DiagramForm.Diagram.export(
  string Info // Info
)
{
  if (this.ParentForm)
  {
    DiagramContent dc = DiagramContent.create(Info)
    this.ParentForm.sendMessage(diagramContent, dc, ...)
  }
}


// ──────────────────────────────────



// ──────────────────────────────────

// ****************************************
// Describe the purpose of this function...
// ****************************************
event DiagramForm.Diagram.onInsertingConnection(
  IDMap value // What is this parameter for?
)
{
  MessageData md = new()
  IDMap key = value
  md.setObjectTag(data, key)
  this.ParentForm.sendMessage(onInsertingConnection, md, ...)
}


// ──────────────────────────────────

// ****************************************
// Describe the purpose of this function...
// ****************************************
event DiagramForm.Diagram.onDeleteConnection(
  IDMap key // What is this parameter for?
)
{
  MessageData md = new()
  md.setObjectTag(data, key)
  this.ParentForm.sendMessage(onDeleteConnection, md, ...)
}


// ──────────────────────────────────

// ****************************************
// Describe the purpose of this function...
// ****************************************
event DiagramForm.Diagram.onUpdateConnection(
  IDMap value // What is this parameter for?
)
{
  MessageData md = new()
  IDMap key = null
  md.setObjectTag(data, key)
  this.ParentForm.sendMessage(onUpdateConnection, md, ...)
}


// ──────────────────────────────────

// ****************************************
// Describe the purpose of this function...
// ****************************************
event DiagramForm.Diagram.SetUnsetReadonly(
  IDMap Info // What is this parameter for?
)
{
  MessageData md = new()
  md.setObjectTag(data, Info)
  this.ParentForm.sendMessage(setUnsetReadOnlyMode, md, ...)
}


// ──────────────────────────────────

// ****************************************
// Describe the purpose of this function...
// ****************************************
event DiagramForm.Diagram.onConnectionDblClick(
  IDMap Info // What is this parameter for?
)
{
  MessageData md = new()
  md.setObjectTag(data, Info)
  this.ParentForm.sendMessage(onConnectionDblClick, md, ...)
}


// ──────────────────────────────────

// ************************************************************************
// Event raised when a form sends a message using the SendMessage procedure
// ************************************************************************
event DiagramForm.OnSendMessage(
  string Message // Indicates the name of the message
  IDForm Sender  // Identifies the form that sent the message. IDForm type object.
  IDDocument Doc // Optional. Document associated with the message.
  string Par1    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par2    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par3    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
  string Par4    // Optional. Parameter associated with the message; can be of any type (except object or generic document).
)
{
  switch (Message)
  {
    case load:
       
      // populate diagram property storedShape with fakeDataFromInde
      Diagram.storedShapeConfiguration = Par3
      Diagram.storedShape = Par1
      Diagram.storedConnection = Par2
    break
    case exportJson:
      Diagram.exportJson()
    break
    case importJson:
      DiagramContent content = cast(Doc)
      this.DiagramController.updateDiagramContent(content)
      Diagram.importJson(this.DiagramController.getContent())
    break
    case print:
      Diagram.printwkf()
    break
    case configuration:
      DiagramConfiguration dc = (DiagramConfiguration)Doc
      this.DiagramController.setConfiguration(dc)
      Diagram.configuration = this.DiagramController.getConfigurationToJson()
    break
    case onItemDblClick:
      MessageData md = cast(Doc)
      this.MessageData = md
      InputStep.show(Modal)
      InputStep.Open(md)
       
    break
    case onConnectionDblClick:
      MessageData md = cast(Doc)
      this.MessageData = md
       
      InputFlow.show(Modal)
      InputFlow.Open(md)
//      Devextreme.messageBox(formatMessage("Questa è la connection con key |1 che parte da |2 e arriva a |2", md.Content.getValue("key"), md.
//            Content.getValue("fromKey"), md.Content.getValue("toKey"), ...))
    break
    case onInsertingStep:
      MessageData md = cast(Doc)
      this.MessageData = md
       
//      InputStep.show(Modal)
//      InputStep.Open(md)
      //  
      // here we can put the logic of onInsering Event we have the droppedShape info in md
       
    break
    case onDeleteStep:
      MessageData md = cast(Doc)
      this.MessageData = md
      Devextreme.messageBox("Shape Cancellata: " + toString(md.Content.getValue("id")))
    break
    case onInsertingConnection:
      MessageData md = cast(Doc)
      this.MessageData = md
      Devextreme.messageBox(toString(md.Content.getValue("id")) + "Nuova conessione da " + toString(md.Content.getValue("fromId")) + " a " +
            toString(md.Content.getValue("toId")))
    break
    case onUpdateConnection:
      MessageData md = cast(Doc)
      this.MessageData = md
      Devextreme.messageBox("Updated Connection: " + toString(md.Content.getValue("id")))
    break
    case onDeleteConnection:
      MessageData md = cast(Doc)
      this.MessageData = md
      Devextreme.messageBox("Connection Cancellata: " + toString(md.Content.getValue("id")))
    break
    case readonly:
      Diagram.readOnly = if(Par1 == "-1", true, false)
    break
    case setUnsetReadOnlyMode:
      MessageData md = cast(Doc)
      this.MessageData = md
      //  
      // the message passed from the frontEnd said if the diagram is or not in readonly
      boolean isDiagramInReadOnly = md.Content.getValue("isReadOnly")
      if (isDiagramInReadOnly = true)
      {
         boolean response = Devextreme.messageConfirmEx("Sicuro di voler sbloccare il diagramma? ", "Si;No")
         if (response == 1)
         {
           Diagram.toggleReadOnlyMode(false)
//           Diagram.readOnly = false
         }
         else 
         {
//           Diagram.readOnly = true
         }
      }
      if (md.Content.getValue("isReadOnly") == false)
      {
         Diagram.toggleReadOnlyMode(true)
//         Diagram.readOnly = true
      }
    break
  }
  this.ParentForm = Sender
}


// ──────────────────────────────────

// ***********************************************
// Event raised to the form when loading in memory
// ***********************************************
event DiagramForm.Load()
{
  MessageData md = null
  this.hasCloseButton = false
  this.hasConfirmButton = false
//  this.hasCaption = false
  this.DiagramController = DiagramController.create(IDForm())
  Devextreme.DXCommunicator.addForm(this.IDForm())
   
  this.sendMessage(readonly, null, 0 - 1, ...)
}


// ──────────────────────────────────

// *********************************************************************************
// Event raised by the form object in web applications when a modal window is closed
// *********************************************************************************
event DiagramForm.EndModal(
  int LookupForm       // An integer that identifies the modal form that was just closed, using the Me function of the form object to make the co...
  boolean Result       // True if the user confirmed the choice, closing the model form using the confirmation button on the title bar; otherwise...
  inout boolean Cancel // If set to True, any subsequent automatic processing will be canceled. In this case, the framework will not attempt to a...
)
{
   
  if (LookupForm == InputStep.me())
  {
    if (Devextreme.ModalClose == true)
    {
      MessageData.Content.setValue("description", InputStep.MessageData.Descrizione)
      MessageData.Content.setValue("text", InputStep.MessageData.Nome)
      MessageData.Content.setValue("color", "#d5f2ed")
      Diagram.updateStep(this.MessageData.Content.getValue("key"), InputStep.MessageData.Descrizione, InputStep.MessageData.Nome, 
            InputStep.MessageData.NuovoID)
    }
  }
   
  if (LookupForm == InputFlow.me())
  {
    if (Devextreme.ModalClose == true)
    {
      MessageData.Content.setValue("text", InputFlow.MessageData.Text)
      Diagram.updateFlow(this.MessageData.Content.getValue("key"), InputFlow.MessageData.Text)
    }
  }
   
   
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DiagramForm.ButtonAddStep()
{
  Diagram.addStep(22222)
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DiagramForm.ButtonLockUnlock()
{
  boolean response = Devextreme.messageConfirmEx("Sicuro di voler sbloccare il diagramma? ", "Si;No")
  if (response == 1)
  {
    Diagram.toggleReadOnlyMode(false)
  }
}


// ──────────────────────────────────



// ──────────────────────────────────

// ************************************************************
// Spiega quale elaborazione viene eseguita da questa procedura
// ************************************************************
public void InputStep.Open(
  MessageData md // Scrivi un commento per questo parametro o premi backspace per eliminare questo commento
)
{
  MessageData.setDocument(md, true)
   
}


// ──────────────────────────────────

// ************************************************************
// Spiega quale elaborazione viene eseguita da questa procedura
// ************************************************************
public void InputStep.Conferma()
{
  Devextreme.ModalClose = true
  this.close(...)
}


// ──────────────────────────────────

// ************************************************************
// Spiega quale elaborazione viene eseguita da questa procedura
// ************************************************************
public void InputStep.Annulla()
{
  Devextreme.ModalClose = false
  this.close(...)
}


// ──────────────────────────────────

// ************************************************************
// Spiega quale elaborazione viene eseguita da questa procedura
// ************************************************************
public void InputFlow.Open(
  MessageData md // Scrivi un commento per questo parametro o premi backspace per eliminare questo commento
)
{
  MessageData.setDocument(md, true)
   
}


// ──────────────────────────────────



// ──────────────────────────────────

// ************************************************************
// Spiega quale elaborazione viene eseguita da questa procedura
// ************************************************************
public void InputFlow.Annulla()
{
  Devextreme.ModalClose = false
  this.close(...)
}


// ──────────────────────────────────

// ************************************************
// all devextreme commands has DXCOM in the command
// ************************************************
public static boolean DXCommunicator.isDXCommand(
  string command // 
)
{
  return find(command, "DXCOM", ...) > 0
}


// ──────────────────────────────────

// ********************************************************************************************
// this procedure gets the content of the command & it creates a message containing the content
// Then it sends to the right dx form instance the data retrieved and formatted
// ********************************************************************************************
public void DXCommunicator.HandleCommand(
  string parameterContent // 
)
{
  if (parameterContent != "")
  {
    IDMap json = cast(JSON.parse(parameterContent))
    int formID = json.getValue("id")
    string messageCMD = json.getValue("message")
    IDMap content = new()
    if (json.getDataType("content") == Object)
    {
      content = (IDMap)json.getObject("content")
    }
    else 
    {
      content.setValue(data, json.getValue("content"))
    }
    MessageData message = MessageData.create(content)
    for (int i = 0; i < DxFormInstances.length(); i = i + 1)
    {
      IDForm idf = (IDForm)DxFormInstances.getObject(i)
      if (idf.index == formID)
      {
         idf.sendMessage(messageCMD, message, ...)
      }
    }
  }
}


// ──────────────────────────────────

// **********************************************************
// notify DX Communicator that the form is being instantiated
// **********************************************************
public void DXCommunicator.addForm(
  IDForm form // 
)
{
  Devextreme.DTTLogMessage(form.index, ...)
  DxFormInstances.setObject(DxFormInstances.length(), form)
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DXCommunicator.removeForm(
  IDForm form // 
)
{
  for (int i = 0; i < DxFormInstances.length(); i = i + 1)
  {
    IDForm idf = (IDForm)DxFormInstances.getObject(i)
    int j = idf.index
    if (j == form.index)
    {
      DxFormInstances.remove(i)
    }
  }
}


// ──────────────────────────────────

// *********************************************
// Raised when the document is being initialized
// *********************************************
event DXCommunicator.OnInit()
{
  DxFormInstances = new()
  DxFormInstances.clear()
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string MessageData.getStringValue()
{
  return Content.getValue(data)
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static MessageData MessageData.create(
  IDMap content // 
)
{
  MessageData message = new()
  message.Content = content
  return message
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DxController.storeFormIndex(
  IDForm parentForm // 
)
{
  FormIndex = parentForm.index
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap DxController.getConfigurationToJson()
{
  IDMap configuration = Configuration.toJson()
  configuration.setValue("indeFormIndex", FormIndex)
  return configuration
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap DxConfiguration.toJson()
{
  IDMap idm = new()
  Devextreme.DTTLogMessage("ABSTRACT ERROR", ..., DTTError)
  return idm
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public SchedulerEvent SchedulerController.updateEvent(
  IDMap newEventProperties // 
)
{
  string IDEvent = newEventProperties.getValue(ID)
  SchedulerEvent eventToBeUpdated = new()
  for each SchedulerEvent se in Events
  {
    if (se.ID == IDEvent)
    {
      se.updateByIDMap(newEventProperties)
      eventToBeUpdated = se
    }
  }
  return eventToBeUpdated
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void SchedulerController.deleteEvent(
  SchedulerEvent sEvent // 
)
{
  for each SchedulerEvent se in Events
  {
    if (se.ID == sEvent.ID)
    {
      se.deleted = true
    }
  }
  Events.removeDeleted()
}


// ──────────────────────────────────

public void SchedulerController.buildBasicConfiguration()
{
  Configuration = new()
  IDMap viewsOPtion = new()
  IDArray views = new()
  views.setValue(0, day)
  views.setValue(1, week)
  views.setValue(2, workweek)
  views.setValue(3, month)
  views.setValue(4, agenda)
  viewsOPtion.setValue("name", views)
  viewsOPtion.setObject("value", views)
  SchedulerConfiguration = cast(SchedulerConfiguration.Create(400, 400, ..., 15, "Europe/Rome", 1, 8, 18, false, views, "week", now()))
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
private void SchedulerController.setupCustomFormToEditEvent(
  optional IDMap configuration // 
)
{
  IDForm editEventForm = (IDForm)configuration.getObject(editEventForm)
  if (editEventForm)
  {
    EventDetailForm = editEventForm
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDCollection SchedulerController.getEvents()
{
  return Events
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void SchedulerController.addEvent(
  SchedulerEvent newEvent // 
)
{
   
   
  boolean eventAlreadyInserted = false
  for each SchedulerEvent currentSe in Events
  {
    if (currentSe.ID == newEvent.ID)
    {
      eventAlreadyInserted = true
    }
  }
   
  if (!(eventAlreadyInserted))
  {
    Events.addRef(newEvent)
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void SchedulerController.setConfiguration(
  optional SchedulerConfiguration configuration // 
)
{
  if (configuration == null)
  {
    this.buildBasicConfiguration()
  }
  else 
  {
    EventDetailForm = configuration.EventDetailForm
     
    SchedulerConfiguration = configuration
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDArray SchedulerController.prepareOptionChangeRequest(
  IDMap request // 
)
{
  IDArray resultingArrayToBeSent = new()
   
  // update scheduler configuration
   
  IDMap resultToBeSent = SchedulerConfiguration.updateSingleConfiguration(request)
   
  // add the request in the resulting array to be sent to the dxScheduler wrapper
  resultingArrayToBeSent.setObject(0, resultToBeSent)
   
  return resultingArrayToBeSent
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static SchedulerController SchedulerController.create(
  IDForm parentForm // 
)
{
  SchedulerController sc = new()
  sc.init()
  sc.storeFormIndex(parentForm)
  return sc
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap SchedulerController.getConfigurationToJson()
{
  IDMap configuration = SchedulerConfiguration.toJson()
  configuration.setValue("indeFormIndex", FormIndex)
  return configuration
}


// ──────────────────────────────────

// *********************************************
// Raised when the document is being initialized
// *********************************************
event SchedulerController.OnInit()
{
  this.buildBasicConfiguration()
  //  
  // default value of OpenAs
  Openas = Modal
}


// ──────────────────────────────────

// **********************************************************************************
// this procedure updates the tags of the Scheduler events by the idmap passed by arg
// 
// **********************************************************************************
public void SchedulerEvent.updateByIDMap(
  IDMap newProperties // 
)
{
  Title = newProperties.getValue(text)
  StartDate = newProperties.getValue(startDate)
  EndDate = newProperties.getValue(endDate)
  ID = newProperties.getValue(ID)
  Type = newProperties.getValue(Type)
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap SchedulerEvent.toJson()
{
  IDMap eventAsIDMap = new()
  eventAsIDMap.setValue(text, Title)
  eventAsIDMap.setValue(employeeID, ResourceId)
  eventAsIDMap.setValue(startDate, StartDate)
  eventAsIDMap.setValue(endDate, EndDate)
  eventAsIDMap.setValue(Type, Type)
  eventAsIDMap.setValue(ID, ID)
  eventAsIDMap.setValue(Description, Description)
  eventAsIDMap.setValue(Image, Image)
  eventAsIDMap.setValue(editable, Editable)
  eventAsIDMap.setValue(color, Color)
  eventAsIDMap.setValue(allDay, AllDay)
  return eventAsIDMap
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static SchedulerEvent SchedulerEvent.create(
  string title                // 
  int resourceID              // 
  date time startDate         // 
  date time endDate           // 
  string type                 // 
  string ID                   // 
  string description          // 
  string image                // 
  boolean editable            // 
  optional string color = "#ffffff" // 
  optional boolean allDay = 0 // 
)
{
  SchedulerEvent se = new()
  se.init()
  se.Title = title
  se.ResourceId = resourceID
  se.StartDate = startDate
  se.EndDate = endDate
  se.Type = type
  se.ID = ID
  se.Description = description
  se.Image = image
  se.Editable = editable
  se.Color = color
  se.AllDay = allDay
  return se
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static SchedulerResource SchedulerResource.create(
  int ID                          // 
  string Name                     // 
  string Type                     // 
  optional string AvatarPath = "" // 
)
{
  SchedulerResource sr = new()
  sr.ID = ID
  sr.Name = Name
  sr.Type = Type
  sr.Avatarpath = AvatarPath
  return sr
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap SchedulerResource.toJson()
{
  IDMap idm = new()
  idm.setValue("id", ID)
  idm.setValue("avatar", Avatarpath)
  idm.setValue("text", Name)
  return idm
}


// ──────────────────────────────────

Devextreme

// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static SchedulerConfiguration SchedulerConfiguration.Create(
  optional int height = 0                  // 
  optional int width = 0                   // 
  optional IDMap editing                   // 
  optional int cellDuration = 0            // 
  optional string timezone = "Europe/Rome" // 
  optional int firstDayOfWeek = 0          // 
  optional int startDayHour = 8            // 
  optional int endDayHour = 18             // 
  optional boolean showAllDayPanel = 18    // 
  optional IDArray views                   // 
  optional string currentView = "week"     // 
  optional date time currentDate = #1899/12/30 00:00:00# // 
  optional IDArray resources               // 
  optional IDForm editEventForm            // 
)
{
  SchedulerConfiguration sc = new()
  sc.Height = height
  sc.Width = width
  sc.Editing = editing
  sc.CellDuration = cellDuration
  sc.Timezone = timezone
  sc.FirstDayOfWeek = firstDayOfWeek
  sc.StartDayHour = startDayHour
  sc.EndDayHour = endDayHour
  sc.ShowAllDayPanel = showAllDayPanel
  sc.Views = views
  sc.CurrentView = currentView
   
  if (year(currentDate) == 1899)
  {
    sc.CurrentDate = now()
  }
  else 
  {
    sc.CurrentDate = currentDate
  }
   
  sc.Resources = resources
  sc.EventDetailForm = editEventForm
  return sc
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap SchedulerConfiguration.updateSingleConfiguration(
  IDMap optionInfo // 
)
{
  IDMap resultToBeSent = optionInfo
  string optionToBeChanged = optionInfo.getValue("name")
  switch (optionToBeChanged)
  {
    case height:
      Height = optionInfo.getValue("value")
    break
    case width:
      Width = optionInfo.getValue("value")
    break
    case editing:
      Editing = (IDMap)optionInfo.getObject("value")
    break
    case cellDuration:
      CellDuration = optionInfo.getValue("value")
    break
    case views:
      Views = (IDArray)optionInfo.getObject("value")
    break
    case showAllDayPanel:
      ShowAllDayPanel = optionInfo.getValue("value")
    break
    case endDayHour:
      EndDayHour = optionInfo.getValue("value")
    break
    case startDayHour:
      StartDayHour = optionInfo.getValue("value")
    break
    case firstDayOfWeek:
      FirstDayOfWeek = optionInfo.getValue("value")
    break
    case currentDate:
      CurrentDate = optionInfo.getValue("value")
    break
    case currentView:
      CurrentView = optionInfo.getValue("value")
    break
    case timezone:
      Timezone = optionInfo.getValue("value")
    break
    case editEventForm:
      Editing = (IDMap)optionInfo.getObject("value")
    break
    case resources:
      IDArray resources = (IDArray)optionInfo.getObject("value")
      Resources = resources
      IDArray resourcesToBeSent = new()
      for (int i = 0; i < resources.length(); i = i + 1)
      {
         SchedulerResource sr = (SchedulerResource)resources.getObject(i)
         resourcesToBeSent.setObject(i, sr.toJson())
      }
       
      IDMap resourceSingleInstance = new()
      resourceSingleInstance.setValue("fieldExpr", "employeeID")
      resourceSingleInstance.setValue("allowMultiple", true)
      resourceSingleInstance.setObject("dataSource", resourcesToBeSent)
      resourceSingleInstance.setValue("label", "Employee")
       
      IDArray singleElementResourceArray = new()
      singleElementResourceArray.setObject(0, resourceSingleInstance)
      resultToBeSent.setObject("value", singleElementResourceArray)
    break
  }
   
  return resultToBeSent
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void GanttController.SetupConfiguration(
  optional GanttConfiguration configuration // 
)
{
  if (!(configuration))
  {
    this.buildBasicConfiguration()
    return 
  }
  else 
  {
    Configuration = cast(configuration)
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void GanttController.setTasks(
  IDCollection tasks of GanttTask // 
)
{
  if (tasks and tasks.count() > 0)
  {
    GanttTask = tasks
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void GanttController.buildBasicConfiguration()
{
  IDMap editingDetailed = new()
  editingDetailed.setValue("enabled", true)
  editingDetailed.setValue("allowTaskAdding", true)
  editingDetailed.setValue("allowTaskDeleting", true)
  editingDetailed.setValue("allowResourceDeleting", true)
  editingDetailed.setValue("allowResourceUpdating", true)
  editingDetailed.setValue("allowTaskResourceUpdating", true)
  editingDetailed.setValue("allowTaskUpdating", true)
  editingDetailed.setValue("allowDependencyAdding", true)
  editingDetailed.setValue("allowDependencyDeleting", true)
   
  Configuration = cast(GanttConfiguration.Create(500, 1000, editingDetailed, ...))
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDArray GanttController.getTasksAsArray()
{
  IDArray tasksComputed = new()
  for each GanttTask gt in GanttTask
  {
    tasksComputed.setObject(tasksComputed.length(), gt.GetIdMap())
  }
  return tasksComputed
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public int GanttController.getFormIndex()
{
  return FormIndex
}


// ──────────────────────────────────

// *********************************************
// Raised when the document is being initialized
// *********************************************
event GanttController.OnInit()
{
  this.buildBasicConfiguration()
}


// ──────────────────────────────────



// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static GanttTask GanttTask.create(
  int id                            // 
  int parentId                      // 
  string title                      // 
  date time start                   // 
  date time end                     // 
  optional int progress = -1        // 
  optional string color = "0"       // 
  optional string description = " " // 
)
{
  GanttTask gt = new()
  gt.init()
   
  gt.setTag(ID, id)
  gt.setTag(parentId, parentId)
  gt.setTag(title, title)
  gt.setTag(start, start)
  gt.setTag(end, end)
  gt.setTag(color, color)
  gt.setTag(description, description)
   
  if (progress == -1)
  {
    gt.setTag(progress, 100)
  }
  else 
  {
    gt.setTag(progress, progress)
  }
  return gt
}


// ──────────────────────────────────



// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static GanttConfiguration GanttConfiguration.Create(
  optional int height = 0     // 
  optional int width = 0      // 
  optional IDMap editing      // 
  optional IDMap toolbar      // 
  optional IDArray stripLines // 
  optional string scaleType = "18" // 
)
{
  GanttConfiguration ganttConfig = new()
  ganttConfig.Height = height
  ganttConfig.Width = width
  ganttConfig.Editing = editing
  ganttConfig.Toolbar = toolbar
  ganttConfig.ScaleType = scaleType
  ganttConfig.StripLines = stripLines
  return ganttConfig
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap GanttConfiguration.updateSingleConfiguration(
  IDMap optionInfo // 
)
{
  IDMap resultToBeSent = optionInfo
  string optionToBeChanged = optionInfo.getValue("name")
  switch (optionToBeChanged)
  {
    case height:
      Height = optionInfo.getValue("value")
    break
    case width:
      Width = optionInfo.getValue("value")
    break
    case editing:
      Editing = (IDMap)optionInfo.getObject("value")
    break
    case "toolbar":
      Toolbar = (IDMap)optionInfo.getObject("value")
    break
    case "stripLines":
      StripLines = (IDArray)optionInfo.getObject("value")
    break
    case "scaleType":
      ScaleType = optionInfo.getValue("value")
    break
  }
   
  return resultToBeSent
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static DiagramController DiagramController.create(
  IDForm parentForm // 
)
{
  DiagramController oc = new()
  oc.init()
  oc.storeFormIndex(parentForm)
  return oc
}


// ──────────────────────────────────



// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DiagramController.updateDiagramContent(
  DiagramContent content // 
)
{
  DiagramConfiguration dc = (DiagramConfiguration)Configuration
  dc.setContent(content)
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string DiagramController.getContent()
{
  DiagramConfiguration dc = (DiagramConfiguration)Configuration
  return dc.getDiagramContent()
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static DiagramConfiguration DiagramConfiguration.create(
  optional boolean readOnly = 0                      // 
  optional IDCollection shapes of DiagramCustomShape // 
  optional DiagramContent content                    // 
  optional DiagramMainToolbar mainToolbar            // 
  optional DiagramToolbox toolbox                    // 
  optional DiagramContextToolbox contextToolbox      // 
  optional DiagramViewToolbar viewToolbar            // 
)
{
  DiagramConfiguration oc = new()
  oc.init()
  oc.ReadOnly = readOnly
  if (shapes != null and shapes.count() > 0)
  {
    oc.setCustomShapes(shapes)
  }
  oc.setContent(content)
  oc.setMainToolbar(mainToolbar)
  oc.setToolbox(toolbox)
  oc.setContextToolbox(contextToolbox)
  oc.setViewToolbar(viewToolbar)
  return oc
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap DiagramConfiguration.toJson()
{
  IDMap configuration = new()
  configuration.setValue("diagram_name", DiagramName)
  configuration.setObject("custom_shapes", CustomShapes)
  configuration.setValue("diagram_content", DiagramContent.getContent())
  configuration.setObject("main_toolbar", MainToolbar.getConfiguration())
  configuration.setObject("toolbox", Toolbox.getConfiguration())
  configuration.setObject("context_toolbox", ContextToolbox.getConfiguration())
  configuration.setObject("view_toolbar", ViewToolbar.getConfiguration())
  return configuration
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string DiagramConfiguration.getDiagramContent()
{
  return DiagramContent.getContent()
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DiagramConfiguration.setViewToolbar(
  DiagramViewToolbar viewToolbar // 
)
{
  DiagramViewToolbar viewToolbar = viewToolbar
  if (!(viewToolbar))
  {
    viewToolbar = DiagramViewToolbar.create(true, null)
  }
  ViewToolbar = viewToolbar
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DiagramConfiguration.setContextToolbox(
  DiagramContextToolbox contextToolbox // 
)
{
  DiagramContextToolbox contextToolbox = contextToolbox
  if (!(contextToolbox))
  {
    contextToolbox = DiagramContextToolbox.create(true, "node", 5, 200)
  }
  ContextToolbox = contextToolbox
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DiagramConfiguration.setToolbox(
  DiagramToolbox toolbox // 
)
{
  DiagramToolbox toolbox = toolbox
  if (!(toolbox))
  {
    toolbox = DiagramToolbox.create("visible", false, true, 5, 220, 400)
  }
  Toolbox = toolbox
  Toolbox.CustomShapesCategories = CustomShapesCategories
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DiagramConfiguration.setMainToolbar(
  DiagramMainToolbar mainToolbarConfiguration // 
)
{
  DiagramMainToolbar mainToolbarConfiguration = mainToolbarConfiguration
  if (!(mainToolbarConfiguration))
  {
    mainToolbarConfiguration = DiagramMainToolbar.Create(true, ...)
  }
  MainToolbar = mainToolbarConfiguration
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DiagramConfiguration.setContent(
  DiagramContent content // 
)
{
  DiagramContent = content
  if (DiagramContent == null or DiagramContent.getContent() == null or DiagramContent.getContent() == "")
  {
    DiagramContent = DiagramContent.create("")
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DiagramConfiguration.setCustomShapes(
  IDCollection customShapes of DiagramCustomShape // 
)
{
  IDMap categories = new()
  CustomShapes = new()
  for each DiagramCustomShape cosb in customShapes
  {
    IDMap customShapeConfiguration = cosb.getConfiguration()
    if (customShapeConfiguration and customShapeConfiguration.length() > 0)
    {
      categories.setValue(customShapeConfiguration.getValue("category"), true)
      CustomShapes.addObject(customShapeConfiguration)
    }
  }
  CustomShapesCategories = categories.getKeys()
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap DiagramCustomShape.getConfiguration()
{
  IDMap customShapeConfiguration = new()
  this.populateConfigurationMapString(customShapeConfiguration, "type", Type)
  this.populateConfigurationMapString(customShapeConfiguration, "basetype", BaseType)
  this.populateConfigurationMapString(customShapeConfiguration, "defaultText", DefaultText)
  this.populateConfigurationMapString(customShapeConfiguration, "backgroundImageUrl", BackgroundImageUrl)
  this.populateConfigurationMapFloat(customShapeConfiguration, "backgroundImageWidth", BackgroundImageWidth)
  this.populateConfigurationMapFloat(customShapeConfiguration, "backgroundImageHeight", BackgroundImageHeight)
  this.populateConfigurationMapFloat(customShapeConfiguration, "defaultWidth", DefaultWidth)
  this.populateConfigurationMapFloat(customShapeConfiguration, "defaultHeight", DefaultHeight)
  this.populateConfigurationMapFloat(customShapeConfiguration, "textTop", TextTop)
  this.populateConfigurationMapFloat(customShapeConfiguration, "textHeight", TextHeight)
  this.populateConfigurationMapString(customShapeConfiguration, "category", Category)
  this.populateConfigurationMapBoolean(customShapeConfiguration, "allowEditText", AllowEditText)
  this.populateConfigurationMapBoolean(customShapeConfiguration, "allowResize", AllowResize)
  this.populateConfigurationMapBoolean(customShapeConfiguration, "allowEditImage", AllowEditImage)
  this.populateConfigurationMapFloat(customShapeConfiguration, "keepRatioOnAutoSize", KeepRatioOnAutoSize)
  this.populateConfigurationMapFloat(customShapeConfiguration, "maxWidth", MaxWidth)
  this.populateConfigurationMapFloat(customShapeConfiguration, "maxHeight", MaxHeight)
  this.populateConfigurationMapString(customShapeConfiguration, "defaultImageUrl", DefaultImageUrl)
  this.populateConfigurationMapFloat(customShapeConfiguration, "imageHeight", ImageHeight)
  this.populateConfigurationMapFloat(customShapeConfiguration, "defaultWidth", ImageWidth)
  this.populateConfigurationMapFloat(customShapeConfiguration, "defaultWidth", ImageTop)
  this.populateConfigurationMapFloat(customShapeConfiguration, "defaultWidth", ImageLeft)
  return customShapeConfiguration
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static DiagramCustomShape DiagramCustomShape.Create(
  string type                      // 
  string defaultText               // 
  string baseType                  // 
  string backgroundImageUrl        // 
  float backgroundImageWidth       // 
  float backgroundImageHeight      // 
  float defaultWidth               // 
  float defaultHeight              // 
  float textTop                    // 
  float textHeight                 // 
  string category                  // 
  boolean allowEditText            // 
  boolean allowResize              // 
  boolean allowEditImage           // 
  boolean keepRatioOnAutoSize      // 
  float maxWidth                   // 
  float maxHeight                  // 
  optional string defaultImageUrl = "" // 
  optional float imageWidth = 0.0  // 
  optional float imageHeight = 0.0 // 
  optional float imageTop = 0.0    // 
  optional float imageLeft = 0.0   // 
)
{
  DiagramCustomShape customOrgchartShape = new()
  customOrgchartShape.Type = type
  customOrgchartShape.BaseType = baseType
  customOrgchartShape.DefaultText = defaultText
  customOrgchartShape.BackgroundImageUrl = backgroundImageUrl
  customOrgchartShape.BackgroundImageWidth = backgroundImageWidth
  customOrgchartShape.BackgroundImageHeight = backgroundImageHeight
  customOrgchartShape.DefaultWidth = defaultWidth
  customOrgchartShape.DefaultHeight = defaultHeight
  customOrgchartShape.TextTop = textTop
  customOrgchartShape.TextHeight = textHeight
  customOrgchartShape.Category = category
  customOrgchartShape.AllowEditText = allowEditText
  customOrgchartShape.AllowResize = allowResize
  customOrgchartShape.AllowEditImage = allowEditImage
  customOrgchartShape.KeepRatioOnAutoSize = keepRatioOnAutoSize
  customOrgchartShape.MaxWidth = maxWidth
  customOrgchartShape.MaxHeight = maxHeight
  customOrgchartShape.DefaultImageUrl = defaultImageUrl
  customOrgchartShape.ImageHeight = imageHeight
  customOrgchartShape.ImageWidth = imageWidth
  customOrgchartShape.ImageTop = imageTop
  customOrgchartShape.ImageLeft = imageLeft
  return customOrgchartShape
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DiagramCustomShape.populateConfigurationMapString(
  IDMap configuration  // 
  string propertyName  // 
  string propertyValue // 
)
{
  if (propertyValue != "" and propertyValue != null)
  {
    configuration.setValue(propertyName, propertyValue)
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DiagramCustomShape.populateConfigurationMapFloat(
  IDMap configuration // 
  string propertyName // 
  float propertyValue // 
)
{
  if (propertyValue != null and propertyValue != 0)
  {
    configuration.setValue(propertyName, propertyValue)
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DiagramCustomShape.populateConfigurationMapBoolean(
  IDMap configuration   // 
  string propertyName   // 
  boolean propertyValue // 
)
{
  if (propertyValue != null)
  {
    configuration.setValue(propertyName, propertyValue)
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static DiagramContent DiagramContent.create(
  string content // 
)
{
  DiagramContent oc = new()
  oc.setContent(content)
  return oc
}


// ──────────────────────────────────



// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static DiagramMainToolbar DiagramMainToolbar.Create(
  boolean visible                 // 
  optional IDArray commands       // 
  optional IDArray customCommands // 
)
{
  DiagramMainToolbar oc = new()
  oc.Visible = visible
  if (commands and commands.length() > 0)
  {
    oc.Commands = commands
     
    // add custom commands
    if (customCommands)
    {
      for (int j = 0; j < customCommands.length(); j = j + 1)
      {
         oc.Commands.addObject(customCommands.getObject(j))
      }
    }
  }
  else 
  {
    oc.Commands = new()
     
    IDMap el1 = new()
    el1.setValue("name", "undo")
    oc.Commands.addObject(el1)
     
    IDMap el2 = new()
    el2.setValue("name", "redo")
    oc.Commands.addObject(el2)
     
    IDMap el3 = new()
    el3.setValue("name", "separator")
    oc.Commands.addObject(el3)
     
    IDMap el4 = new()
    el4.setValue("name", "fontName")
    oc.Commands.addObject(el4)
     
    IDMap el5 = new()
    el5.setValue("name", "fontSize")
    oc.Commands.addObject(el5)
     
    IDMap el6 = new()
    el6.setValue("name", "separator")
    oc.Commands.addObject(el6)
     
    IDMap el7 = new()
    el7.setValue("name", "bold")
    oc.Commands.addObject(el7)
     
    IDMap el8 = new()
    el8.setValue("name", "italic")
    oc.Commands.addObject(el8)
     
    IDMap el9 = new()
    el9.setValue("name", "underline")
    oc.Commands.addObject(el9)
     
    IDMap el10 = new()
    el10.setValue("name", "separator")
    oc.Commands.addObject(el10)
     
    IDMap el11 = new()
    el11.setValue("name", "fontColor")
    oc.Commands.addObject(el11)
     
    IDMap el12 = new()
    el12.setValue("name", "lineColor")
    oc.Commands.addObject(el12)
     
    IDMap el13 = new()
    el13.setValue("name", "fillColor")
    oc.Commands.addObject(el13)
     
    IDMap el14 = new()
    el14.setValue("name", "separator")
    oc.Commands.addObject(el14)
    //  
    // add custom commands
    if (customCommands)
    {
      for (int j = 0; j < customCommands.length(); j = j + 1)
      {
         oc.Commands.addObject(customCommands.getObject(j))
      }
    }
  }
  return oc
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap DiagramMainToolbar.getConfiguration()
{
  IDMap configuration = new()
  configuration.setValue("visible", Visible)
  configuration.setObject("commands", Commands)
  return configuration
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static DiagramToolbox DiagramToolbox.create(
  string visiblity     // 
  boolean showGeneralShapesGroup // 
  boolean showSearch   // 
  int shapeIconsPerRow // 
  float width          // 
  float height         // 
)
{
  DiagramToolbox toolbox = new()
  toolbox.Visibility = visiblity
  toolbox.ShowGeneralShapesGroup = showGeneralShapesGroup
  toolbox.ShowSearch = showSearch
  toolbox.ShapeIconsPerRow = shapeIconsPerRow
  toolbox.Width = width
  toolbox.Height = height
  return toolbox
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap DiagramToolbox.getConfiguration()
{
  IDMap configuration = new()
  configuration.setValue("visibility", Visibility)
   
  IDArray groups = new()
  if (ShowGeneralShapesGroup)
  {
    groups.addValue("general")
  }
  if (CustomShapesCategories != null)
  {
    for (int i = 0; i < CustomShapesCategories.length(); i = i + 1)
    {
      IDMap newGroup = new()
      newGroup.setValue("category", CustomShapesCategories.getValue(i))
      newGroup.setValue("title", CustomShapesCategories.getValue(i))
      groups.addObject(newGroup)
    }
  }
   
  configuration.setObject("groups", groups)
  configuration.setValue("showSearch", ShowSearch)
  configuration.setValue("shapeIconsPerRow", ShapeIconsPerRow)
  configuration.setValue("width", Width)
  configuration.setValue("height", Height)
  return configuration
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static DiagramContextToolbox DiagramContextToolbox.create(
  boolean enabled      // 
  string category      // 
  int shapeIconsPerRow // 
  float width          // 
)
{
  DiagramContextToolbox toolbox = new()
  toolbox.Enabled = enabled
  toolbox.Category = category
  toolbox.ShapeIconsPerRow = shapeIconsPerRow
  toolbox.Width = width
  return toolbox
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap DiagramContextToolbox.getConfiguration()
{
  IDMap configuration = new()
  configuration.setValue("enabled", Enabled)
  configuration.setValue("category", Category)
  configuration.setValue("shapeIconsPerRow", ShapeIconsPerRow)
  configuration.setValue("width", Width)
  return configuration
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static DiagramViewToolbar DiagramViewToolbar.create(
  boolean visible  // 
  IDArray commands // 
)
{
  DiagramViewToolbar toolbox = new()
  toolbox.Visible = visible
  if (commands and commands.length() > 0)
  {
    toolbox.Commands = commands
  }
  else 
  {
    IDArray defaultCommands = new()
    defaultCommands.addValue("zoomLevel")
    IDMap commands = new()
    commands.setValue("name", "export")
    commands.setValue("icon", "export")
    IDArray items = new()
    items.addValue("exportSvg")
    items.addValue("exportPng")
    items.addValue("exportJpg")
    commands.setObject("items", items)
    defaultCommands.addObject(commands)
    toolbox.Commands = defaultCommands
  }
  return toolbox
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap DiagramViewToolbar.getConfiguration()
{
  IDMap configuration = new()
  configuration.setValue("visible", Visible)
  configuration.setObject("commands", Commands)
  return configuration
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static DiagramShapeConfiguration DiagramShapeConfiguration.create(
  string id             // 
  string type           // 
  string category       // 
  string baseType       // 
  float defaultWidth    // 
  float defaultHeight   // 
  float toolboxWidthToHeightRatio // 
  float minWidth        // 
  float minHeight       // 
  float maxWidth        // 
  float maxHeight       // 
  boolean allowEditText // 
  string description    // 
)
{
  DiagramShapeConfiguration diagramShapeConfiguration = new()
  diagramShapeConfiguration.Id = id
  diagramShapeConfiguration.Type = type
  diagramShapeConfiguration.Category = category
  diagramShapeConfiguration.Basetype = baseType
  diagramShapeConfiguration.DefaultWidth = defaultWidth
  diagramShapeConfiguration.DefaultHeight = defaultHeight
  diagramShapeConfiguration.ToolboxWidthToHeightRatio = toolboxWidthToHeightRatio
  diagramShapeConfiguration.MinWidth = minWidth
  diagramShapeConfiguration.MinHeight = minHeight
  diagramShapeConfiguration.MaxWidth = maxWidth
  diagramShapeConfiguration.MaxHeight = maxHeight
  diagramShapeConfiguration.AllowEditText = allowEditText
  diagramShapeConfiguration.Description = description
   
  return diagramShapeConfiguration
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
private IDMap DiagramShapeConfiguration.toIdMap()
{
  IDMap shapeConfiguration = new()
  shapeConfiguration.setValue("id", Id)
  shapeConfiguration.setValue("type", Type)
  shapeConfiguration.setValue("category", Category)
  shapeConfiguration.setValue("baseType", Basetype)
  shapeConfiguration.setValue("defaultWidth", DefaultWidth)
  shapeConfiguration.setValue("defaultHeight", DefaultHeight)
  shapeConfiguration.setValue("toolboxWidthToHeightRatio", ToolboxWidthToHeightRatio)
  shapeConfiguration.setValue("minWidth", MinWidth)
  shapeConfiguration.setValue("minHeight", MinHeight)
  shapeConfiguration.setValue("maxWidth", MaxWidth)
  shapeConfiguration.setValue("maxHeight", MaxHeight)
  shapeConfiguration.setValue("allowEditText", AllowEditText)
  shapeConfiguration.setValue("description", Description)
   
  return shapeConfiguration
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string DiagramShapeConfiguration.toJson()
{
  IDMap map = this.toIdMap()
  string json = JSON.stringify(map)
  return json
}


// ──────────────────────────────────



// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap DiagramShape.getDiagramMap()
{
  IDMap diagramMap = new()
  this.PopulateDiagramMap(diagramMap, "ID", toString(ID))
  this.PopulateDiagramMap(diagramMap, "Type", Type)
  this.PopulateDiagramMap(diagramMap, "Name", Name)
  this.PopulateDiagramMap(diagramMap, "Description", Description)
  this.PopulateDiagramMap(diagramMap, "x", toString(X))
  this.PopulateDiagramMap(diagramMap, "y", toString(Y))
   
  return diagramMap
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string DiagramShape.toJson()
{
   
  IDMap map = this.toIdMap()
  string json = JSON.stringify(map)
  return json
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
private IDMap DiagramShape.toIdMap()
{
  IDMap shapeMap = new()
  shapeMap.setValue("id", ID)
  shapeMap.setValue("type", Type)
  shapeMap.setValue("name", Name)
  shapeMap.setValue("description", Description)
  shapeMap.setValue("x", X)
  shapeMap.setValue("y", Y)
  shapeMap.setValue("color", Color)
   
  return shapeMap
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static DiagramConnection DiagramConnection.create(
  int id      // 
  int fromId  // 
  int toId    // 
  string text // 
  int:connectorsStartingEndingEdge connectionStart // 
  int:connectorsStartingEndingEdge connectionEnd // 
)
{
  DiagramConnection createdConnetion = new()
   
  createdConnetion.Id = id
  createdConnetion.Fromid = fromId
  createdConnetion.Toid = toId
  createdConnetion.Text = text
  createdConnetion.FromPointIndex = connectionStart
  createdConnetion.ToPointIndex = connectionEnd
   
  return createdConnetion
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string DiagramConnection.toJson()
{
   
  IDMap map = this.toIdMap()
  string json = JSON.stringify(map)
  return json
}


// ──────────────────────────────────



// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string DiagramBackendInfo.collectionToJson(
  string:diagramElement diagramElementType // 
)
{
  string json = "["
   
  if (diagramElementType == Shape)
  {
    for each DiagramShape ds in DiagramShape
    {
       
      string currentJsonData = ds.toJson()
      json = json + if(json == "[", "", ",") + currentJsonData
       
    }
  }
  if (diagramElementType == Connection)
  {
    for each DiagramConnection dc in DiagramConnections
    {
      string currentJsonData = dc.toJson()
      json = json + if(json == "[", "", ",") + currentJsonData
       
    }
  }
  if (diagramElementType == ShapeConfiguration)
  {
    for each DiagramShapeConfiguration dsc in DiagramShapeConfiguration
    {
      string currentJsonData = dsc.toJson()
      json = json + if(json == "[", "", ",") + currentJsonData
       
    }
  }
  json = json + "]"
   
  return json
}


// ──────────────────────────────────

// **************************************************************************************
// Fake placeholder procedure to create json file that store all the shape of the diagram
// **************************************************************************************
public static string DiagramBackendInfo.GetJsonData(
  string:diagramElement diagramElementType // 
)
{
  DiagramBackendInfo dbidafare = new()
  if (diagramElementType == ShapeConfiguration)
  {
    DiagramShapeConfiguration firstShapeConfiguration = DiagramShapeConfiguration.create(docIDToGuid(newDocID()), "startStop", "step", Ellipse, 1,5
             , 1, 2, 1,5, 1, 3, 2, false, "Start / Stop")
    dbidafare.DiagramShapeConfiguration.add(firstShapeConfiguration)
     
    DiagramShapeConfiguration firstShapeConfiguration1 = DiagramShapeConfiguration.create(docIDToGuid(newDocID()), "step", "step", Rectangle, 1,5, 
             1, 2, 1,5, 1, 3, 2, false, "Step")
    dbidafare.DiagramShapeConfiguration.add(firstShapeConfiguration1)
  }
//  if (diagramElementType == Shape)
//  {
//    DiagramShape firstShape = DiagramShape.Create(1, "startStop", "Francesco", "CEO", 1, 2, "#fcba03")
//    DiagramShape secondShape = DiagramShape.Create(2, "step", "Carlo", "BEO", 4, 2, "#006b44")
//    DiagramShape thirdShape = DiagramShape.Create(3, "step", "Marco", "SEO", 8, 2, "#603c7a")
//    dbidafare.DiagramShape.add(firstShape)
//    dbidafare.DiagramShape.add(secondShape)
//    dbidafare.DiagramShape.add(thirdShape)
//  }
//  if (diagramElementType == Connection)
//  {
//    DiagramConnection firstConnection = DiagramConnection.create(116, 1, 2, "test testo", Bottom, Left)
//    DiagramConnection secondConnection = DiagramConnection.create(200, 2, 3, "secondo test", Bottom, Right)
//    DiagramConnection thirdConnection = DiagramConnection.create(202, 1, 2, "terzo test", Left, Top)
//    dbidafare.DiagramConnections.add(firstConnection)
//    dbidafare.DiagramConnections.add(secondConnection)
//    dbidafare.DiagramConnections.add(thirdConnection)
//  }
   
   
   
  string concatenatedShapeData = dbidafare.collectionToJson(diagramElementType)
  concatenatedShapeData = trim(concatenatedShapeData)
   
  return concatenatedShapeData
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDArray DiagramBackendInfo.jsonToDiagramArray()
{
  IDArray ida = new()
  ida.addValue(this.GetJsonData(Shape))
  ida.addValue(this.GetJsonData(Connection))
  return ida
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static HTMLEditorController HTMLEditorController.create(
  HTMLEditorConfiguration configuration // 
)
{
  HTMLEditorController htmlec = new()
  htmlec.init()
  htmlec.Configuration = configuration
  htmlec.updateOriginalObjectWithUpdatedValue(configuration.HtmlValue)
  return htmlec
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void HTMLEditorController.updateOriginalObjectWithUpdatedValue(
  string value // 
)
{
  Value = this.wrapHtmlFragment(value)
  if (!(HTMLEditorConfiguration.isMyInstance(Configuration)))
  {
    Devextreme.DTTLogMessage(formatMessage("Configuration is not HTMLEditorConfiguration, but it's |1", Configuration.typeName(), ...), ..., 
          DTTError)
  }
  HTMLEditorConfiguration htmlec = (HTMLEditorConfiguration)Configuration
  IDDocument doc = cast(htmlec.Origin)
  doc.setProperty(htmlec.HtmlPropertyIndex, Value)
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string HTMLEditorController.getHtmlValue()
{
  return Value
}


// ──────────────────────────────────

// *****************************************************************
//  Wraps HTML fragment in a full document shell so external
// consumers (e.g. Delphi TDBRichViewEdit with FieldFormat=rvdbHTML)
// can detect and parse it as HTML.
// Important: already-wrapped content is returned unchanged.
// *****************************************************************
public string HTMLEditorController.wrapHtmlFragment(
  string html // 
)
{
  string result = ""
  if (isNull(html) or length(html) == 0)
  {
    return html
  }
  string lowerTrimmedHtml = lower(trim(html))
  boolean startsWithHtmlTag = mid(lowerTrimmedHtml, 1, 5) == "<html"
  boolean startsWithDocType = mid(lowerTrimmedHtml, 1, 9) == "<!doctype"
  if (startsWithHtmlTag or startsWithDocType)
  {
    return html
  }
  result = formatMessage("<html><head><meta http-equiv=\\"Content-Type\\" content=\\"text/html; charset=utf-8\\"></head><body>|1</body></html>", 
           html, ...)
  return result
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static HTMLEditorConfiguration HTMLEditorConfiguration.create(
  int height            // 
  IDDocument origin     // 
  int htmlPropertyIndex // 
  boolean readOnly      // 
)
{
  HTMLEditorConfiguration configuration = new()
  configuration.init()
  configuration.Height = height
  configuration.ReadOnly = readOnly
  configuration.Origin = (IDDocument)origin
  configuration.HtmlPropertyIndex = htmlPropertyIndex
  configuration.HtmlValue = configuration.Origin.getProperty(htmlPropertyIndex)
  return configuration
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap HTMLEditorConfiguration.toJson()
{
  IDMap configuration = new()
  configuration.setValue("height", Height)
  configuration.setValue("value", HtmlValue)
  configuration.setValue("readOnly", ReadOnly)
   
  return configuration
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DGController.computeColumns(
  IDDocument source // 
)
{
  IDArray columns = new()
  IDDocumentStructure idds = source.getStructure()
  int propertyCount = idds.getPropertyCount()
  for (int i = 1; i <= propertyCount; i = i + 1)
  {
    IDPropertyDefinition idpd = idds.getPropertyDefinition(i)
    string propertyCaption = idpd.UIName
    string propertyDataField = idpd.UIName
    columns.setValue(i, propertyDataField)
     
    // handle somehow the visibility and filters
    DGColumn dc = DGColumn.create(propertyCaption, propertyDataField, i, true, true)
    DataColumn.add(dc)
  }
  Columns = columns
}


// ──────────────────────────────────

// *********************************************************************************
// this procedure returns the configuration IDMap to configure the DataGrid instance
// *********************************************************************************
public IDMap DGController.getConfiguration()
{
  IDMap data = new()
  IDMap idm = new()
  IDArray columns = this.getColumns()
  IDMap editing = this.getEditing()
  IDMap filters = this.getFilters()
  idm.setObject("columns", columns)
  idm.setObject("editing", editing)
  idm.setObject("datasource", Datasource)
  idm.setObject("filters", filters)
  idm.setValue("DivID", ComponentDivID)
  data.setObject("data", idm)
   
  return data
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static DGController DGController.create(
  IDCollection data of IDDocument // 
)
{
  DGController dc = new()
  if (data.count() > 0)
  {
    data.moveFirst()
    IDDocument doc = (IDDocument)data.getAt()
    dc.computeColumns(doc)
    dc.SetDataSource(data)
    dc.generateDivIDForDxDataGrid()
  }
  return dc
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DGController.SetDataSource(
  IDCollection dataSource of IDDocument // 
)
{
  IDArray datasource = new()
  int i = 0
  for each IDDocument doc in dataSource
  {
    // current data should be substitute with class
    IDMap currentData = new()
    for each DGColumn dc in DataColumn
    {
      string propertyCode = dc.getDataField()
      int indexCurrentColumn = doc.getPropertyIndex(propertyCode, true, true, true, true)
      currentData.setValue(propertyCode, doc.getProperty(indexCurrentColumn))
    }
    datasource.setObject(i, currentData)
    i = i + 1
  }
   
   
  Datasource = datasource
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDArray DGController.getColumns()
{
  IDArray columns = new()
  if (DataColumn.count() > 1)
  {
    int sequenceIndex = DGColumn.getSequenceIndex()
    DataColumn.addSortCriteria(sequenceIndex)
    DataColumn.doSort()
    for each DGColumn dc in DataColumn
    {
      int arrayPosition = columns.length()
      IDMap columnConfiguration = dc.getConfiguration()
      columns.setObject(arrayPosition, columnConfiguration)
    }
  }
  return columns
}


// ──────────────────────────────────



// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DGController.setEditingOptions(
  string mode           // 
  boolean allowUpdating // 
  boolean allowDeleting // 
  boolean allowAdding   // 
)
{
  DGEditingOptions = DGEditingOptions.create(mode, allowUpdating, allowDeleting, allowAdding)
}


// ──────────────────────────────────



// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap DGController.getFilters()
{
  return DGFilteringOptions.getConfiguration()
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DGController.setFieldEditable(
  string filterName // 
  boolean editable  // 
)
{
  for each DGColumn dgc in DataColumn
  {
    if (dgc.getDataField() == filterName)
    {
      dgc.setAllowEditing(editable)
      return 
    }
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DGController.generateDivIDForDxDataGrid()
{
  ComponentDivID = left(docIDToGuid(newDocID()), 5) + "_dxDataGrid"
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static DGColumn DGColumn.create(
  string caption   // 
  string dataField // 
  int sequence     // 
  boolean visibile // 
  boolean allowFiltering // 
)
{
  DGColumn column = new()
  column.init()
  column.setCaption(caption)
  column.setDataField(dataField)
  column.setSequence(sequence)
  column.setVisible(visibile)
  column.setAllowFiltering(allowFiltering)
  return column
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static int DGColumn.getSequenceIndex()
{
  DGColumn dummy = new()
  return dummy.getPropertyIndex("SEQUENCE", true, true, true, true)
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap DGColumn.getConfiguration()
{
  IDMap columnConfig = new()
  columnConfig.setValue("caption", Caption)
  columnConfig.setValue("visible", Visible)
  columnConfig.setValue("dataField", DataField)
  columnConfig.setValue("allowFiltering", AllowFiltering)
  columnConfig.setValue("allowEditing", AllowEditing)
  return columnConfig
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string DGColumn.getDataField()
{
  return DataField
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DGColumn.setDataField(
  string dataField // 
)
{
  DataField = dataField
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DGColumn.setSequence(
  int sequence // 
)
{
  Sequence = sequence
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public int DGColumn.getSequence()
{
  return Sequence
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string DGColumn.getCaption()
{
  return Caption
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public boolean DGColumn.getVisible()
{
  return Visible
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DGColumn.setVisible(
  boolean visible // 
)
{
  Visible = visible
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DGColumn.setCaption(
  string caption // 
)
{
  Caption = caption
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DGColumn.setAllowFiltering(
  boolean allowFiltering // 
)
{
  AllowFiltering = allowFiltering
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public boolean DGColumn.getAllowFiltering()
{
  return AllowFiltering
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void DGColumn.setAllowEditing(
  boolean allowEditing // 
)
{
  AllowEditing = allowEditing
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public boolean DGColumn.getAllowEditing()
{
  return AllowEditing
}


// ──────────────────────────────────

// *********************************************
// Raised when the document is being initialized
// *********************************************
event DGColumn.OnInit()
{
  Caption = ""
  Visible = true
  Sequence = 0
  AllowEditing = true
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static DGEditingOptions DGEditingOptions.create(
  string mode           // 
  boolean allowUpdating // 
  boolean allowDeleting // 
  boolean allowSaving   // 
)
{
  DGEditingOptions dgo = new()
  dgo.Mode = mode
  dgo.AllowUpdating = allowUpdating
  dgo.AllowDeleting = allowDeleting
  dgo.AllowAdding = allowSaving
  return dgo
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap DGEditingOptions.GetConfiguration()
{
  IDMap editing = new()
  editing.setValue("mode", Mode)
  editing.setValue("allowUpdating", AllowUpdating)
  editing.setValue("allowDeleting", AllowDeleting)
  editing.setValue("allowAdding", AllowAdding)
   
  // defaults
  editing.setValue("allowHiding", true)
  return editing
}


// ──────────────────────────────────

// *********************************************
// return the content formatted for the wrapper 
// *********************************************
public IDMap DGFilteringOptions.getConfiguration()
{
  IDMap filtering = new()
   
  // filtering row
  IDMap filteringRow = new()
  filteringRow.setValue("visible", FilteringRow)
  filtering.setObject("filterRow", filteringRow)
   
   
  // filter on header
  IDMap filterOnHeader = new()
  filterOnHeader.setValue("visible", HeaderFilter)
  filtering.setObject("headerFilter", filterOnHeader)
   
   
  // advanced Filter
  IDMap advancedFilter = new()
  advancedFilter.setValue("visible", FilterPanel)
  filtering.setObject("filterPanel", advancedFilter)
   
  return filtering
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static DGFilteringOptions DGFilteringOptions.create(
  boolean filterOnRow    // 
  boolean filterOnHeader // 
  boolean advancedFilter // 
)
{
  DGFilteringOptions filteringOptions = new()
  filteringOptions.FilteringRow = filterOnRow
  filteringOptions.HeaderFilter = filterOnHeader
  filteringOptions.FilterPanel = advancedFilter
  return filteringOptions
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public IDMap DGConfiguration.getConfiguration()
{
  return null
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static PieChartDataController PieChartDataController.create()
{
  PieChartDataController controller = new()
  controller.init()
  return controller
}


// ──────────────────────────────────

// **************************************************************************************************************************************************
// this procedure computes the fields and the data set in the PivotController into 2 arrays in the properties "fields" and "store" - according to the
// documentation of DevExtreme
// **************************************************************************************************************************************************
public IDMap PieChartDataController.getConfiguratioin()
{
  IDMap configuration = new()
   
  // prepare data IDMAP
  IDArray dataConfig = new()
   
  int i = 0
  for each PieChartData pcd in Data
  {
    IDMap data = new()
    data.setValue("name", pcd.getTag("name"))
    data.setValue("amount", pcd.getTag("amount"))
    dataConfig.setObject(i, data)
    i = i + 1
  }
   
  configuration.setObject("data", dataConfig)
  configuration.setValue("divToUse", right(docIDToGuid(newDocID()), 5))
  configuration.setValue("title", this.getTitle())
  Div = configuration.getValue("divToUse")
  configuration.setValue("width", this.getWidth())
  configuration.setValue("height", this.getHeight())
  return configuration
}


// ──────────────────────────────────



// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string PieChartDataController.getTitle()
{
  if (PieChartTitle == "")
  {
    PieChartTitle = "GRAFICO"
  }
  return PieChartTitle
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void PieChartDataController.setTitle(
  string title // 
)
{
  PieChartTitle = title
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void PieChartDataController.setHeight(
  int height // 
)
{
  Height = height
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void PieChartDataController.setWidth(
  int width // 
)
{
  Width = width
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public int PieChartDataController.getHeight()
{
  if (!(Height))
  {
    Height = 500
  }
  return Height
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public int PieChartDataController.getWidth()
{
  if (!(Width))
  {
    Width = 500
  }
  return Width
}


// ──────────────────────────────────

// *********************************************
// Raised when the document is being initialized
// *********************************************
event PieChartDataController.OnInit()
{
  Data.clear()
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static PieChartData PieChartData.Create(
  string name // 
  int amount  // 
)
{
  PieChartData pcd = new()
  pcd.setTag("name", name)
  pcd.setTag("amount", amount)
  return pcd
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static PivotDataController PivotDataController.create()
{
  PivotDataController controller = new()
  controller.init()
  return controller
}


// ──────────────────────────────────

// **************************************************************************************************************************************************
// this procedure computes the fields and the data set in the PivotController into 2 arrays in the properties "fields" and "store" - according to the
// documentation of DevExtreme
// **************************************************************************************************************************************************
public IDMap PivotDataController.getConfiguratioin()
{
  IDMap configuration = new()
   
  // prepare data IDMAP
  IDMap dataConfig = this.getData()
   
  configuration.setObject("data", dataConfig)
  if (!(HideChart))
  {
    HideChart = false
  }
   
  if (!(HidePivot))
  {
    HidePivot = false
  }
  configuration.setValue("onlyPivot", HideChart)
  configuration.setValue("onlyChart", HidePivot)
  string chartSettings = this.computeChartScript()
  configuration.setValue("chartScript", chartSettings)
  configuration.setValue("divToUse", right(docIDToGuid(newDocID()), 5))
  configuration.setValue("allowFiltering", this.getAllowFiltering())
  Div = configuration.getValue("divToUse")
  return configuration
}


// ──────────────────────────────────

// ********************************
// Example of the IDMAP to be set: 
// {
//     caption: 'Region',
//     width: 120,
//     dataField: 'region',
//     area: 'row',
//     sortBySummaryField: 'Total',
// }
// ********************************
public void PivotDataController.addField(
  optional string caption = ""       // 
  optional int width = 0 // 
  optional string datafield = ""     // 
  optional string area = ""          // 
  optional string SortBySummaryField = "" // 
  optional string dataType = ""      // 
  optional string groupName = ""     // 
  optional string groupInterval = "" // 
  optional boolean visible = 0       // 
  optional string summaryType = ""   // 
  optional string format = ""        // 
)
{
  PivotField fieldConfig = new()
  fieldConfig.init()
  fieldConfig.Field.setValue("caption", caption)
  fieldConfig.Field.setValue("width", width)
  fieldConfig.Field.setValue("dataField", datafield)
  fieldConfig.Field.setValue("area", area)
  fieldConfig.Field.setValue("sortBySummaryField", SortBySummaryField)
  fieldConfig.Field.setValue("dataType", dataType)
  fieldConfig.Field.setValue("groupName", groupName)
  fieldConfig.Field.setValue("groupInterval", groupInterval)
  fieldConfig.Field.setValue("visible", visible)
  fieldConfig.Field.setValue("summaryType", summaryType)
  fieldConfig.Field.setValue("format", format)
  Fields.add(fieldConfig)
  return 
}


// ──────────────────────────────────

// ********************************
// Example of the IDMAP to be set: 
// {
//     caption: 'Region',
//     width: 120,
//     dataField: 'region',
//     area: 'row',
//     sortBySummaryField: 'Total',
// }
// ********************************
public void PivotDataController.addData(
  IDMap data // 
)
{
  PivotStore ps = PivotStore.create(data)
  Data.add(ps)
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void PivotDataController.setData(
  IDCollection data of IDDocument      // 
  int indexPropRow                     // 
  string:pivotDataTypes dataTypeRow    // 
  string rowName                       // 
  int indexPropColumn                  // 
  string:pivotDataTypes dataTypeColumn // 
  string columnName                    // 
  int indexData                        // 
  string dataName                      // 
)
{
  if (data != null and data.count() > 0)
  {
    // create fields
     
    this.addField(columnName, 50, columnName, column, ..., dataTypeColumn, true)
    this.addField(rowName, 50, rowName, row, ..., dataTypeRow, true)
     
    for each IDDocument doc in data
    {
       
       
       
      IDMap data = null
    }
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
private IDMap PivotDataController.getData()
{
  IDMap dataConfig = new() // prepare data IDMAP
   
   
  // prepare Fields and Store Objs
  IDArray fieldsA = new()
  int fieldsIndex = 0
  for each PivotField pf in Fields
  {
    fieldsA.setObject(fieldsIndex, pf.Field)
    fieldsIndex = fieldsIndex + 1
  }
  dataConfig.setObject("fields", fieldsA)
   
  IDArray dataA = new()
  int dataIndex = 0
  for each PivotStore pd in Data
  {
    dataA.setObject(dataIndex, pd.Data)
    dataIndex = dataIndex + 1
  }
  dataConfig.setObject("store", dataA)
  return dataConfig
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void PivotDataController.SetHideChart(
  boolean value // 
)
{
  HideChart = value
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string PivotDataController.computeChartScript()
{
  string chartComponent = this.getChartComponent()
  string chartConfiguration = this.getChartConfiguration()
  Chartscript = formatMessage("$(chartDiv).|1(|2);this.chart=$(chartDiv).|1("instance");", chartComponent, chartConfiguration, ...)
  return Chartscript
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void PivotDataController.setChartComponent(
  string typeOfChart // 
)
{
  ChartComponent = typeOfChart
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string PivotDataController.getChartComponent()
{
  if (ChartComponent == "" or ChartComponent == null)
  {
    ChartComponent = "dxChart"
  }
  return ChartComponent
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string PivotDataController.getChartConfiguration()
{
  if (ChartComponent == "dxChart")
  {
    string chartType = this.getChartType()
    string chartTitle = this.getTitle()
     
    // argument Axis
    string argumentAxisPart = ""
    boolean addArgumentAxis = ArgumentAxis and ArgumentAxis.length() > 0
    if (addArgumentAxis == true)
    {
      string argumentAxisContent = ""
      argumentAxisContent = JSON.stringify(ArgumentAxis)
      argumentAxisPart = formatMessage("argumentAxis: |1,", argumentAxisContent, ...)
    }
     
    // palette
    string palette = if(Palette != "", formatMessage("palette: '|1',", Palette, ...), "")
    string paletteExtensionMode = if(PaletteExtensionMode != "", formatMessage("paletteExtensionMode: '|1',", PaletteExtensionMode, ...), "")
    palette = palette + paletteExtensionMode
     
    // legend
     
    string legend = ""
    if (Legend and Legend.length() > 0)
    {
      legend = formatMessage("legend: |1,", JSON.stringify(Legend), ...)
    }
     
     
    // fomrat:false is needed to show the number as it is, without using formatting such as ##0.##
    Chartconfiguration = formatMessage("{commonSeriesSettings:{type:'|1'},title:|2,tooltip:{enabled:true,format:false},size:{height:200},export:{­
             enabled:true,printingEnabled:true,},adaptiveLayout:{width:450},|3|4|5onInitialized:function(e){var pivotGridInstance=$(pivotdiv).
             dxPivotGrid("instance");pivotGridInstance.bindChart(chartDiv);}}", chartType, chartTitle, argumentAxisPart, palette, legend)
     
  }
  else if (ChartComponent == "dxPieChart")
  {
    // dxPieChart not supported yet
    Chartconfiguration = ""
  }
  return Chartconfiguration
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void PivotDataController.setChartConfiguration(
  string chartConfig // 
)
{
  Chartconfiguration = chartConfig
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void PivotDataController.setChartType(
  string:chartTypes chartType // 
)
{
  ChartType = chartType
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string PivotDataController.getChartType()
{
  if (ChartType == "")
  {
    ChartType = line
  }
  return ChartType
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string PivotDataController.getTitle()
{
  if (ChartTitle == "")
  {
    ChartTitle = "{font:{color:"black",},text:'GRAFICO',}"
  }
  return ChartTitle
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void PivotDataController.setTitle(
  IDMap titleMap // 
)
{
  ChartTitle = JSON.stringify(titleMap)
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void PivotDataController.sethidePivot(
  boolean value // 
)
{
  HidePivot = value
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public boolean PivotDataController.GetHidePivot()
{
  return HidePivot
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string PivotDataController.getPivotDivID()
{
  string pivotDivID = formatMessage("|1|2", Div, "Pivot", ...)
  return pivotDivID
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public boolean PivotDataController.GetHideChart()
{
  return HideChart
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public string PivotDataController.getChartDivID()
{
  string chartDivID = formatMessage("|1|2", Div, "Chart", ...)
  return chartDivID
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public boolean PivotDataController.getAllowFiltering()
{
  return AllowFiltering
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void PivotDataController.setAllowFiltering(
  boolean allowFiltering // 
)
{
  AllowFiltering = allowFiltering
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void PivotDataController.setArgumentAxis(
  IDMap argumentAxis // 
)
{
  ArgumentAxis = argumentAxis
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void PivotDataController.setPalette(
  string palette              // 
  string paletteExtensionMode // 
)
{
  Palette = palette
  PaletteExtensionMode = paletteExtensionMode
}


// ──────────────────────────────────



// ──────────────────────────────────

// *********************************************
// Raised when the document is being initialized
// *********************************************
event PivotDataController.OnInit()
{
  Data.clear()
  Fields.clear()
}


// ──────────────────────────────────

// ********************************
// Example of the IDMAP to be set: 
// {
//     caption: 'Region',
//     width: 120,
//     dataField: 'region',
//     area: 'row',
//     sortBySummaryField: 'Total',
// }
// ********************************
public static PivotField PivotField.create(
  optional string caption = ""       // 
  optional int width = 0 // 
  optional string datafield = ""     // 
  optional string area = ""          // 
  optional string SortBySummaryField = "" // 
  optional string dataType = ""      // 
  optional string groupName = ""     // 
  optional string groupInterval = "" // 
  optional boolean visible = 0       // 
  optional string summaryType = ""   // 
  optional string format = ""        // 
)
{
  PivotField fieldsConfig = new()
  fieldsConfig.init()
  fieldsConfig.Field = new()
  fieldsConfig.Field.setValue("caption", caption)
  fieldsConfig.Field.setValue("width", width)
  fieldsConfig.Field.setValue("dataField", datafield)
  fieldsConfig.Field.setValue("area", area)
  fieldsConfig.Field.setValue("sortBySummaryField", SortBySummaryField)
  fieldsConfig.Field.setValue("dataType", dataType)
  fieldsConfig.Field.setValue("groupName", groupName)
  fieldsConfig.Field.setValue("groupInterval", groupInterval)
  fieldsConfig.Field.setValue("visible", visible)
  fieldsConfig.Field.setValue("summaryType", summaryType)
  fieldsConfig.Field.setValue("format", format)
  return fieldsConfig
}


// ──────────────────────────────────

// *********************************************
// Raised when the document is being initialized
// *********************************************
event PivotField.OnInit()
{
  Field = new()
  Field.clear()
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public static PivotStore PivotStore.create(
  IDMap dataToBeSet // 
)
{
  PivotStore ps = new()
  ps.Data = dataToBeSet
  return ps
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void RD3CalendarController.SetupConfiguration(
  optional IDMap configuration // 
)
{
  if (!(configuration))
  {
    this.buildBasicConfiguration()
    return 
  }
   
   
  IDArray ida = configuration.getKeys()
  for (int i = 0; i < ida.length(); i = i + 1)
  {
    string key = ida.getValue(i)
     
    switch (key)
    {
      case value:
         IDMap currentDate = new()
         currentDate.setValue("name", value)
         currentDate.setValue("value", configuration.getValue(value))
      break
      case firstDayOfWeek:
         IDMap currentView = new()
         currentView.setValue("name", firstDayOfWeek)
         currentView.setValue("value", configuration.getValue(firstDayOfWeek))
      break
      case min:
         IDMap firstDayOfWeek = new()
         firstDayOfWeek.setValue("name", min)
         firstDayOfWeek.setValue("value", configuration.getValue(min))
      break
      case max:
         IDMap startDayHour = new()
         startDayHour.setValue("name", max)
         startDayHour.setValue("value", configuration.getValue(max))
      break
      case zoomLevel:
         IDMap endDayHour = new()
         endDayHour.setValue("name", zoomLevel)
         endDayHour.setValue("value", configuration.getValue(zoomLevel))
      break
      case minZoomLevel:
         IDMap showAllDaypanel = new()
         showAllDaypanel.setValue("name", minZoomLevel)
         showAllDaypanel.setValue("value", configuration.getValue(minZoomLevel))
      break
      case maxZoomLevel:
         IDMap showAllDaypanel = new()
         showAllDaypanel.setValue("name", maxZoomLevel)
         showAllDaypanel.setValue("value", configuration.getValue(maxZoomLevel))
      break
      case height:
         IDMap heightOption = new()
         heightOption.setValue("name", height)
         heightOption.setValue("value", configuration.getValue(height))
      break
      case width:
         IDMap widthOption = new()
         widthOption.setValue("name", width)
         widthOption.setValue("value", configuration.getValue(width))
      break
    }
  }
}


// ──────────────────────────────────

// ****************************************
// Describe what this procedure is used for
// ****************************************
public void RD3CalendarController.buildBasicConfiguration()
{
   
  IDMap currentView = new()
  currentView.setValue("name", zoomLevel)
  currentView.setValue("value", "month")
   
  IDMap currentDate = new()
  currentDate.setValue("name", value)
  currentDate.setValue("value", now())
   
  IDMap firstDayOfWeek = new()
  firstDayOfWeek.setValue("name", firstDayOfWeek)
  firstDayOfWeek.setValue("value", 1)
   
  IDMap startDayHour = new()
  startDayHour.setValue("name", minZoomLevel)
  startDayHour.setValue("value", "month")
   
  IDMap endDayHour = new()
  endDayHour.setValue("name", maxZoomLevel)
  endDayHour.setValue("value", "century")
   
  IDMap showAllDaypanel = new()
  showAllDaypanel.setValue("name", height)
  showAllDaypanel.setValue("value", 400)
   
  IDMap currentOption = new()
  currentOption.setValue("name", width)
  currentOption.setValue("value", 400)
}


// ──────────────────────────────────

// *********************************************
// Raised when the document is being initialized
// *********************************************
event RD3CalendarController.OnInit()
{
  this.buildBasicConfiguration()
}
