示例#1
0
        public static Task Create(Core core, User creator, Primitive owner, string topic, string description, long dueTimestamp, TaskStatus status, byte percentComplete, TaskPriority priority)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            InsertQuery query = new InsertQuery("tasks");
            query.AddField("user_id", creator.UserId);
            query.AddField("task_item_id", owner.Id);
            query.AddField("task_item_type_id", owner.TypeId);
            query.AddField("task_topic", topic);
            query.AddField("task_description", description);
            query.AddField("task_due_date_ut", dueTimestamp);
            query.AddField("task_views", 0);
            query.AddField("task_comments", 0);
            query.AddField("task_category", 0);
            query.AddField("task_status", (byte)status);
            query.AddField("task_percent_complete", percentComplete);
            query.AddField("task_priority", (byte)priority);
            query.AddField("task_time_completed_ut", 0);

            long taskId = core.Db.Query(query);

            Task myTask = new Task(core, owner, taskId);

            //Access.CreateGrantForPrimitive(core, myTask, creator.ItemKey, "EDIT");

            /*if (Access.FriendsCanRead(myTask.Permissions))
            {
                core.CallingApplication.PublishToFeed(creator, "created a new task", string.Format("[iurl={0}]{1}[/iurl]",
                    Task.BuildTaskUri(core, myTask), myTask.Topic));
            }*/

            Access.CreateGrantForPrimitive(core, myTask, Task.GetAssigneeGroupKey(core), "EDIT");

            return myTask;
        }
示例#2
0
        public static void Show(Core core, TPage page, Primitive owner, long taskId)
        {
            core.Template.SetTemplate("Calendar", "viewcalendartask");

            try
            {
                Task calendarTask = new Task(core, owner, taskId);

                if (!calendarTask.Access.Can("VIEW"))
                {
                    core.Functions.Generate403();
                    return;
                }

                if (calendarTask.Calendar.Access.Can("CREATE_TASKS"))
                {
                    core.Template.Parse("U_NEW_TASK", core.Hyperlink.BuildAccountSubModuleUri(owner, "calendar", "new-task", true,
                        string.Format("year={0}", core.Tz.Now.Year),
                        string.Format("month={0}", core.Tz.Now.Month),
                        string.Format("day={0}", core.Tz.Now.Day)));
                }

                if (calendarTask.Access.Can("EDIT"))
                {
                    core.Template.Parse("U_EDIT_TASK", core.Hyperlink.BuildAccountSubModuleUri(owner, "calendar", "new-task", "edit", taskId, true));
                }

                /* pages */
                core.Display.ParsePageList(owner, true);

                core.Template.Parse("PAGE_TITLE", calendarTask.Topic);

                core.Template.Parse("TOPIC", calendarTask.Topic);
                core.Template.Parse("DESCRIPTION", calendarTask.Description);
                core.Template.Parse("DUE_DATE", calendarTask.GetDueTime(core.Tz).ToString());

                List<string[]> calendarPath = new List<string[]>();

                calendarPath.Add(new string[] { "calendar", core.Prose.GetString("CALENDAR") });
                calendarPath.Add(new string[] { "*tasks", core.Prose.GetString("TASKS") });
                calendarPath.Add(new string[] { "task/" + calendarTask.TaskId.ToString(), calendarTask.Topic });

                owner.ParseBreadCrumbs(calendarPath);
            }
            catch (InvalidTaskException)
            {
                core.Display.ShowMessage("Invalid submission", "You have made an invalid form submission.");
            }
        }
示例#3
0
 public static string BuildTaskUri(Core core, Task calendarTask)
 {
     return core.Hyperlink.AppendSid(string.Format("{0}calendar/task/{1}",
         calendarTask.owner.UriStub, calendarTask.TaskId));
 }
示例#4
0
 public static string BuildTaskMarkCompleteUri(Core core, Task calendarTask)
 {
     return core.Hyperlink.BuildAccountSubModuleUri("calendar", "mark-complete", calendarTask.Id, true);
 }
        void AccountCalendarTaskNew_Show(object sender, EventArgs e)
        {
            SetTemplate("account_calendar_task_new");

            bool edit = false;

            if (core.Http.Query["mode"] == "edit")
            {
                edit = true;
            }

            DateTimePicker dueDateTimePicker = new DateTimePicker(core, "due-date");
            dueDateTimePicker.ShowTime = true;
            dueDateTimePicker.ShowSeconds = false;

            int year = core.Functions.RequestInt("year", tz.Now.Year);
            int month = core.Functions.RequestInt("month", tz.Now.Month);
            int day = core.Functions.RequestInt("day", tz.Now.Day);

            byte percentComplete = 0;
            TaskPriority priority = TaskPriority.Normal;

            DateTime dueDate = new DateTime(year, month, day, 17, 0, 0);

            string topic = string.Empty;
            string description = string.Empty;

            Dictionary<string, string> percentages = new Dictionary<string, string>();
            for (int i = 0; i <= 100; i += 25)
            {
                percentages.Add(i.ToString(), i.ToString() + "%");
            }

            Dictionary<string, string> priorities = new Dictionary<string, string>();
            priorities.Add(((byte)TaskPriority.Low).ToString(), "Low");
            priorities.Add(((byte)TaskPriority.Normal).ToString(), "Normal");
            priorities.Add(((byte)TaskPriority.High).ToString(), "High");

            if (edit)
            {
                int id = core.Functions.RequestInt("id", -1);

                if (id < 1)
                {
                    DisplayGenericError();
                }

                try
                {
                    Task calendarTask = new Task(core, Owner, id);

                    template.Parse("EDIT", "TRUE");
                    template.Parse("ID", calendarTask.TaskId.ToString());

                    dueDate = calendarTask.GetDueTime(core.Tz);

                    topic = calendarTask.Topic;
                    description = calendarTask.Description;

                    percentComplete = calendarTask.PercentageComplete;
                    priority = calendarTask.Priority;
                }
                catch
                {
                    core.Display.ShowMessage("Invalid", "If you have stumbled onto this page by mistake, click back in your browser.");
                }
            }

            dueDateTimePicker.Value = dueDate;

            template.Parse("S_YEAR", year.ToString());
            template.Parse("S_MONTH", month.ToString());
            template.Parse("S_DAY", day.ToString());

            template.Parse("S_DUE_DATE", dueDateTimePicker);

            template.Parse("S_TOPIC", topic);
            template.Parse("S_DESCRIPTION", description);

            ParseSelectBox("S_PERCENT_COMPLETE", "percent-complete", percentages, percentComplete.ToString());
            ParseSelectBox("S_PRIORITY", "priority", priorities, ((byte)priority).ToString());

            Save(new EventHandler(AccountCalendarTaskNew_Save));
        }
        void AccountCalendarTaskNew_Save(object sender, EventArgs e)
        {
            long taskId = 0;
            string topic = string.Empty;
            string description = string.Empty;
            byte percentComplete = core.Functions.FormByte("percent-complete", 0);
            TaskPriority priority = (TaskPriority)core.Functions.FormByte("priority", (byte)TaskPriority.Normal);
            long dueDate = tz.GetUnixTimeStamp(tz.Now);
            bool edit = false;

            AuthoriseRequestSid();

            if (core.Http.Form["mode"] == "edit")
            {
                edit = true;
            }

            try
            {
                topic = core.Http.Form["topic"];
                description = core.Http.Form["description"];

                dueDate = DateTimePicker.FormDate(core, "due-date");

                if (edit)
                {
                    taskId = long.Parse(core.Http.Form["id"]);
                }
            }
            catch
            {
                core.Display.ShowMessage("Invalid submission", "You have made an invalid form submission.");
                return;
            }

            if (description == null)
            {
                description = string.Empty;
            }

            if (!edit)
            {
                TaskStatus status = TaskStatus.Future;

                if (percentComplete == 100)
                {
                    status = TaskStatus.Completed;
                }

                Task calendarTask = Task.Create(core, LoggedInMember, Owner, topic, description, dueDate, status, percentComplete, priority);

                SetRedirectUri(Task.BuildTaskUri(core, calendarTask));
                core.Display.ShowMessage("Task Created", "You have successfully created a new task.");
            }
            else
            {
                if (!Access.Can("EDIT_TASKS"))
                {
                    core.Display.ShowMessage("Unauthorised", "You are unauthorised to edit this task.");
                }

                TaskStatus status = TaskStatus.Future;

                if (percentComplete == 100)
                {
                    status = TaskStatus.Completed;
                }

                UpdateQuery query = new UpdateQuery("tasks");
                query.AddField("task_topic", topic);
                query.AddField("task_description", description);
                query.AddField("task_due_date_ut", dueDate);
                query.AddField("task_percent_complete", percentComplete);
                query.AddField("task_status", (byte)status);
                query.AddField("task_priority", (byte)priority);
                query.AddCondition("user_id", LoggedInMember.UserId);
                query.AddCondition("task_id", taskId);

                db.Query(query);

                Task calendarTask = new Task(core, Owner, taskId);

                SetRedirectUri(Task.BuildTaskUri(core, calendarTask));
                core.Display.ShowMessage("Task Saved", "You have successfully saved your changes to the task.");
            }
        }
        void AccountCalendarTaskMarkComplete_Show(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long taskId = core.Functions.FormLong("id", 0);
            bool isAjax = false;

            if (core.Http["ajax"] == "true")
            {
                isAjax = true;
            }

            try
            {
                Task task = new Task(core, session.LoggedInMember, taskId);

                UpdateQuery query = new UpdateQuery("tasks");
                query.AddField("task_status", (byte)TaskStatus.Completed);
                query.AddField("task_percent_complete", 100);
                query.AddField("task_time_completed_ut", UnixTime.UnixTimeStamp());
                query.AddCondition("user_id", core.LoggedInMemberId);
                query.AddCondition("task_id", taskId);

                if (db.Query(query) == 1)
                {
                    if (!isAjax)
                    {
                        SetRedirectUri(Task.BuildTaskUri(core, task));
                    }
                    core.Response.ShowMessage("success", "Task Complete", "The task has been marked as complete.");
                }
            }
            catch (InvalidTaskException)
            {
                core.Response.ShowMessage("error", "Error", "An error occured while marking the task as complete, go back");
            }
        }