Esempio n. 1
0
        public override void Init(System.Html.Element element, Func <object> valueAccessor, Func <System.Collections.Dictionary> allBindingsAccessor, object viewModel, object context)
        {
            string       formatString = GetFormatString();
            jQueryObject container    = jQuery.FromElement(element);

            jQueryObject inputField   = container.Find(".sparkle-input-timeofday-part");
            jQueryObject selectButton = container.Find(".sparkle-input-timeofday-button-part");

            AutoCompleteOptions options = XrmTimeEditor.GetTimePickerAutoCompleteOptions(formatString);

            options.Position = new Dictionary <string, object>("collision", "fit");
            options.Select   = delegate(jQueryEvent e, AutoCompleteSelectEvent uiEvent)
            {
                // Note we assume that the binding has added an array of string items
                string value = ((Dictionary)uiEvent.Item)["value"].ToString();

                TrySetObservable(valueAccessor, inputField, value);
            };

            inputField = inputField.Plugin <AutoCompleteObject>().AutoComplete(options);


            // Add the click binding to show the drop down
            selectButton.Click(delegate(jQueryEvent e)
            {
                inputField.Plugin <AutoCompleteObject>().AutoComplete(AutoCompleteMethod.Search, ""); // Give "" to show all items
            });
            //// Set initial value
            //Observable<DateTime> dateValueAccessor = (Observable<DateTime>)valueAccessor();
            //DateTime intialValue = dateValueAccessor.GetValue();
            //FormatterUpdate(inputField, intialValue);

            //handle the field changing
            KnockoutUtils.RegisterEventHandler(inputField.GetElement(0), "change", delegate(object sender, EventArgs e)
            {
                string value = inputField.GetValue();
                TrySetObservable(valueAccessor, inputField, value);
            });

            Action disposeCallBack = delegate()
            {
                Script.Literal("$({0}).autocomplete(\"destroy\")", element);
            };

            //handle disposal (if KO removes by the template binding)
            Script.Literal("ko.utils.domNodeDisposal.addDisposeCallback({0}, {1})", element, (object)disposeCallBack);

            // Note: Because the time picker is always part of the date picker - we don't need to display validation messages
            //Knockout.BindingHandlers["validationCore"].Init(element, valueAccessor, allBindingsAccessor, null, null);
        }
        public static void Init()
        {
            PageEx.MajorVersion = 2013;

            jQuery.OnDocumentReady(delegate()
            {
                ValidationApi.RegisterExtenders();

                // Init settings
                OrganizationServiceProxy.GetUserSettings();
                SimpleEditableGridViewModel vm = new SimpleEditableGridViewModel();

                // Create Grid
                GridDataViewBinder dataViewBinder      = new GridDataViewBinder();
                dataViewBinder.AddCheckBoxSelectColumn = true;
                dataViewBinder.SelectActiveRow         = true;
                dataViewBinder.MultiSelect             = false;
                List <Column> columns    = new List <Column>();
                EditorFactory textEditor = (EditorFactory)Script.Literal("Slick.Editors.Text");

                XrmTextEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Title", 150, "title"));
                XrmTextEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Author", 150, "author"));
                XrmDateEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Published", 150, "publishdate"), true);
                XrmMoneyEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Price", 150, "price"), 0, 100);
                XrmNumberEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Copies", 150, "numberofcopies"), 0, 1000, 0);
                XrmLookupEditorOptions languageLookupOptions =
                    (XrmLookupEditorOptions)XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Language", 150, "language"), vm.GetLanguages, "id", "name", null).Options;
                languageLookupOptions.showImage = false;

                OptionSetBindingOptions formatBindingOptions = new OptionSetBindingOptions();
                formatBindingOptions.allowEmpty            = true;
                formatBindingOptions.GetOptionSetsDelegate = vm.GetFormats;

                XrmOptionSetEditor.BindColumnWithOptions(GridDataViewBinder.AddColumn(columns, "Format", 150, "format"), formatBindingOptions);
                XrmDurationEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Audio Length", 150, "audiolength"));
                XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Start Time", 150, "starttime"));

                Grid grid = dataViewBinder.DataBindXrmGrid(vm.Books, columns, "booksGridContainer", null, true, true);
                ViewBase.RegisterViewModel(vm);

                Window.SetTimeout(delegate()
                {
                    vm.LoadBooks();
                    grid.ResizeCanvas();
                }, 0);
            });
        }
Esempio n. 3
0
        public static void SetUpGrids(TimeSheetViewModel vm)
        {
            // Create Timesheet Grid
            DataViewBase daysDataView = vm.Days;

            List <Column> columns = new List <Column>();

            GridDataViewBinder.BindRowIcon(GridDataViewBinder.AddColumn(columns, "", 50, "icon"), "activity");
            XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Account", 300, "account"), vm.AccountSeachCommand, "accountid", "name", null);
            XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Regarding", 300, "regardingObjectId"), vm.RegardingObjectSearchCommand, "id", "displayName", null);
            XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Activity", 300, "activity"), vm.ActivitySearchCommand, "activityid", "subject", "activitytypecode");

            string[] daysOfWeek     = new string[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
            int      firstDayOfWeek = OrganizationServiceProxy.OrganizationSettings.WeekStartDayCode.Value.Value;

            GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek], 50, "day0");
            GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 1], 50, "day1");
            GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 2], 50, "day2");
            GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 3], 50, "day3");
            GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 4], 50, "day4");
            GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 5], 50, "day5");
            GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 6], 50, "day6");

            GridDataViewBinder daysDataBinder = new GridDataViewBinder();

            daysDataBinder.SelectActiveRow         = true;
            daysDataBinder.AddCheckBoxSelectColumn = false;
            daysGrid = daysDataBinder.DataBindXrmGrid(daysDataView, columns, "timesheetGridContainer", null, true, true);

            // Set the totals row meta data
            daysDataView.OnGetItemMetaData += delegate(object item)
            {
                ItemMetaData metaData = new ItemMetaData();
                DayEntry     day      = (DayEntry)item;
                if (day != null && day.isTotalRow)
                {
                    metaData.Editor               = delegate(EditorArguments args) { return(null); };
                    metaData.Columns              = new Dictionary <object, Column>();
                    metaData.Columns["Account"]   = new Column("editor", null);
                    metaData.Columns["Regarding"] = new Column("editor", null);
                    metaData.Columns["Activity"]  = new Column("editor", null);
                    metaData.Formatter            = delegate(int row, int cell, object value, Column columnDef, object dataContext)
                    {
                        switch (columnDef.Field)
                        {
                        case "account":
                        case "regardingObjectId":
                            return("");

                        case "activity":
                            return("Total");

                        default:
                            return(XrmDurationEditor.Formatter(row, cell, value, columnDef, dataContext));
                        }
                    };

                    metaData.CssClasses = "days_total_row";
                }

                else
                {
                    metaData.Formatter = delegate(int row, int cell, object value, Column columnDef, object dataContext)
                    {
                        switch (columnDef.Field)
                        {
                        case "account":
                        case "regardingObjectId":
                        case "activity":
                            return(XrmLookupEditor.Formatter(row, cell, value, columnDef, dataContext));

                        default:
                            return(XrmDurationEditor.Formatter(row, cell, value, columnDef, dataContext));
                        }
                    };
                }

                return(metaData);
            };

            daysDataBinder.DataBindSelectionModel(daysGrid, daysDataView);


            // ---------------------------------------
            // Sessions Grid
            // ---------------------------------------
            DataViewBase sessionsDataView = vm.SessionDataView;

            List <Column> sessionGridCols = new List <Column>();

            GridDataViewBinder.AddEditIndicatorColumn(sessionGridCols);

            XrmTextEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Activity", 300, "activitypointer_subject")).Editor = null;



            XrmDateEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Date", 100, "dev1_starttime"), true);

            XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Start", 100, "dev1_starttime")).Validator =
                delegate(object value, object item)
            {
                dev1_session     session      = (dev1_session)item;
                DateTime         newStartTime = (DateTime)value;
                ValidationResult result       = new ValidationResult();

                if (session.dev1_EndTime != null)
                {
                    result.Valid = true;
                    string valueText = (string)value;
                    // Check if the end time is before the start time

                    bool isValid = DateTimeEx.GetTimeDuration(newStartTime) < DateTimeEx.GetTimeDuration(session.dev1_EndTime);

                    result.Valid   = isValid;
                    result.Message = "The start time must be before the end time";
                }
                else
                {
                    result.Valid = true;
                }
                return(result);
            };

            XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "End", 100, "dev1_endtime")).Validator =
                delegate(object value, object item)
            {
                dev1_session session    = (dev1_session)item;
                DateTime     newEndTime = (DateTime)value;

                ValidationResult result = new ValidationResult();

                if (session.dev1_StartTime != null)
                {
                    result.Valid = true;
                    string valueText = (string)value;
                    // Check if the end time is before the start time

                    bool isValid = DateTimeEx.GetTimeDuration(session.dev1_StartTime) < DateTimeEx.GetTimeDuration(newEndTime);

                    result.Valid   = isValid;
                    result.Message = "The end time must be after the start time";
                }
                else
                {
                    result.Valid = true;
                }

                return(result);
            };


            XrmDurationEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Duration", 70, "dev1_duration"));
            XrmTextEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Description", 300, "dev1_description"));


            GridDataViewBinder sessionsDataBinder = new GridDataViewBinder();

            sessionsDataBinder.SelectActiveRow         = false;
            sessionsDataBinder.AddCheckBoxSelectColumn = true;

            sessionsGrid = sessionsDataBinder.DataBindXrmGrid(sessionsDataView, sessionGridCols, "sessionsGridContainer", null, true, true);

            sessionsGrid.OnBeforeEditCell.Subscribe(delegate(EventData e, object args)
            {
                // Stop the row from being edited if locked
                Entity item = (Entity)((EditEventData)args).item;
                bool result = sessionsDataView.OnBeforeEdit(item);
                Script.Literal("return {0}", result);
            });

            daysGrid.OnActiveCellChanged.Subscribe(delegate(EventData e, object args)
            {
                CellSelection activeCell = daysGrid.GetActiveCell();
                if (activeCell != null)
                {
                    if (activeCell.Cell < StartDaysColumnIndex)
                    {
                        // Whole activity is selected
                        vm.Days.SelectedDay = null;
                    }
                    else
                    {
                        vm.Days.SelectedDay = activeCell.Cell - (StartDaysColumnIndex - 1);
                    }
                }
            });
        }
Esempio n. 4
0
        public static void SetUpGrids(TimeSheetViewModel vm)
        {
            GridOptions daysGridOpts = new GridOptions();

            daysGridOpts.EnableCellNavigation = true;
            daysGridOpts.EnableColumnReorder  = false;
            daysGridOpts.AutoEdit             = false;
            daysGridOpts.Editable             = true;
            daysGridOpts.RowHeight            = 20;
            daysGridOpts.HeaderRowHeight      = 25;
            daysGridOpts.ForceFitColumns      = false;
            daysGridOpts.EnableAddRow         = true;



            // Create Timesheet Grid
            DataViewBase daysDataView = vm.Days;

            List <Column> columns = new List <Column>();

            GridDataViewBinder.BindRowIcon(GridDataViewBinder.AddColumn(columns, "", 50, "icon"), "activity");
            XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Activity", 300, "activity"), vm.ActivitySearchCommand, "activityid", "subject", "activitytypecode");

            GridDataViewBinder.AddColumn(columns, "Mon", 50, "day0");
            GridDataViewBinder.AddColumn(columns, "Tue", 50, "day1");
            GridDataViewBinder.AddColumn(columns, "Wed", 50, "day2");
            GridDataViewBinder.AddColumn(columns, "Thu", 50, "day3");
            GridDataViewBinder.AddColumn(columns, "Fri", 50, "day4");
            GridDataViewBinder.AddColumn(columns, "Sat", 50, "day5");
            GridDataViewBinder.AddColumn(columns, "Sun", 50, "day6");

            daysGrid = new Grid("#timesheetGridContainer", daysDataView, columns, daysGridOpts);

            GridDataViewBinder daysDataBinder = new GridDataViewBinder();

            daysDataBinder.DataBindEvents(daysGrid, daysDataView, "timesheetGridContainer");

            // Set the totals row meta data
            daysDataView.OnGetItemMetaData += delegate(object item)
            {
                DayEntry day = (DayEntry)item;
                if (day != null && day.isTotalRow)
                {
                    ItemMetaData metaData = new ItemMetaData();
                    metaData.Editor    = null;
                    metaData.Formatter = delegate(int row, int cell, object value, Column columnDef, object dataContext)
                    {
                        if (columnDef.Field == "activity")
                        {
                            return("Total");
                        }
                        else
                        {
                            return(Formatters.DefaultFormatter(row, cell, value, columnDef, dataContext));
                        }
                    };
                    metaData.CssClasses = "days_total_row";
                    return(metaData);
                }

                else
                {
                    return(null);
                }
            };

            daysDataBinder.DataBindSelectionModel(daysGrid, daysDataView);


            // ---------------------------------------
            // Sessions Grid
            // ---------------------------------------
            DataViewBase sessionsDataView = vm.SessionDataView;

            List <Column> sessionGridCols = new List <Column>();

            GridDataViewBinder.AddEditIndicatorColumn(sessionGridCols);

            XrmTextEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Description", 200, "dev1_description"));

            XrmDateEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Date", 200, "dev1_starttime"), true);

            XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Start", 100, "dev1_starttime")).Validator =
                delegate(object value, object item)
            {
                dev1_session     session      = (dev1_session)item;
                DateTime         newStartTime = (DateTime)value;
                ValidationResult result       = new ValidationResult();

                if (session.dev1_EndTime != null)
                {
                    result.Valid = true;
                    string valueText = (string)value;
                    // Check if the end time is before the start time

                    bool isValid = DateTimeEx.GetTimeDuration(newStartTime) < DateTimeEx.GetTimeDuration(session.dev1_EndTime);

                    result.Valid   = isValid;
                    result.Message = "The start time must be before the end time";
                }
                else
                {
                    result.Valid = true;
                }
                return(result);
            };

            XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "End", 100, "dev1_endtime")).Validator =
                delegate(object value, object item)
            {
                dev1_session session    = (dev1_session)item;
                DateTime     newEndTime = (DateTime)value;

                ValidationResult result = new ValidationResult();

                if (session.dev1_StartTime != null)
                {
                    result.Valid = true;
                    string valueText = (string)value;
                    // Check if the end time is before the start time

                    bool isValid = DateTimeEx.GetTimeDuration(session.dev1_StartTime) < DateTimeEx.GetTimeDuration(newEndTime);

                    result.Valid   = isValid;
                    result.Message = "The end time must be after the start time";
                }
                else
                {
                    result.Valid = true;
                }

                return(result);
            };


            XrmDurationEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Duration", 200, "dev1_duration"));



            GridDataViewBinder sessionsDataBinder = new GridDataViewBinder();

            sessionsGrid = sessionsDataBinder.DataBindXrmGrid(sessionsDataView, sessionGridCols, "sessionsGridContainer", null, true, true);
            sessionsDataBinder.DataBindSelectionModel(sessionsGrid, sessionsDataView);


            daysGrid.OnActiveCellChanged.Subscribe(delegate(EventData e, object args)
            {
                CellSelection activeCell = daysGrid.GetActiveCell();
                if (activeCell != null)
                {
                    if (activeCell.Cell < 2)
                    {
                        // Whole activity is selected
                        vm.Days.SelectedDay = null;
                    }
                    else
                    {
                        vm.Days.SelectedDay = activeCell.Cell - 1;
                    }
                }
            });
        }