For an Explicit Panel that uses a widget, is there a reason the Widget API can't be used to complete an ajax POST?

I am implementing an Explicit Panel, and I was having trouble with using a velocity file as a json url POST endpoint which typically works fine on other pages and provides results from the widget api. When posting from Panels, is it required to use the REST Api when using Panels? if so, why?

Velocity code that is not working as expected in "CoriaMapManPanel.vm":

#if ($core_v2_page.IsPost)
$core_v2_page.SetContentType('application/json')
#set($options = "%{}")               
#set ($id = $core_v2_utility.ParseInt($core_v2_page.GetFormValue('id')))
#set ($name = $core_v2_page.GetFormValue('name'))
#set ($description = $core_v2_page.GetFormValue('description'))
#set ($urlSafeName = $core_v2_page.GetFormValue('urlSafeName'))
#set ($thumbnailUrl = $core_v2_page.GetFormValue('thumbnailUrl'))
 
#set ($isIndexed = $core_v2_utility.ParseBool($core_v2_page.GetFormValue('isIndexed')))
#set ($group = $core_v2_utility.ParseInt($core_v2_page.GetFormValue('groupId')))
#set ($mapOptions = $core_v2_page.GetFormValue('mapOptions'))
#set ($mapTypeId = $core_v2_utility.ParseGuid($core_v2_page.GetFormValue('mapTypeId')))
#set ($mapGuid = $core_v2_utility.ParseGuid($core_v2_page.GetFormValue('mapGuid')))
#set ($createdByUser = $core_v2_page.GetFormValue('createdByUser'))
#set ($modifiedByUser = $core_v2_page.GetFormValue('modifiedByUser'))
#set ($createdUtcDate = $core_v2_utility.ParseDate($core_v2_page.GetFormValue('createdUtcDate')))
#set ($modifiedUtcDate = $core_v2_utility.ParseDate($core_v2_page.GetFormValue('modifiedUtcDate')))

$options.Add('Id',$id)
$options.Add('Name', $name)
$options.Add('Description', $description)
$options.Add('isIndexed', $isIndexed)
$options.Add('group', $group)
$options.Add('mapOptions',$mapOptions)
$options.Add('mapTypeId',$mapTypeId)
$options.Add('mapGuid',$mapGuid)
$options.Add('createdByUser',$createdByUser)
$options.Add('modifiedByUser',$modifiedByUser)
$options.Add('createdUtcDate',$createdUtcDate)
$options.Add('modifiedUtcDate', $modifiedUtcDate)

 
 
#set($response = $context.Update($options))
#if($response.HasErrors())
$core_v2_page.SendJsonError($response.Errors)
#end

#set ($map = $coria_v1_map.Get("%{Id = $id}"))

{"success":true, "redirectUrl":"$map.Url"}
 
#end 

Here is the ajax post that uses it, which has an empty string for the "updateUrl" variable:

/**update is error out because the "context.updateUrl" is "" */
update: function (context, options) {
            return $.telligent.evolution.post({
                url: context.updateUrl,
                dataType: 'json',
                data: options,
                async: true
            });
        },

UpdateUrl is defined as below:

updateUrl : '$core_v2_encoding.JavascriptEncode($core_v2_widget.ExecuteFile('CoriaMapManPanel.vm'))'

so this snippet is called when the panel is loaded, and here is the javascript that the above is embedded in:

<script type="text/javascript">
jQuery(document).ready(function(j){
        j.coria.map.panel.ui.register({
            saveTemplateId : "saveTemplateId",
            fieldItemTemplateId: "fieldItemTemplateId",
            fieldInputListId: '#$core_v2_encoding.JavascriptEncode($fieldInputListId)',
            /**here is the updateUrl that is returned**/
            updateUrl      : '$core_v2_encoding.JavascriptEncode($core_v2_widget.ExecuteFile('CoriaMapManPanel.vm'))',
            redirect       : #if ($redirect) true #else false #end,
            groupRedirect  : '$core_v2_encoding.JavaScriptEncode($core_v2_page.AbsoluteUrl($core_v2_groupUrls.Group($context.MapBook.Group.Id)))',
		        groupId        : '$mapbook.Group.Id',
		        mapbookId      : '$mapbook.ObjectId',
		        applicationKey : '$mapbook.SafeName',
		        groupName      : '$mapbook.Group.Name',
                mapObjectId    : '$map.MapId',


This "$core_v2_page.IsPost" is false. so, maybe I am using this incorrectly...

 

Parents Reply Children
  • oh.. I got it working. I had changed the object type of an IDictionary object into a NameValueCollection which will cause the issue, below code is in the WidgetAPI that caused the problem... corrected it. but thanks...

       [Documentation("Update an existing map.")]
            public PublicApi.Map Update(
                [Documentation("The identifier of the map to update.")]
                Guid Id,
                [
                    Documentation(Name="Description", Type=typeof(string), Description="The description of the map."),
                    Documentation(Name = "Name", Type = typeof(string), Description = "The name of the map.")]
                IDictionary options)
            
            {
                 
    
                return PublicApi.Maps.Update(Id, options);
            }