Dev team
  • Name:
    Stefan P.
    Contributor since:
    01.08.2013
  • Name:
    Ciprian P.
    Contributor since:
    01.09.2013
  • Name:
    Cezar C.
    Contributor since:
    15.08.2013
  • Name:
    Marius C.
    Contributor since:
    10.08.2013
  • Name:
    Cristian P.
    Contributor since:
    01.10.2013
  • Name:
    Oana M.
    Contributor since:
    05.08.2013
  • Name:
    Mihai P.
    Contributor since:
    14.10.2013
  • Name:
    Andrei F.
    Contributor since:
    14.10.2013
  • Name:
    Bogdan T.
    Contributor since:
    14.10.2013
  • Name:
    Cosmin G.
    Contributor since:
    14.10.2013
  • Name:
    Marina C.
    Contributor since:
    14.10.2013
  • Name:
    Marin V.
    Contributor since:
    14.10.2013
  • Name:
    Sorin S.
    Contributor since:
    14.10.2013
  • Name:
    Alessandro M.
    Contributor since:
    14.10.2013
  • Name:
    Razvan D.
    Contributor since:
    14.10.2013
Projects
Add to BForms project
Stefan P.

Oana M.

Cezar C.

Marius C.

Add to RequireJSDotNet project
Stefan P.
Cezar C.
  public class GroupEditorViewModel
    {
        public GroupEditorModel Editor { get; set; }
    }

    public class GroupEditorModel
    {
        [BsEditorTab(Name = "Developers", Id = ContributorType.Developer, Selected = true, Editable = true)]
        public BsEditorTabModel<ContributorRowModel, ContributorSearchModel, ContributorNewModel> Developers { get; set; }

        [BsEditorTab(Name = "Testers", Id = ContributorType.Tester, Selected = false)]
        public ContributorsInheritExample Testers { get; set; }

        [BsEditorGroup(Id = GroupEditorProjects.BForms)]
        public BsEditorGroupModel<ContributorsGroupRowModel, ContributorsRowFormModel> BFormsProject { get; set; }

        [BsEditorGroup(Id = GroupEditorProjects.RequireJs)]
        public BsEditorGroupModel<ContributorsGroupRowModel> RequireJsProject { get; set; }

        public GroupFormModel Form { get; set; }
    }

    public class ContributorsInheritExample : BsEditorTabModel<ContributorRowModel>
    {
        public ContributorSearchModel Search { get; set; }
    }

    public class ContributorsGroupRowModel : BsEditorGroupItemModel<ContributorsRowFormModel>
    {
        public int Id { get; set; }
        public string Name { get; set; }

        public override object GetUniqueID()
        {
            return this.Id;
        }
    }

    public class ContributorsRowFormModel
    {
        [Display(Name = "Contributions")]
        [Required]
        [BsControl(BsControlType.TextBox)]
        public string Contributions { get; set; }
    }

    public class GroupFormModel
    {
        [BsControl(BsControlType.TextBox)]
        [Display(Name = "Name", Prompt = "Name", ResourceType = typeof(Resource))]
        [Required(ErrorMessageResourceName = "RequiredField", ErrorMessageResourceType = typeof(Resource))]
        public string Name { get; set; }
    }
            
@{

    var builder = Html.BsGroupEditorFor(x => x.Editor);

    builder.Theme = Html.GetTheme();
    
    builder.ConfigureTabs(cfg =>
    {
        var tab2 = cfg.For(x => x.Testers)
            .Template(x => x.Grid, "_TabItem")
            .Template(x => x.Search, "~/Areas/Demo/Views/Contributors/Toolbar/_Search.cshtml")
            .ConnectsWith(GroupEditorProjects.BForms);

        var tab1 = cfg.For(x => x.Developers)
            .Editable()
            .Template(x => x.Grid, "_TabItem")
            .Template(x => x.Search, "~/Areas/Demo/Views/Contributors/Toolbar/_Search.cshtml")
            .Template(x => x.New, "~/Areas/Demo/Views/Contributors/Toolbar/_New.cshtml")
            .ConnectsWith(GroupEditorProjects.BForms, GroupEditorProjects.RequireJs);

        tab1.BulkMove = true;
        tab1.For(x => x.Grid).Avatar(x => x.Name.DisplayValue.Contains("Marius") ?
                    "https://2.gravatar.com/avatar/50e73c9ac16439780dd040694880fe9d" : Url.Content("~/Content/Images/bg-user.png"));
        
        tab2.Toolbar.QuickSearch = true;
        tab2.For(x => x.Grid).Avatar(x => Url.Content("~/Content/Images/bg-user.png"));
        
        cfg.Title = Resource.DevTeam;

    })
        .ConfigureGroups(cfg =>
        {
            cfg.For(x => x.BFormsProject)
                .DisplayText(Resource.AddToBFormsProject)
                .DisplayName(Resource.BFormsProject)
                .Template(x => x.Items, "_GroupItem")
                .Template(x => x.Form, "_RowForm");

            cfg.For(x => x.RequireJsProject)
                .DisplayText(Resource.AddToRequireJsProject)
                .DisplayName(Resource.RequireJsProject)
                .Template(x => x.Items, "_GroupItem");

            cfg.Title = Resource.Projects;

            cfg.FormTemplate(Html.Partial("_GroupEditorForm", Model.Editor.Form));
        })
        .SaveUrl(Url.Action("Save"))
        .IgnoreAjaxRequest(false);
}

@Html.BsGroupEditorFor(Model, builder)


            

public class GroupEditorController : BaseController
{
    #region Ctor and Properties
    private readonly ContributorsRepository repo;

    public GroupEditorController()
    {
        repo = new ContributorsRepository(Db);
    }
    #endregion

    #region Pages
    public ActionResult Index()
    {
        var model = new GroupEditorModel()
        {
            Developers = new BsEditorTabModel<ContributorRowModel, ContributorSearchModel, ContributorNewModel>
            {
                Grid = repo.ToBsGridViewModel(new BsGridRepositorySettings<ContributorSearchModel>
                {
                    Page = 1,
                    PageSize = 5,
                    Search = new ContributorSearchModel
                    {
                        RolesFilter = new List<ProjectRole>() { ProjectRole.Developer, ProjectRole.TeamLeader }
                    }
                }),
                Search = repo.GetSearchForm(null),
                New = repo.GetNewForm()
            },

            Testers = new ContributorsInheritExample
            {
                Grid = repo.ToBsGridViewModel(new BsGridRepositorySettings<ContributorSearchModel>
                {
                    Page = 1,
                    PageSize = 5,
                    Search = new ContributorSearchModel
                    {
                        RolesFilter = new List<ProjectRole>() { ProjectRole.Tester }
                    }
                }),
                Search = repo.GetSearchForm(null)
            },

            BFormsProject = new BsEditorGroupModel<ContributorsGroupRowModel, ContributorsRowFormModel>
            {
                Items = new List<ContributorsGroupRowModel>()
                {
                    new ContributorsGroupRowModel
                    {
                        Id = 1,
                        Name = "Stefan P.",
                        TabId = ContributorType.Developer,
                        Form = new ContributorsRowFormModel()
                        {
                            Contributions = "concept, api design, razor helpers, documentation, c# bug fixing, testing"
                        }
                    },
                    new ContributorsGroupRowModel
                    {
                        Id = 6,
                        Name = "Oana M.",
                        TabId = ContributorType.Developer,
                        Form = new ContributorsRowFormModel()
                        {
                            Contributions = "UI & UX, css master"
                        }
                    },
                        new ContributorsGroupRowModel
                    {
                        Id = 3,
                        Name = "Cezar C.",
                        TabId = ContributorType.Developer,
                        Form = new ContributorsRowFormModel()
                        {
                            Contributions = "documentation, razor helpers"
                        }
                    },
                    new ContributorsGroupRowModel
                    {
                        Id = 4,
                        Name = "Marius C.",
                        TabId = ContributorType.Developer,
                        Form = new ContributorsRowFormModel()
                        {
                            Contributions = "js framework, datetime picker, automated tests for js"
                        }
                    }
                },
                Form = new ContributorsRowFormModel()
            },

            RequireJsProject = new BsEditorGroupModel<ContributorsGroupRowModel>
            {
                Items = new List<ContributorsGroupRowModel>()
                {
                    new ContributorsGroupRowModel
                    {
                        Id = 1,
                        Name = "Stefan P.",
                        TabId = ContributorType.Developer
                    },
                    new ContributorsGroupRowModel
                    {
                        Id = 3,
                        Name = "Cezar C.",
                        TabId = ContributorType.Developer
                    }
                }
            },
            Form = new GroupFormModel()
        };

        var viewModel = new GroupEditorViewModel
        {
            Editor = model
        };

        var options = new
        {
            getTabUrl = Url.Action("GetTab"),
            save = Url.Action("Save"),
            advancedSearchUrl = Url.Action("Search"),
            addUrl = Url.Action("New"),
            contributorType = RequireJsHtmlHelpers.ToJsonDictionary<ContributorType>(),
            projectRole = RequireJsHtmlHelpers.ToJsonDictionary<ProjectRole>()
        };

        RequireJsOptions.Add("index", options);

        return View(viewModel);
    }
    #endregion

    #region Ajax
    public BsJsonResult GetTab(BsEditorRepositorySettings<ContributorType> settings)
    {
        var msg = string.Empty;
        var status = BsResponseStatus.Success;
        var html = string.Empty;
        var count = 0;

        try
        {
            html = RenderTab(settings, out count);
        }
        catch (Exception ex)
        {
            msg = ex.Message;
            status = BsResponseStatus.ServerError;
        }

        return new BsJsonResult(new
        {
            Count = count,
            Html = html
        }, status, msg);
    }

    public BsJsonResult Save(GroupEditorModel model)
    {
        var errorMessage = "This is how a server error is displayed in group editor";

        return new BsJsonResult(new
        {
            Message = errorMessage
        },BsResponseStatus.ValidationError, "Server error");
    }

    public BsJsonResult Search(ContributorSearchModel model, ContributorType tabId)
    {
        var settings = new BsEditorRepositorySettings<ContributorType>
        {
            Search = model,
            TabId = tabId
        };

        var count = 0;

        var html = this.RenderTab(settings, out count);

        return new BsJsonResult(new
        {
            Count = count,
            Html = html
        });
    }

    public BsJsonResult New(ContributorNewModel model, ContributorType tabId)
    {
        var status = BsResponseStatus.Success;
        var row = string.Empty;
        var msg = string.Empty;

        try
        {
            if (ModelState.IsValid)
            {
                var rowModel = repo.Create(model);

                var groupEditorModel = new GroupEditorModel
                {
                    Developers = new BsEditorTabModel<ContributorRowModel, ContributorSearchModel, ContributorNewModel>
                    {
                        Grid = new BsGridModel<ContributorRowModel>
                        {
                            Items = new List<ContributorRowModel>
                            {
                                rowModel
                            }
                        }
                    }
                };

                var viewModel = new GroupEditorViewModel()
                {
                    Editor = groupEditorModel
                };

                row = this.BsRenderPartialView("_Editors", viewModel);

            }
            else
            {
                return new BsJsonResult(
                    new Dictionary<string, object> { { "Errors", ModelState.GetErrors() } },
                    BsResponseStatus.ValidationError);
            }
        }
        catch (Exception ex)
        {
            msg = Resource.ServerError;
            status = BsResponseStatus.ServerError;
        }

        return new BsJsonResult(new
        {
            Row = row
        }, status, msg);
    }
    #endregion

    #region Helpers
    [NonAction]
    public string RenderTab(BsEditorRepositorySettings<ContributorType> settings, out int count)
    {
        var html = string.Empty;
        count = 0;

        GroupEditorModel model = new GroupEditorModel();

        if (settings.Search == null)
        {
            settings.Search = new ContributorSearchModel();
        }

        switch (settings.TabId)
        {
            case ContributorType.Developer:

                ((ContributorSearchModel)settings.Search).RolesFilter = new List<ProjectRole>() { ProjectRole.Developer, ProjectRole.TeamLeader };
                    
                var gridDevelopers = repo.ToBsGridViewModel(settings.ToGridRepositorySettings<ContributorSearchModel>(), out count);
                   
                model.Developers = new BsEditorTabModel<ContributorRowModel, ContributorSearchModel, ContributorNewModel>
                {
                    Grid = gridDevelopers
                };
                    
                break;

            case ContributorType.Tester:

                ((ContributorSearchModel)settings.Search).RolesFilter = new List<ProjectRole>() { ProjectRole.Tester };

                var gridTesters = repo.ToBsGridViewModel(settings.ToGridRepositorySettings<ContributorSearchModel>(), out count);

                model.Testers = new ContributorsInheritExample
                {
                    Grid = gridTesters
                };
                break;
        }

        var viewModel = new GroupEditorViewModel()
        {
            Editor = model
        };

        html = this.BsRenderPartialView("_Editors", viewModel);

        return html;
    }
    #endregion
}
            
require([
        'singleton-ich',
        'bforms-groupEditor',
        'bforms-namespace',
        'bforms-initUI',
        'bforms-ajax',
        'main-script',
        'history-js'
], function (ichSingleton) {

    //#region Constructor and Properties
    var GroupEditorIndex = function (options) {
        this.options = $.extend(true, {}, options);
        this.init();
        this.renderer = ichSingleton.getInstance();
    };

    GroupEditorIndex.prototype.init = function () {
        $('#myGroupEditor').bsGroupEditor({
            getTabUrl: this.options.getTabUrl,
            groupBulkMoveConfirmShown: function () {},
            groupBulkMoveConfirm: false,
            groupBulkMoveConfirmContent: 'Are you sure ?',
            groupBulkMoveConfirmBtns: [{
                text: 'Yes',
                cssClass: 'btn-primary bs-confirm',
                callback: function () {
                    var editor = this.options.additionalData.groupEditor,
                        groupId = this.options.additionalData.groupId;
                    var additionalData = {
                        Test: "test"
                    };
                    editor.bulkMoveToGroup(groupId, additionalData);
                    this.hide();
                }
            }, {
                text: 'No',
                cssClass: 'btn-theme bs-cancel',
                callback: function (e) {
                    this.hide();
                }
            }],
            onTabItemAdd: function (e, response) {},
            buildDragHelper: function (model, tabId, connectsWith) {
                return $('<div class="col-lg-6 col-md-6 bs-itemContent" style="z-index:999"><span>' + model.Name + '</span></div>');
            },
            buildGroupItem: $.proxy(function (model, group, tabId, objId) {
                var view = this.renderer['js-groupItem'](model);
                return view;
            }, this),
            validateMove: function (model, tabId, $group) {
                if (model.Role == 1 && $group.data('groupid') == 4) return false;
            },
            onSaveSuccess: $.proxy(function () {
            }, this),
            initEditorForm: $.proxy(function ($form, uid, tabModel) {

                if (uid.indexOf('Search') != -1) {
                    this._initSearchForm($form, uid, tabModel.tabId);
                } else if (uid.indexOf('New') != -1) {
                    this._initAddForm($form, uid, tabModel.tabId);
                }

            }, this),
            validation: {
                required: {
                    unobtrusive: true,
                    message: "Please add at least an item."
                }
            }
        });
    };

    GroupEditorIndex.prototype._initSearchForm = function ($form, uid, tabId) {

        var rolesFilter = [],
            contributorType = this.options.contributorType,
            projectRole = this.options.projectRole;

        // this is useless, already filtered on server based on tabId
        if (tabId == contributorType.Developer) { 
            rolesFilter = [projectRole.Developer, projectRole.TeamLeader];
        } else if (tabId == contributorType.Tester) {
            rolesFilter = [projectRole.Tester]
        }

        $form.bsForm({
            uniqueName: 'searchForm',
            prefix: 'prefix' + uid + '.',
            actions: [
            {
                name: 'search',
                selector: '.js-btn-search',
                actionUrl: this.options.advancedSearchUrl,
                parse: true,
                getExtraData: $.proxy(function (data) {
                    
                    data.model = $.extend(true, {
                        RolesFilter: rolesFilter
                    }, data);
                    data.tabId = tabId;

                }, this),
                handler: $.proxy(function (formData, response) {
                    $('#myGroupEditor').bsGroupEditor('setTabContent', response.Html);
                }, this)
            }, {
                name: 'reset',
                selector: '.js-btn-reset',
                handler: $.proxy(function () {
                    $form.bsForm('reset');
                }, this)
            }]
        });
    };

    GroupEditorIndex.prototype._initAddForm = function ($form, uid, tabId) {

        $form.bsForm({
            uniqueName: 'addForm',
            prefix: 'prefix' + uid + '.',
            actions: [
            {
                name: 'add',
                selector: '.js-btn-save',
                actionUrl: this.options.addUrl,
                parse: true,
                validate: true,
                getExtraData: $.proxy(function (data) {

                    data.model = $.extend(true, {}, data);
                    data.tabId = tabId;

                }, this),
                handler: $.proxy(function (formData, response) {

                    var $row = $(response.Row).find('.bs-tabItem');

                    $('#myGroupEditor').bsGroupEditor('addTabItem', $row);

                }, this)
            }, {
                name: 'reset',
                selector: '.js-btn-reset',
                handler: $.proxy(function () {
                    $form.bsForm('reset');
                }, this)
            }]
        });
    };
    //#endregion

    //#region Dom Ready
    $(document).ready(function () {

        var ctrl = new GroupEditorIndex(window.requireConfig.pageOptions.index);

    });
    //#endregion
});
            
Loading...