public static string Restore(SiteSettings ss, long wikiId)
        {
            var wikiModel = new WikiModel();
            var invalid   = WikiValidators.OnRestoring();

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            var error = wikiModel.Restore(ss, wikiId);

            if (error.Has())
            {
                return(error.MessageJson());
            }
            else
            {
                var res = new WikisResponseCollection(wikiModel);
                return(res.ToJson());
            }
        }
Beispiel #2
0
        public static string Histories(
            Context context, SiteSettings ss, long wikiId, Message message = null)
        {
            var wikiModel = new WikiModel(context: context, ss: ss, wikiId: wikiId);

            ss.SetColumnAccessControls(
                context: context,
                mine: wikiModel.Mine(context: context));
            var columns = ss.GetHistoryColumns(context: context, checkPermission: true);

            if (!context.CanRead(ss: ss))
            {
                return(Error.Types.HasNotPermission.MessageJson());
            }
            var hb = new HtmlBuilder();

            hb
            .HistoryCommands(context: context, ss: ss)
            .Table(
                attributes: new HtmlAttributes().Class("grid history"),
                action: () => hb
                .THead(action: () => hb
                       .GridHeader(
                           columns: columns,
                           sort: false,
                           checkRow: true))
                .TBody(action: () => hb
                       .HistoriesTableBody(
                           context: context,
                           ss: ss,
                           columns: columns,
                           wikiModel: wikiModel)));
            return(new WikisResponseCollection(wikiModel)
                   .Html("#FieldSetHistories", hb)
                   .Message(message)
                   .ToJson());
        }
Beispiel #3
0
        public static Error.Types OnUpdating(SiteSettings ss, WikiModel wikiModel)
        {
            if (!ss.CanUpdate())
            {
                return(Error.Types.HasNotPermission);
            }
            ss.SetColumnAccessControls(wikiModel.Mine());
            foreach (var controlId in Forms.Keys())
            {
                switch (controlId)
                {
                case "Wikis_Title":
                    if (wikiModel.Title_Updated &&
                        !ss.GetColumn("Title").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Wikis_Body":
                    if (wikiModel.Body_Updated &&
                        !ss.GetColumn("Body").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Comments":
                    if (!ss.GetColumn("Comments").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;
                }
            }
            return(Error.Types.None);
        }
Beispiel #4
0
        public static Error.Types OnUpdating(SiteSettings ss, WikiModel wikiModel)
        {
            if (!ss.CanUpdate())
            {
                return(Error.Types.HasNotPermission);
            }
            ss.SetColumnAccessControls(wikiModel.Mine());
            foreach (var column in ss.Columns
                     .Where(o => !o.CanUpdate)
                     .Where(o => !ss.FormulaTarget(o.ColumnName)))
            {
                switch (column.ColumnName)
                {
                case "Title":
                    if (wikiModel.Title_Updated())
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Body":
                    if (wikiModel.Body_Updated())
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;

                case "Comments":
                    if (!ss.GetColumn("Comments").CanUpdate)
                    {
                        return(Error.Types.HasNotPermission);
                    }
                    break;
                }
            }
            return(Error.Types.None);
        }
Beispiel #5
0
        public static string Editor(SiteSettings ss, WikiModel wikiModel)
        {
            var invalid = WikiValidators.OnEditing(ss, wikiModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(HtmlTemplates.Error(invalid));
            }
            var hb = new HtmlBuilder();

            ss.SetColumnAccessControls(wikiModel.Mine());
            return(hb.Template(
                       ss: ss,
                       verType: wikiModel.VerType,
                       methodType: wikiModel.MethodType,
                       siteId: wikiModel.SiteId,
                       parentId: ss.ParentId,
                       referenceType: "Wikis",
                       title: wikiModel.MethodType == BaseModel.MethodTypes.New
                    ? Displays.New()
                    : wikiModel.Title.DisplayValue,
                       useTitle: ss.TitleColumns?.Any(o => ss.EditorColumns.Contains(o)) == true,
                       userScript: ss.EditorScripts(wikiModel.MethodType),
                       userStyle: ss.EditorStyles(wikiModel.MethodType),
                       action: () => hb
                       .Editor(
                           ss: ss,
                           wikiModel: wikiModel)
                       .Hidden(controlId: "TableName", value: "Wikis")
                       .Hidden(controlId: "Id", value: wikiModel.WikiId.ToString())
                       .Hidden(controlId: "TriggerRelatingColumns", value: Jsons.ToJson(ss.RelatingColumns))
                       .Hidden(controlId: "DropDownSearchPageSize", value: Parameters.General.DropDownSearchPageSize.ToString()))
                   .ToString());
        }
Beispiel #6
0
 private static void HistoriesTableBody(
     this HtmlBuilder hb, SiteSettings ss, List <Column> columns, WikiModel wikiModel)
 {
     new WikiCollection(
         ss: ss,
         column: HistoryColumn(columns),
         where : Rds.WikisWhere().WikiId(wikiModel.WikiId),
         orderBy: Rds.WikisOrderBy().Ver(SqlOrderBy.Types.desc),
         tableType: Sqls.TableTypes.NormalAndHistory)
     .ForEach(wikiModelHistory => hb
              .Tr(
                  attributes: new HtmlAttributes()
                  .Class("grid-row")
                  .DataAction("History")
                  .DataMethod("post")
                  .DataVer(wikiModelHistory.Ver)
                  .DataLatest(1, _using:
                              wikiModelHistory.Ver == wikiModel.Ver),
                  action: () =>
     {
         hb.Td(
             css: "grid-check-td",
             action: () => hb
             .CheckBox(
                 controlCss: "grid-check",
                 _checked: false,
                 dataId: wikiModelHistory.Ver.ToString(),
                 _using: wikiModelHistory.Ver < wikiModel.Ver));
         columns
         .ForEach(column => hb
                  .TdValue(
                      ss: ss,
                      column: column,
                      wikiModel: wikiModelHistory));
     }));
 }
Beispiel #7
0
        public static HtmlBuilder TdCustomValue(
            this HtmlBuilder hb, SiteSettings ss, string gridDesign, WikiModel wikiModel)
        {
            ss.IncludedColumns(gridDesign).ForEach(column =>
            {
                var value = string.Empty;
                switch (column.ColumnName)
                {
                case "SiteId": value = wikiModel.SiteId.GridText(column: column); break;

                case "UpdatedTime": value = wikiModel.UpdatedTime.GridText(column: column); break;

                case "WikiId": value = wikiModel.WikiId.GridText(column: column); break;

                case "Ver": value = wikiModel.Ver.GridText(column: column); break;

                case "Title": value = wikiModel.Title.GridText(column: column); break;

                case "Body": value = wikiModel.Body.GridText(column: column); break;

                case "TitleBody": value = wikiModel.TitleBody.GridText(column: column); break;

                case "Comments": value = wikiModel.Comments.GridText(column: column); break;

                case "Creator": value = wikiModel.Creator.GridText(column: column); break;

                case "Updator": value = wikiModel.Updator.GridText(column: column); break;

                case "CreatedTime": value = wikiModel.CreatedTime.GridText(column: column); break;
                }
                gridDesign = gridDesign.Replace("[" + column.ColumnName + "]", value);
            });
            return(hb.Td(action: () => hb
                         .Div(css: "markup", action: () => hb
                              .Text(text: gridDesign))));
        }
Beispiel #8
0
        public static string Update(SiteSettings ss, long wikiId)
        {
            var wikiModel = new WikiModel(ss, wikiId, setByForm: true);
            var invalid   = WikiValidators.OnUpdating(ss, wikiModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            if (wikiModel.AccessStatus != Databases.AccessStatuses.Selected)
            {
                return(Messages.ResponseDeleteConflicts().ToJson());
            }
            var error = wikiModel.Update(
                ss: ss,
                notice: true,
                permissions: Forms.List("CurrentPermissionsAll"),
                permissionChanged: Forms.Exists("CurrentPermissionsAll"));

            if (error.Has())
            {
                return(error == Error.Types.UpdateConflicts
                    ? Messages.ResponseUpdateConflicts(wikiModel.Updator.Name).ToJson()
                    : new ResponseCollection().Message(error.Message()).ToJson());
            }
            else
            {
                var res = new WikisResponseCollection(wikiModel);
                res.ReplaceAll("#Breadcrumb", new HtmlBuilder().Breadcrumb(ss.SiteId));
                return(ResponseByUpdate(res, ss, wikiModel)
                       .PrependComment(wikiModel.Comments, wikiModel.VerType)
                       .ToJson());
            }
        }
Beispiel #9
0
        public static string RestoreFromHistory(
            IContext context, SiteSettings ss, long wikiId)
        {
            if (!Parameters.History.Restore)
            {
                return(Error.Types.InvalidRequest.MessageJson(context: context));
            }
            var wikiModel = new WikiModel(context, ss, wikiId);
            var invalid   = WikiValidators.OnUpdating(
                context: context,
                ss: ss,
                wikiModel: wikiModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson(context: context));
            }
            var ver = context.Forms.Data("GridCheckedItems")
                      .Split(',')
                      .Where(o => !o.IsNullOrEmpty())
                      .ToList();

            if (ver.Count() != 1)
            {
                return(Error.Types.SelectOne.MessageJson(context: context));
            }
            wikiModel.SetByModel(new WikiModel().Get(
                                     context: context,
                                     ss: ss,
                                     tableType: Sqls.TableTypes.History,
                                     where : Rds.WikisWhere()
                                     .SiteId(ss.SiteId)
                                     .WikiId(wikiId)
                                     .Ver(ver.First())));
            wikiModel.VerUp = true;
            var error = wikiModel.Update(
                context: context,
                ss: ss,
                otherInitValue: true);

            switch (error)
            {
            case Error.Types.None:
                SessionUtilities.Set(
                    context: context,
                    message: Messages.RestoredFromHistory(
                        context: context,
                        data: ver.First().ToString()));
                return(new ResponseCollection()
                       .SetMemory("formChanged", false)
                       .Href(Locations.ItemEdit(
                                 context: context,
                                 id: wikiId))
                       .ToJson());

            default:
                return(error.MessageJson(context: context));
            }
        }
Beispiel #10
0
 private static ResponseCollection ResponseByUpdate(
     WikisResponseCollection res,
     IContext context,
     SiteSettings ss,
     WikiModel wikiModel)
 {
     if (context.Forms.Bool("IsDialogEditorForm"))
     {
         var view = Views.GetBySession(
             context: context,
             ss: ss,
             setSession: false);
         var gridData = new GridData(
             context: context,
             ss: ss,
             view: view,
             where : Rds.WikisWhere().WikiId(wikiModel.WikiId));
         var columns = ss.GetGridColumns(
             context: context,
             checkPermission: true);
         return(res
                .ReplaceAll(
                    $"[data-id=\"{wikiModel.WikiId}\"]",
                    gridData.TBody(
                        hb: new HtmlBuilder(),
                        context: context,
                        ss: ss,
                        columns: columns,
                        checkAll: false))
                .CloseDialog()
                .Message(Messages.Updated(
                             context: context,
                             data: wikiModel.Title.DisplayValue)));
     }
     else
     {
         return(res
                .Ver(context: context, ss: ss)
                .Timestamp(context: context, ss: ss)
                .FieldResponse(context: context, ss: ss, wikiModel: wikiModel)
                .Val("#VerUp", false)
                .Disabled("#VerUp", false)
                .Html("#HeaderTitle", wikiModel.Title.DisplayValue)
                .Html("#RecordInfo", new HtmlBuilder().RecordInfo(
                          context: context,
                          baseModel: wikiModel,
                          tableName: "Wikis"))
                .Html("#Links", new HtmlBuilder().Links(
                          context: context,
                          ss: ss,
                          id: wikiModel.WikiId))
                .SetMemory("formChanged", false)
                .Message(Messages.Updated(
                             context: context,
                             data: wikiModel.Title.DisplayValue))
                .Comment(
                    context: context,
                    ss: ss,
                    column: ss.GetColumn(context: context, columnName: "Comments"),
                    comments: wikiModel.Comments,
                    deleteCommentId: wikiModel.DeleteCommentId)
                .ClearFormData());
     }
 }
Beispiel #11
0
        public static HtmlBuilder FieldSetGeneralColumns(
            this HtmlBuilder hb,
            IContext context,
            SiteSettings ss,
            WikiModel wikiModel,
            bool preview      = false,
            bool editInDialog = false)
        {
            ss.GetEditorColumns(context: context).ForEach(column =>
            {
                switch (column.Name)
                {
                case "WikiId":
                    hb.Field(
                        context: context,
                        ss: ss,
                        column: column,
                        methodType: wikiModel.MethodType,
                        value: wikiModel.WikiId
                        .ToControl(context: context, ss: ss, column: column),
                        columnPermissionType: column.ColumnPermissionType(context: context),
                        preview: preview);
                    break;

                case "Ver":
                    hb.Field(
                        context: context,
                        ss: ss,
                        column: column,
                        methodType: wikiModel.MethodType,
                        value: wikiModel.Ver
                        .ToControl(context: context, ss: ss, column: column),
                        columnPermissionType: column.ColumnPermissionType(context: context),
                        preview: preview);
                    break;

                case "Title":
                    hb.Field(
                        context: context,
                        ss: ss,
                        column: column,
                        methodType: wikiModel.MethodType,
                        value: wikiModel.Title
                        .ToControl(context: context, ss: ss, column: column),
                        columnPermissionType: column.ColumnPermissionType(context: context),
                        preview: preview);
                    break;

                case "Body":
                    hb.Field(
                        context: context,
                        ss: ss,
                        column: column,
                        methodType: wikiModel.MethodType,
                        value: wikiModel.Body
                        .ToControl(context: context, ss: ss, column: column),
                        columnPermissionType: column.ColumnPermissionType(context: context),
                        preview: preview);
                    break;
                }
            });
            if (!preview)
            {
                hb.VerUpCheckBox(
                    context: context,
                    ss: ss,
                    baseModel: wikiModel);
            }
            return(hb);
        }
Beispiel #12
0
        /// <summary>
        /// Fixed:
        /// </summary>
        private static HtmlBuilder Editor(
            this HtmlBuilder hb,
            IContext context,
            SiteSettings ss,
            WikiModel wikiModel)
        {
            var commentsColumn = ss.GetColumn(
                context: context,
                columnName: "Comments");
            var commentsColumnPermissionType = commentsColumn
                                               .ColumnPermissionType(context: context);
            var showComments = ss.ShowComments(commentsColumnPermissionType);
            var tabsCss      = showComments ? null : "max";

            return(hb.Div(id: "Editor", action: () => hb
                          .Form(
                              attributes: new HtmlAttributes()
                              .Id("WikiForm")
                              .Class("main-form")
                              .Action(Locations.ItemAction(
                                          context: context,
                                          id: wikiModel.WikiId != 0
                                ? wikiModel.WikiId
                                : wikiModel.SiteId)),
                              action: () => hb
                              .RecordHeader(
                                  context: context,
                                  ss: ss,
                                  baseModel: wikiModel,
                                  tableName: "Wikis")
                              .Div(
                                  id: "EditorComments", action: () => hb
                                  .Comments(
                                      context: context,
                                      ss: ss,
                                      comments: wikiModel.Comments,
                                      column: commentsColumn,
                                      verType: wikiModel.VerType,
                                      columnPermissionType: commentsColumnPermissionType),
                                  _using: showComments)
                              .Div(id: "EditorTabsContainer", css: tabsCss, action: () => hb
                                   .EditorTabs(
                                       context: context,
                                       ss: ss,
                                       wikiModel: wikiModel)
                                   .FieldSetGeneral(
                                       context: context,
                                       ss: ss,
                                       wikiModel: wikiModel)
                                   .FieldSet(
                                       attributes: new HtmlAttributes()
                                       .Id("FieldSetHistories")
                                       .DataAction("Histories")
                                       .DataMethod("post"),
                                       _using: wikiModel.MethodType != BaseModel.MethodTypes.New)
                                   .FieldSet(
                                       attributes: new HtmlAttributes()
                                       .Id("FieldSetRecordAccessControl")
                                       .DataAction("Permissions")
                                       .DataMethod("post"),
                                       _using: context.CanManagePermission(ss: ss))
                                   .MainCommands(
                                       context: context,
                                       ss: ss,
                                       siteId: wikiModel.SiteId,
                                       verType: wikiModel.VerType,
                                       referenceId: wikiModel.WikiId,
                                       updateButton: true,
                                       copyButton: false,
                                       moveButton: false,
                                       mailButton: true,
                                       deleteButton: true))
                              .Hidden(
                                  controlId: "BaseUrl",
                                  value: Locations.BaseUrl(context: context))
                              .Hidden(
                                  controlId: "MethodType",
                                  value: "edit")
                              .Hidden(
                                  controlId: "Wikis_Timestamp",
                                  css: "always-send",
                                  value: wikiModel.Timestamp)
                              .Hidden(
                                  controlId: "SwitchTargets",
                                  css: "always-send",
                                  value: wikiModel.WikiId.ToString(),
                                  _using: !context.Ajax || context.Action == "create"))
                          .OutgoingMailsForm(
                              context: context,
                              ss: ss,
                              referenceType: "Wikis",
                              referenceId: wikiModel.WikiId,
                              referenceVer: wikiModel.Ver)
                          .CopyDialog(
                              context: context,
                              referenceType: "items",
                              id: wikiModel.WikiId)
                          .MoveDialog(context: context)
                          .OutgoingMailDialog()));
        }
Beispiel #13
0
        public static HtmlBuilder TdValue(
            this HtmlBuilder hb,
            IContext context,
            SiteSettings ss,
            Column column,
            WikiModel wikiModel)
        {
            if (!column.GridDesign.IsNullOrEmpty())
            {
                return(hb.TdCustomValue(
                           context: context,
                           ss: ss,
                           gridDesign: column.GridDesign,
                           wikiModel: wikiModel));
            }
            else
            {
                var mine = wikiModel.Mine(context: context);
                switch (column.Name)
                {
                case "SiteId":
                    return(ss.ReadColumnAccessControls.Allowed(
                               context: context,
                               ss: ss,
                               column: column,
                               type: ss.PermissionType,
                               mine: mine)
                                ? hb.Td(
                               context: context,
                               column: column,
                               value: wikiModel.SiteId)
                                : hb.Td(
                               context: context,
                               column: column,
                               value: string.Empty));

                case "UpdatedTime":
                    return(ss.ReadColumnAccessControls.Allowed(
                               context: context,
                               ss: ss,
                               column: column,
                               type: ss.PermissionType,
                               mine: mine)
                                ? hb.Td(
                               context: context,
                               column: column,
                               value: wikiModel.UpdatedTime)
                                : hb.Td(
                               context: context,
                               column: column,
                               value: string.Empty));

                case "WikiId":
                    return(ss.ReadColumnAccessControls.Allowed(
                               context: context,
                               ss: ss,
                               column: column,
                               type: ss.PermissionType,
                               mine: mine)
                                ? hb.Td(
                               context: context,
                               column: column,
                               value: wikiModel.WikiId)
                                : hb.Td(
                               context: context,
                               column: column,
                               value: string.Empty));

                case "Ver":
                    return(ss.ReadColumnAccessControls.Allowed(
                               context: context,
                               ss: ss,
                               column: column,
                               type: ss.PermissionType,
                               mine: mine)
                                ? hb.Td(
                               context: context,
                               column: column,
                               value: wikiModel.Ver)
                                : hb.Td(
                               context: context,
                               column: column,
                               value: string.Empty));

                case "Title":
                    return(ss.ReadColumnAccessControls.Allowed(
                               context: context,
                               ss: ss,
                               column: column,
                               type: ss.PermissionType,
                               mine: mine)
                                ? hb.Td(
                               context: context,
                               column: column,
                               value: wikiModel.Title)
                                : hb.Td(
                               context: context,
                               column: column,
                               value: string.Empty));

                case "Body":
                    return(ss.ReadColumnAccessControls.Allowed(
                               context: context,
                               ss: ss,
                               column: column,
                               type: ss.PermissionType,
                               mine: mine)
                                ? hb.Td(
                               context: context,
                               column: column,
                               value: wikiModel.Body)
                                : hb.Td(
                               context: context,
                               column: column,
                               value: string.Empty));

                case "TitleBody":
                    return(ss.ReadColumnAccessControls.Allowed(
                               context: context,
                               ss: ss,
                               column: column,
                               type: ss.PermissionType,
                               mine: mine)
                                ? hb.Td(
                               context: context,
                               column: column,
                               value: wikiModel.TitleBody)
                                : hb.Td(
                               context: context,
                               column: column,
                               value: string.Empty));

                case "Comments":
                    return(ss.ReadColumnAccessControls.Allowed(
                               context: context,
                               ss: ss,
                               column: column,
                               type: ss.PermissionType,
                               mine: mine)
                                ? hb.Td(
                               context: context,
                               column: column,
                               value: wikiModel.Comments)
                                : hb.Td(
                               context: context,
                               column: column,
                               value: string.Empty));

                case "Creator":
                    return(ss.ReadColumnAccessControls.Allowed(
                               context: context,
                               ss: ss,
                               column: column,
                               type: ss.PermissionType,
                               mine: mine)
                                ? hb.Td(
                               context: context,
                               column: column,
                               value: wikiModel.Creator)
                                : hb.Td(
                               context: context,
                               column: column,
                               value: string.Empty));

                case "Updator":
                    return(ss.ReadColumnAccessControls.Allowed(
                               context: context,
                               ss: ss,
                               column: column,
                               type: ss.PermissionType,
                               mine: mine)
                                ? hb.Td(
                               context: context,
                               column: column,
                               value: wikiModel.Updator)
                                : hb.Td(
                               context: context,
                               column: column,
                               value: string.Empty));

                case "CreatedTime":
                    return(ss.ReadColumnAccessControls.Allowed(
                               context: context,
                               ss: ss,
                               column: column,
                               type: ss.PermissionType,
                               mine: mine)
                                ? hb.Td(
                               context: context,
                               column: column,
                               value: wikiModel.CreatedTime)
                                : hb.Td(
                               context: context,
                               column: column,
                               value: string.Empty));

                default: return(hb);
                }
            }
        }
        public static ErrorData OnCreating(
            Context context, SiteSettings ss, WikiModel wikiModel, bool api = false)
        {
            if (api && (context.ContractSettings.Api == false || !Parameters.Api.Enabled))
            {
                return(new ErrorData(type: Error.Types.InvalidRequest));
            }
            if (!context.CanCreate(ss: ss))
            {
                return(new ErrorData(type: Error.Types.HasNotPermission));
            }
            ss.SetColumnAccessControls(context: context, mine: wikiModel.Mine(context: context));
            foreach (var column in ss.Columns
                     .Where(o => !o.CanCreate)
                     .Where(o => !ss.FormulaTarget(o.ColumnName))
                     .Where(o => !o.Linking))
            {
                switch (column.ColumnName)
                {
                case "Title":
                    if (wikiModel.Title_Updated(context: context, column: column))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Body":
                    if (wikiModel.Body_Updated(context: context, column: column))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Comments":
                    if (!ss.GetColumn(context: context, columnName: "Comments").CanUpdate)
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                default:
                    switch (Def.ExtendedColumnTypes.Get(column.Name))
                    {
                    case "Class":
                        if (wikiModel.Class_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Num":
                        if (wikiModel.Num_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Date":
                        if (wikiModel.Date_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Description":
                        if (wikiModel.Description_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Check":
                        if (wikiModel.Check_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Attachments":
                        if (wikiModel.Attachments_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;
                    }
                    break;
                }
            }
            return(new ErrorData(type: Error.Types.None));
        }
        public static string Editor(
            Context context,
            SiteSettings ss,
            WikiModel wikiModel,
            bool editInDialog = false)
        {
            var invalid = WikiValidators.OnEditing(
                context: context,
                ss: ss,
                wikiModel: wikiModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(HtmlTemplates.Error(context, invalid));
            }
            var hb = new HtmlBuilder();

            ss.SetColumnAccessControls(
                context: context,
                mine: wikiModel.Mine(context: context));
            return(editInDialog
                ? hb.DialogEditorForm(
                       context: context,
                       siteId: wikiModel.SiteId,
                       referenceId: wikiModel.WikiId,
                       action: () => hb
                       .FieldSetGeneral(
                           context: context,
                           ss: ss,
                           wikiModel: wikiModel,
                           editInDialog: editInDialog))
                   .ToString()
                : hb.Template(
                       context: context,
                       ss: ss,
                       view: null,
                       verType: wikiModel.VerType,
                       methodType: wikiModel.MethodType,
                       siteId: wikiModel.SiteId,
                       parentId: ss.ParentId,
                       referenceType: "Wikis",
                       title: wikiModel.MethodType == BaseModel.MethodTypes.New
                        ? Displays.New(context: context)
                        : wikiModel.Title.DisplayValue,
                       body: wikiModel.Body,
                       useTitle: ss.TitleColumns?.Any(o => ss.EditorColumns.Contains(o)) == true,
                       userScript: ss.EditorScripts(
                           context: context, methodType: wikiModel.MethodType),
                       userStyle: ss.EditorStyles(
                           context: context, methodType: wikiModel.MethodType),
                       action: () => hb
                       .Editor(
                           context: context,
                           ss: ss,
                           wikiModel: wikiModel)
                       .Hidden(controlId: "TableName", value: "Wikis")
                       .Hidden(controlId: "Controller", value: context.Controller)
                       .Hidden(controlId: "Id", value: wikiModel.WikiId.ToString())
                       .Hidden(controlId: "TriggerRelatingColumns", value: Jsons.ToJson(ss.RelatingColumns))
                       .Hidden(controlId: "DropDownSearchPageSize", value: Parameters.General.DropDownSearchPageSize.ToString()))
                   .ToString());
        }
Beispiel #16
0
 public static Error.Types OnDeleting(SiteSettings ss, WikiModel wikiModel)
 {
     return(ss.CanDelete()
         ? Error.Types.None
         : Error.Types.HasNotPermission);
 }
Beispiel #17
0
        public static ErrorData OnCreating(
            Context context, SiteSettings ss, WikiModel wikiModel, bool api = false)
        {
            if (api)
            {
                if ((context.ContractSettings.Api == false || !Parameters.Api.Enabled))
                {
                    return(new ErrorData(type: Error.Types.InvalidRequest));
                }
                if (context.InvalidJsonData)
                {
                    return(new ErrorData(type: Error.Types.InvalidJsonData));
                }
            }
            if (ss.LockedTable())
            {
                return(new ErrorData(
                           type: Error.Types.LockedTable,
                           data: new string[]
                {
                    ss.LockedTableUser.Name,
                    ss.LockedTableTime.DisplayValue.ToString(context.CultureInfo())
                }));
            }
            if (!context.CanCreate(ss: ss) || wikiModel.ReadOnly)
            {
                return(!context.CanRead(ss: ss)
                    ? new ErrorData(type: Error.Types.NotFound)
                    : new ErrorData(type: Error.Types.HasNotPermission));
            }
            foreach (var column in ss.Columns
                     .Where(o => !o.CanCreate(
                                context: context,
                                ss: ss,
                                mine: wikiModel.Mine(context: context)))
                     .Where(o => !ss.FormulaTarget(o.ColumnName))
                     .Where(o => !o.Linking))
            {
                switch (column.ColumnName)
                {
                case "Title":
                    if (wikiModel.Title_Updated(context: context, column: column))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Body":
                    if (wikiModel.Body_Updated(context: context, column: column))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Locked":
                    if (wikiModel.Locked_Updated(context: context, column: column))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                case "Comments":
                    if (wikiModel.Comments_Updated(context: context))
                    {
                        return(new ErrorData(type: Error.Types.HasNotPermission));
                    }
                    break;

                default:
                    switch (Def.ExtendedColumnTypes.Get(column.Name))
                    {
                    case "Class":
                        if (wikiModel.Class_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Num":
                        if (wikiModel.Num_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Date":
                        if (wikiModel.Date_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Description":
                        if (wikiModel.Description_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Check":
                        if (wikiModel.Check_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;

                    case "Attachments":
                        if (wikiModel.Attachments_Updated(
                                columnName: column.Name,
                                context: context,
                                column: column))
                        {
                            return(new ErrorData(type: Error.Types.HasNotPermission));
                        }
                        break;
                    }
                    break;
                }
            }
            return(new ErrorData(type: Error.Types.None));
        }
Beispiel #18
0
        public static ResponseCollection FieldResponse(
            this ResponseCollection res,
            SiteSettings ss,
            WikiModel wikiModel)
        {
            var mine = wikiModel.Mine();

            ss.EditorColumns
            .Select(o => ss.GetColumn(o))
            .Where(o => o != null)
            .ForEach(column =>
            {
                switch (column.Name)
                {
                case "SiteId":
                    res.Val(
                        "#Wikis_SiteId",
                        wikiModel.SiteId.ToControl(ss, column));
                    break;

                case "UpdatedTime":
                    res.Val(
                        "#Wikis_UpdatedTime",
                        wikiModel.UpdatedTime.ToControl(ss, column));
                    break;

                case "WikiId":
                    res.Val(
                        "#Wikis_WikiId",
                        wikiModel.WikiId.ToControl(ss, column));
                    break;

                case "Ver":
                    res.Val(
                        "#Wikis_Ver",
                        wikiModel.Ver.ToControl(ss, column));
                    break;

                case "Title":
                    res.Val(
                        "#Wikis_Title",
                        wikiModel.Title.ToControl(ss, column));
                    break;

                case "Body":
                    res.Val(
                        "#Wikis_Body",
                        wikiModel.Body.ToControl(ss, column));
                    break;

                case "Comments":
                    res.Val(
                        "#Wikis_Comments",
                        wikiModel.Comments.ToControl(ss, column));
                    break;

                case "Creator":
                    res.Val(
                        "#Wikis_Creator",
                        wikiModel.Creator.ToControl(ss, column));
                    break;

                case "Updator":
                    res.Val(
                        "#Wikis_Updator",
                        wikiModel.Updator.ToControl(ss, column));
                    break;

                case "CreatedTime":
                    res.Val(
                        "#Wikis_CreatedTime",
                        wikiModel.CreatedTime.ToControl(ss, column));
                    break;

                default: break;
                }
            });
            return(res);
        }
Beispiel #19
0
 private static HtmlBuilder EditorExtensions(
     this HtmlBuilder hb, SiteSettings ss, WikiModel wikiModel)
 {
     return(hb);
 }
Beispiel #20
0
 private static HtmlBuilder MainCommandExtensions(
     this HtmlBuilder hb, SiteSettings ss, WikiModel wikiModel)
 {
     return(hb);
 }