如何使用 Anguilla JavaScript 设置 Tridion ApplicationData? [英] How to set Tridion ApplicationData using Anguilla JavaScript?

查看:18
本文介绍了如何使用 Anguilla JavaScript 设置 Tridion ApplicationData?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有表单和文本字段的 Tab GUI 扩展.我想将表单字段的值保存到 ApplicatioData.我正在考虑调用 Anguilla 方法的更新"按钮.

I have a Tab GUI Extension with a form and a text field. I would like to save the values of the form field to ApplicatioData. I was thinking of an 'Update' button calling an Anguilla method.

是否有安圭拉方法可以做到这一点?我在安圭拉没有看到任何方法.代码开头:

Is there an Anguilla method to do this? I don't see any method in Anguilla for this. Start of the code:

var c = $display.getItem();
var uri = c.getId();

推荐答案

Anguilla 不公开任何(webservice 或 JavaScript)方法来一般修改 ApplicationData.您必须提供自己的服务器端代码来设置 ApplicationData.

Anguilla doesn't expose any (webservice or JavaScript) methods to generically modify ApplicationData. You will have to provide your own server-side code to set the ApplicationData.

因此,在我最后一次需要时,我编写了一个简单的 WCF Web 服务来设置应用程序数据:

So in my last need for this I wrote a simply WCF web service that sets the application data:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceContract(Namespace= "ExtensionsModel.Services")]
public class ExtensionsService
{
    [OperationContract]
    [WebInvoke(Method = "POST",
                RequestFormat = WebMessageFormat.Json,
                ResponseFormat = WebMessageFormat.Json)]
    public void SetEnabled(string[] itemIDs, bool enabled)
    {
        using (var client = TridionCoreService.GetSessionAwareClient())
        {
            var appdata = new ApplicationData();
            appdata.ApplicationId = "ext:IsEnabled";
            appdata.Data = new ASCIIEncoding().GetBytes(enabled ? bool.TrueString : bool.FalseString);
            foreach (var itemID in itemIDs)
            {
                client.SaveApplicationData(itemID, new[] {appdata});
            }
        }
    }
}

在我的模型的配置文件中连接起来:

Wired it up in the configuration file of my model:

<?xml version="1.0" encoding="utf-8" ?>
<Configuration> <!-- namespaces removed for readability -->
  <resources cache="true">
    <cfg:filters/>
    <cfg:groups>
      <cfg:group name="Extensions.Models">
        <cfg:domainmodel name="Extensions.Models">
          <cfg:services>
            <cfg:service type="wcf">Services/ExtensionsService.svc</cfg:service>
          </cfg:services>
        </cfg:domainmodel>
      </cfg:group>
    </cfg:groups>
  ...

然后从我的command._execute

Extensions.Commands.DisableExtension.prototype._execute = function (selection) {
  ExtensionsModel.Services.ExtensionsService.SetEnabled(selection.getItems(), false);
};

这篇关于如何使用 Anguilla JavaScript 设置 Tridion ApplicationData?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆