Пример #1
0
 /// <summary>
 /// 添加删除按钮
 /// 点击后弹出确认框,确认后把json=[数据Id]提交到删除url
 /// </summary>
 /// <param name="column">操作列</param>
 /// <param name="typeName">类型名称</param>
 /// <param name="deleteUrl">删除使用的Url</param>
 /// <param name="name">名称,不指定时使用默认值</param>
 /// <param name="buttonClass">按钮的Css类,不指定时使用默认值</param>
 /// <param name="iconClass">图标的Css类,不指定时使用默认值</param>
 /// <param name="titleTemplate">标题的模板,格式是underscore.js的格式,参数传入rows</param>
 /// <param name="urlTemplate">编辑Url的模板,格式是underscore.js的格式,参数传入rows</param>
 /// <param name="primaryKey">数据Id保存的名称,不指定时使用默认值</param>
 /// <param name="dialogParameters">弹出框的参数,不指定时使用默认值</param>
 public static void AddDeleteAction(
     this AjaxTableActionColumn column, string typeName, string deleteUrl,
     string name          = null, string buttonClass      = null, string iconClass = null,
     string titleTemplate = null, string urlTemplate      = null,
     string primaryKey    = null, object dialogParameters = null)
 {
     primaryKey = primaryKey ?? EntityTrait.For <object>().PrimaryKey;
     column.AddConfirmActionForBelongedRow(
         name ?? new T("Delete"),
         buttonClass ?? "btn btn-xs btn-danger",
         iconClass ?? "fa fa-remove",
         titleTemplate ?? string.Format(new T("Delete {0}"), new T(typeName)),
         ScriptStrings.ConfirmMessageTemplateForMultiSelected(
             string.Format(new T("Sure to delete following {0}?"), new T(typeName)), "ToString"),
         ScriptStrings.PostConfirmedActionForMultiSelected(primaryKey, deleteUrl),
         dialogParameters);
 }
Пример #2
0
        /// <summary>
        /// 添加删除相关的按钮
        /// 如果数据类型可以回收,则添加批量删除或批量恢复和永久删除
        /// 如果数据类型不可以回收,则添加批量永久删除
        /// </summary>
        /// <param name="column">Id列</param>
        /// <param name="request">搜索请求</param>
        /// <param name="dataType">数据类型</param>
        /// <param name="typeName">类型名称</param>
        /// <param name="batchUrl">批量操作使用的Url</param>
        public static void AddDeleteActions(
            this AjaxTableIdColumn column, AjaxTableSearchRequest request,
            Type dataType, string typeName, string batchUrl)
        {
            // 判断需要添加哪些操作
            bool addBatchDelete        = false;
            bool addBatchRecover       = false;
            bool addBatchDeleteForever = false;

            if (RecyclableTrait.For(dataType).IsRecyclable)
            {
                var deleted = request.Conditions.GetOrDefault <bool>("Deleted");
                addBatchDelete        = !deleted;
                addBatchRecover       = deleted;
                addBatchDeleteForever = deleted;
            }
            else
            {
                addBatchDeleteForever = true;
            }
            // 添加批量删除
            typeName = new T(typeName);
            var entityTrait = EntityTrait.For(dataType);

            if (addBatchDelete)
            {
                column.AddConfirmActionForMultiChecked(
                    new T("Batch Delete"),
                    "fa fa-recycle",
                    string.Format(new T("Please select {0} to delete"), typeName),
                    new T("Batch Delete"),
                    ScriptStrings.ConfirmMessageTemplateForMultiSelected(
                        string.Format(new T("Sure to delete following {0}?"), typeName), "ToString"),
                    ScriptStrings.PostConfirmedActionForMultiSelected(
                        entityTrait.PrimaryKey, batchUrl + "?action=delete"),
                    new { type = "type-danger" });
            }
            // 添加批量恢复
            if (addBatchRecover)
            {
                column.AddConfirmActionForMultiChecked(
                    new T("Batch Recover"),
                    "fa fa-history",
                    string.Format(new T("Please select {0} to recover"), typeName),
                    new T("Batch Recover"),
                    ScriptStrings.ConfirmMessageTemplateForMultiSelected(
                        string.Format(new T("Sure to recover following {0}?"), typeName), "ToString"),
                    ScriptStrings.PostConfirmedActionForMultiSelected(
                        entityTrait.PrimaryKey, batchUrl + "?action=recover"));
            }
            // 添加批量永久删除
            if (addBatchDeleteForever)
            {
                column.AddConfirmActionForMultiChecked(
                    new T("Batch Delete Forever"),
                    "fa fa-remove",
                    string.Format(new T("Please select {0} to delete"), typeName),
                    new T("Batch Delete Forever"),
                    ScriptStrings.ConfirmMessageTemplateForMultiSelected(
                        string.Format(new T("Sure to delete following {0} forever?"), typeName), "ToString"),
                    ScriptStrings.PostConfirmedActionForMultiSelected(
                        entityTrait.PrimaryKey, batchUrl + "?action=delete_forever"),
                    new { type = "type-danger" });
            }
        }