예제 #1
0
            /// <summary>
            /// Displays an inline-checkbox for instant-editing of simple on-off-attributes on a table
            /// </summary>
            /// <typeparam name="TModel">the model of the current table</typeparam>
            /// <param name="target">the column-factory for the current table</param>
            /// <param name="expression">the expression that identifies the bound column</param>
            /// <param name="pkName">the primary-key name of the target-model</param>
            /// <param name="customChangeHandler">a custom changed-handler</param>
            /// <param name="readOnly">indicates whether to put this on read-only</param>
            /// <returns>the column-builder for the bound column</returns>
            public static GridBoundColumnBuilder<TModel> InlineCheckbox<TModel>(this GridColumnFactory<TModel> target, Expression<Func<TModel, bool>> expression, string pkName, string customChangeHandler = null, bool readOnly = false)
                where TModel : class
            {
                var retVal = target.Bound(expression);
                string columnName = retVal.Column.Member;
                string idRaw = CustomActionHelper.RandomName(retVal.Column.Member);
                string id = $"{idRaw}#={pkName}#";
                string template = $@"<input id='{id}' class='itv-icb-marker' data-col-name='{columnName}' #if ({columnName}) {{ # checked='checked' # }} # type='checkbox' style='display:none;' {(!string.IsNullOrEmpty(customChangeHandler) ? $"itvCustomChangeHandler='{customChangeHandler}'" : "")} />
    #{{
        var nameId = {pkName}.toString();
        var name = ""\#{idRaw}"".concat(nameId);
        var ids = {columnName};
        var dataItem = this;
        $(function(){{
            $(name).kendoSwitch({{
                enabled:{(readOnly?"false":"true")},
                change:{customChangeHandler??"ITVenture.Tools.TableHelper.defaultCheckedCallback"}
            }});
        }});
    }}#";
                /*if (clientTemplateReady)
                {
                    template = template.ToClientTemplate();
                }*/

                retVal.ClientTemplate(template);
                return retVal;
            }
예제 #2
0
        public static IHtmlContent AjaxFkFor<TModel, TResult>(this IHtmlHelper<TModel> target, Expression<Func<TModel, TResult>> expression, string repoName, string tableName, object customFilterData = null, int minSearchLength = 0, Dictionary<string, string> nameBuffer = null, string cascadeFrom = null) where TModel : class
        {
            string dataCallback = null;
            string columnName = target.DisplayNameFor(expression);
            string id = CustomActionHelper.RandomName($"FK_{repoName}_{tableName}_{columnName}");
            nameBuffer?.Add(columnName, id);
            string dataCallbackBody = null;
            var route = target.ViewContext.HttpContext.Request.RouteValues;
            string area = null;
            if (route.ContainsKey("area"))
            {
                area = (string) route["area"];
            }

            if (customFilterData != null)
            {
                dataCallback = $"ITVenture.Tools.ListCallbackHelper.dataCallbacks.{CreateDataScriptFor(repoName, tableName, columnName, customFilterData, out dataCallbackBody)}";
            }
            
            target.Raw($@"<script>
            {dataCallbackBody}
</script>").WriteTo(target.ViewContext.Writer, HtmlEncoder.Default);
            return target.EditorFor(expression, "ApiForeignKey", new Dictionary<string, object>
            {
                {$"{columnName}_RepoName", repoName},
                {$"{columnName}_TableName", tableName},
                {$"{columnName}_ID", id},
                {$"{columnName}_minLength", minSearchLength},
                {$"{columnName}_CascadeTarget", cascadeFrom},
                {$"{columnName}_DataCallback", dataCallback},
                {$"{columnName}_Area", area}
            });
        }
예제 #3
0
            /// <summary>
            /// Displays a Multi-Select box for editing / displaying data
            /// </summary>
            /// <typeparam name="TModel">the target-model of the list</typeparam>
            /// <typeparam name="TValue">the value type of the bound field</typeparam>
            /// <param name="target">the column-factory of the list</param>
            /// <param name="expression">the expression targeting an enumerable field</param>
            /// <param name="repoName">the name of the repository that provides the fk-data</param>
            /// <param name="tableName">the name of the source table</param>
            /// <param name="pkName">the name of the primary-key</param>
            /// <param name="placeholder">a placeholder text that is being displayed when nothing is selected</param>
            /// <param name="alwaysActive">Indicates whether to keep the display-template editable, so that this column can be edited without entering edit-mode</param>
            /// <param name="customInlineChangedHandler">defines a custom handler that will be called, when an item was selected or deleted. If no value is provided, the default handler will be used and the grid will be synced on every modification action of the item.</param>
            /// <returns>the ColumnBuilder object for the bound field</returns>
            public static GridBoundColumnBuilder<TModel> MultiSelect<TModel, TValue>(this GridColumnFactory<TModel> target, Expression<Func<TModel, TValue>> expression, string repoName, string tableName, string pkName, string placeholder = "", bool alwaysActive = false, string customInlineChangedHandler = null) where TModel : class
                where TValue : IEnumerable
            {
                var retVal = target.Bound(expression);
                var route = target.Container.HtmlHelper.ViewContext.HttpContext.Request.RouteValues;
                string area = null;
                string changedHandler = customInlineChangedHandler ?? "ITVenture.Tools.TableHelper.defaultMultiSelectCallback";
                if (route.ContainsKey("area"))
                {
                    area = (string) route["area"];
                }

                var urlFormat = target.Container.HtmlHelper.ViewContext.HttpContext.RequestServices.GetService<IUrlFormat>();
            var url = new StringBuilder();
            url.Append(urlFormat != null ?
                urlFormat.FormatUrl($"[SlashPermissionScope]{(!string.IsNullOrEmpty(area) ? $"/{area}" : "")}") :
                $"{(!string.IsNullOrEmpty(area) ? $"/{area}" : "")}");
            url.Append($"/ForeignKey/{repoName}/{tableName}");
            string columnName = $"{retVal.Column.Member}";
                string displayTemplateName = $"{columnName}#={pkName}#";
                string idRaw = CustomActionHelper.RandomName(retVal.Column.Member);
                string id = $"{idRaw}#={pkName}#";
                var clientTemplate = @$"<select {(!alwaysActive?@"disabled=""disabled""":"")} id=""{id}"" multiple=""multiple"" style='display:none;' name=""{displayTemplateName}"" data-col-name='{columnName}'></select>
    #{{
        if (typeof({retVal.Column.Member}) !== ""undefined""){{
예제 #4
0
        internal static string CreateDataScriptFor(string repoName, string tableName, string memberName, object customDataFilter, out string dataFilter)
        {
            string filterFunction = CustomActionHelper.RandomName($"dataCbFx_{repoName}_{tableName}_{memberName}");
            dataFilter = $@"ITVenture.Tools.ListCallbackHelper.dataCallbacks.{filterFunction} = function(dataRequest){{
            var obj = {JsonHelper.ToJson(customDataFilter)};
            var retVal = $.extend({{}},dataRequest,obj);

            return retVal;
}};";
            return filterFunction;
        }
예제 #5
0
        public static IHtmlContent Uploader(this IHtmlHelper target, UploadMode mode, string uploaderModule, string uploadReason, string callbackMethod, int height = 0, int width = 0, Dictionary<string, string> customAttributes = null)
        {
            string uniqueDivId;
            uniqueDivId = CustomActionHelper.RandomName("uploadDiv");
            string template = $@"<div purpose='{mode}' id='{uniqueDivId}' nameTarget='{uniqueDivId}' uploadModule='{uploaderModule}' uploadReason='{uploadReason}' class='dropzone dropzone-flexi' {(height != 0 || width != 0 ? $"style=\"display:table-cell;position:relative;{(height != 0 ? $"height:{height}px;" : "")}{(width != 0 ? $"width:{width}px;" : "")}\"" : "")} {(customAttributes != null ? string.Join(" ", from t in customAttributes select $"{t.Key}='{t.Value}'") : "")}></div>
<script>ITVenture.Tools.Uploader.prepareUploadRegion({{
    {uniqueDivId}: {callbackMethod}
}});
</script>";

            return target.Raw(template);
        }
예제 #6
0
        public async Task <IViewComponentResult> InvokeAsync(string name, string sourceContextName, string controllerName, ICollection <TableColumnDefinition> tableDef, bool create = true, bool update = true, bool delete = true, object customRouteData = null, IDictionary <string, object> customViewData = null)
        {
            ViewData["name"]            = CustomActionHelper.RandomName(name);
            ViewData["controllerName"]  = controllerName;
            ViewData["create"]          = create;
            ViewData["update"]          = update;
            ViewData["delete"]          = delete;
            ViewData["customRouteData"] = customRouteData;
            ViewData["contextForFk"]    = sourceContextName;
            if (customViewData != null)
            {
                customViewData.ForEach(n => ViewData[n.Key] = n.Value);
            }

            return(View(tableDef));
        }
예제 #7
0
        public static IHtmlContent UploaderFor<TModel, TResult>(this IHtmlHelper<TModel> target,
                Expression<Func<TModel, TResult>> expression,
                UploadMode mode,
                string uploaderModule,
                string uploadReason,
                bool preserveOriginal,
                string originalFieldName,
                string uploadHint,
                string customUploadCallback,
                bool setOriginalOnlyIfNull)
            {
                string uniqueDivId, uniqueInputId, uniqueOrigId, uniqueDummyId;
                uniqueDivId = CustomActionHelper.RandomName("uploadDiv");
                uniqueInputId = CustomActionHelper.RandomName("valueBox");
                uniqueOrigId = CustomActionHelper.RandomName("oriValueBox");
                uniqueDummyId = CustomActionHelper.RandomName("dummyDiv");
                var notNullOrig = $@"""var $ori = $(\""\\#{uniqueOrigId}\"").val();""
.concat(        ""if ($ori === null || $ori.trim() === \""\""){{"")
.concat(""$(\""\\#{uniqueOrigId}\"").val(oriValue).change();"")
.concat(""}}"")";
                var additionalCallback = $@"""{(!string.IsNullOrEmpty(customUploadCallback)?$"{customUploadCallback}(value{(preserveOriginal ? ", oriValue" : "")});":"")}""";
                string template = $@"<div id=""{uniqueDummyId}""></div>
<script>
var tmpl = ""\u003Cdiv purpose=\""{mode}\"" nameTarget=\""{uniqueDivId}\"" uploadModule=\""{uploaderModule}\"" uploadReason=\""{uploadReason}\"" uploadHint=\""{uploadHint}\"" class=\""dropzone\""\u003E""
.concat(""\u003C/div\u003E"")
.concat(""{target.HiddenFor(expression, new {id = uniqueInputId}).GetString().Replace("#", @"\\#").Replace(@"""", @"\""").Replace(@"<", @"\u003C").Replace(@">", @"\u003E")}"")
.concat({(preserveOriginal ? $@"""\u003Cinput data-bind=\""value:{originalFieldName}\"" id=\""{uniqueOrigId}\"" name=\""{originalFieldName}\"" type=\""hidden\"" value=\""\""  /\u003E""" : "\"\"")})
.concat(""\u003Cscript>ITVenture.Tools.Uploader.prepareUploadRegion({{"")
.concat(    ""{uniqueDivId}: function(value{(preserveOriginal ? ", oriValue" : "")}){{"")
.concat(        ""$(\""\\#{uniqueInputId}\"").val(value).change();"")
.concat({(preserveOriginal ? $@"{(setOriginalOnlyIfNull ? notNullOrig : "\"\"")}":"\"\"")})
.concat({additionalCallback})
.concat(""}}"")
.concat(""}});\u003C/script\u003E"");
var template = kendo.template(tmpl);
var data = $(""#{uniqueDummyId}"").parent().parent().data(""kendoEditable"").options.model;
var result = template(data);
$(""#{uniqueDummyId}"").replaceWith(result);
</script>";
                return target.Raw(template);
            }
예제 #8
0
 /// <summary>
 /// Enables the Refresh-Button in the Command-Toolbar of the table
 /// </summary>
 /// <typeparam name="TModel">the model of the table</typeparam>
 /// <param name="target">the command-factory for the given table</param>
 /// <returns></returns>
 public static GridToolBarCustomCommandBuilder RefreshTable<TModel>(this GridToolBarCommandFactory<TModel> target) where TModel : class
 {
     return target.Custom().Name(CustomActionHelper.RandomName("refresh")).Text("\u200B").HtmlAttributes(new Dictionary<string, object> {{"onclick", "ITVenture.Tools.TableHelper.refreshTable(event)"}, {"class", "itv-tool-button itv-fa-tbx"}, {"title", TextsAndMessagesHelper.IWCN_KX_RTB_Caption}}).IconClass("fas fa-sync");
 }