Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    string method representation in Javascript

    I have a string function that starts like this:

    Code:
    Log.setPriority("Log", 5);
    Log.logDebug("****working servlet version*** MeetingForm.CreateAgendaButton.Click");
    
        var form = MeetingForm;
    This was pasted into VisualBuilder on a button event. When I look at the code generated, it has been transformed into this.
    Code:
    "Log.setPriority(\"Log\", 5);\nLog.logDebug(\"****working servlet version*** MeetingForm.CreateAgendaButton.Click\");\n\n    var form = MeetingForm;\n\n
    This seems to work well. However, I have outgrown VB and need to maintain the original method JavaScript versions that have carriage returns, et cetera.

    Can you tell me how to transform my JavaScript into the syntax required for string methods?

    Thanks very much,

    Rick

    P.S. I am running SmartClient_v82p_2013-08-08/EVAL Development Only on Mozilla Firefox 20.0 with Firebug using Windows 7 Premium 64 bit.

    #2
    Not sure if we entirely follow this question, but a stringMethod can be defined as either a string of script to execute or a method.

    So if we took TileGrid.recordClick as an example, you could have JS like this:


    STRING
    Code:
    myTileGrid.recordClick = "if (record == null) alert(\"null!\");\n else alert(record.name);"
    or
    FUNCTION
    Code:
    myTileGrid.recordClick = function(viewer,tile,record) {
        if (record == null) alert("null");
        else alert(record.name);
    }
    Does that help?

    Thanks
    Isomorphic Software

    Comment


      #3
      Good. Good. I think I need to widen the scope of what I am doing.

      I am defining what I want to have happen on an event when I create the form.
      Code:
      isc.DynamicForm.create({
          ID:"MeetingForm",
          autoDraw:false,
          dataSource:"MeetingType",
          numCols:10,
          overflow:"hidden",
          fields:[
              {
                  name:"CreateAgendaButton",
                  title:"CREATE AGENDA",
                  align:"center",
                  colSpan:1,
                  startRow:false,
                  endRow:false,
                  click:"Log.setPriority(\"Log\", 5);\nLog.logDebug(\"****working servlet version*** ... );",
                  _constructor:"ButtonItem"
      I tried to put the method in a function defined up in front of the form creation.
      Code:
      function MeetingForm_CreateAgendaButton_Click(form){
      	Log.setPriority("Log", 5);
      	Log.logDebug("****working servlet version*** 
              ... }
      And, call it from the string method.
      Code:
              {
                  name:"CreateAgendaButton",
                  title:"CREATE AGENDA",
                  align:"center",
                  colSpan:1,
                  startRow:false,
                  endRow:false,
                  click: "MeetingForm_CreateAgendaButton_Click(this);",
                  _constructor:"ButtonItem"
              },
      This is not yet working. But, I have not tried all the combinations yet. The difficulty, I think, is that the context of the string method is different that the context of the HTML Javascript.

      I am currently having problems getting RPCManager to work. Here is the call.
      Code:
      isc.RPCManager.sendRequest({
      		httpMethod: "POST",
      		actionURL: 	String("/servlet/" + form.getValue("AgendaServletName")),
      		params: {   meetingDate:        meetingDate,
      					meetingTime:        meetingTime,
      					timeZoneOffset:     timeZoneOffset,
      					emailsKey:          String(emailsKey),
      					meetingTypeID:      String(Application.currentMeetingTypeID),
      					agendaPrintOptions: String(form.getValue("AgendaPrintOptions"))
      			},
      		downloadResult: true,
      		downloadToNewWindow:false,
      		useSimpleHttp: true
      	});
      This code works in the string method, but not when I wrap it in a function.

      I am not sure yet of the exact syntax of defining a function after "click:". Is the context of such a function the same as code defined as a string?

      In this example, this is the only event that uses this function. However, I can see in my code that some of the simpler functions are generic. And, I would like to define it only once in my code, and reference it multiple times.

      Thanks,

      Rick

      Comment


        #4
        When you pass "this" to your MeetingForm_CreateAgendaButton_Click function you are passing a ButtonItem. You've named the parameter "form" so you probably intended to pass a form instead. If you look at the definition of ButtonItem.click (same as FormItem.click) you'll see that the form is passed as a parameter, so changing "this" to "form" would probably correct your issue.

        There's no special syntax for inline functions, it's just JavaScript.

        Code:
        {
            _constructor:"ButtonItem",
            click : function (form, item) { .. },
            title:"CREATE AGENDA",
            ...

        Comment


          #5
          SPECTACULAR!

          I took the arguments off the function call and reference it from a string method. Works great. All the global variables are found without problem.
          Code:
                  {
                      name:"CreateAgendaButton",
                      title:"CREATE AGENDA",
                      align:"center",
                      colSpan:1,
                      startRow:false,
                      endRow:false,
                      click: "MeetingForm_CreateAgendaButton_Click();",
                      _constructor:"ButtonItem"
                  },
          So, now I can move forward with my program of embedding my string functions in the Javascript files. Right now they live in separate little files. I found an M4 preprocessor I can use to 'include' them in the right places.

          Thanks very much for your help.

          Rick

          Comment

          Working...
          X