summaryrefslogtreecommitdiff
path: root/addons/note/static/src/js
diff options
context:
space:
mode:
authorDharmang Soni <dpr@openerp.com>2018-04-04 15:34:43 +0530
committerThibault Delavallée <tde@odoo.com>2018-04-09 14:35:06 +0200
commit807c4c3f5e729d8b2f463d93e73b0dbbc008492b (patch)
treedc6774487c50efbd6c09b5ae642744582b3fe260 /addons/note/static/src/js
parentc56491b11bc399247a595a2e08bbc940d2be3746 (diff)
[REF] mail, note: move reminder feature from mail to note
This commit refactors f488dc58c37fdc7fd49df759165de641e213444b that added reminder feature in activities. After merging it was suggested specifications were not correct and it has been decided to move the whole reminder feature in note. Reminders are now notes instead of activities. Now when having note appµ systray proposes to create a note / reminder. A note.note record is created with info given by the user. If a date is given in the systray quick create then an activity is scheduled on this note. This means user can create records in activity systray that are not activities but notes used as reminders. Those will use the first availableµ note column for the user. As reminders are now notes the support of activities not linked to any document is removed, as well as archiving activities and tests linked to that behavior. This commit has been not carefully tested nor in-depth reviewied. It is considered as too important for the upcoming freeze. This closes task ID 1833628. Closes #24129 . Many thanks to @dpr-odoo for its quick development and good work on this task.
Diffstat (limited to 'addons/note/static/src/js')
-rw-r--r--addons/note/static/src/js/systray.js138
1 files changed, 138 insertions, 0 deletions
diff --git a/addons/note/static/src/js/systray.js b/addons/note/static/src/js/systray.js
new file mode 100644
index 00000000000..54a2fe6bdd1
--- /dev/null
+++ b/addons/note/static/src/js/systray.js
@@ -0,0 +1,138 @@
+odoo.define('note.systray', function (require) {
+"use strict";
+
+var core = require('web.core');
+var ActivityMenu = require('mail.systray').ActivityMenu;
+var datepicker = require('web.datepicker');
+
+var _t = core._t;
+
+ActivityMenu.include({
+ events: _.extend({}, ActivityMenu.prototype.events, {
+ 'click .o_note_show': '_onAddNoteClick',
+ 'click .o_note_save': '_onNoteSaveClick',
+ 'click .o_note_set_datetime': '_onNoteDateTimeSetClick',
+ 'keydown input.o_note_input': '_onNoteInputKeyDown',
+ 'click .o_note': '_onNewNoteClick',
+ }),
+ //--------------------------------------------------
+ // Private
+ //--------------------------------------------------
+ /**
+ * Moving notes at first place
+ * @override
+ */
+ _getActivityData: function () {
+ var self = this;
+ return this._super.apply(this, arguments).then(function() {
+ var reminderIndex = _.findIndex(self.activities, function (val) { return val.model == 'note.note'; });
+ if (reminderIndex > 0) {
+ self.activities.splice(0, 0, self.activities.splice(reminderIndex, 1)[0]);
+ }
+ });
+ },
+ /**
+ * Save the note to database using datepicker date and field as note
+ * @private
+ */
+ _saveNote: function () {
+ var note = this.$('.o_note_input').val().trim();
+ if (! note) {
+ return;
+ }
+ var params = {'note': note};
+ var noteDateTime = this.noteDateTimeWidget.getValue();
+ if (noteDateTime) {
+ params = _.extend(params, {'date_deadline': noteDateTime});
+ }
+ this.$('.o_note_show').removeClass('hidden');
+ this.$('.o_note').addClass('hidden');
+ this._rpc({
+ route: '/note/new',
+ params: params,
+ }).then(this._updateActivityPreview.bind(this));
+ },
+ //-----------------------------------------
+ // Handlers
+ //-----------------------------------------
+ /**
+ * @override
+ */
+ _onActivityFilterClick: function (ev) {
+ var $el = $(ev.currentTarget);
+ if(!$el.hasClass("o_note")) {
+ var data = _.extend({}, $el.data(), $(ev.target).data());
+ if (data.res_model === "note.note" && data.filter === "my") {
+ this.do_action({
+ type: 'ir.actions.act_window',
+ name: data.model_name,
+ res_model: data.res_model,
+ views: [[false, 'kanban'], [false, 'form'], [false, 'list']]
+ });
+ } else {
+ this._super.apply(this, arguments);
+ }
+ }
+ },
+ /**
+ * When add new note button clicked, toggling quick note create view inside
+ * Systray activity view
+ *
+ * @private
+ * @param {MouseEvent} ev
+ */
+ _onAddNoteClick: function (ev) {
+ ev.stopPropagation();
+ if (!this.noteDateTimeWidget){
+ this.noteDateTimeWidget = new datepicker.DateWidget(this, {useCurrent: true});
+ }
+ this.noteDateTimeWidget.appendTo(this.$('.o_note_datetime'));
+ this.noteDateTimeWidget.$input.attr('placeholder', _t("Today"));
+ this.$('.o_note_show, .o_note').toggleClass('hidden');
+ this.$('.o_note_input').val('').focus();
+
+ },
+ /**
+ * When focusing on input for new quick note systerm tray must be open.
+ * Preventing to close
+ *
+ * @private
+ * @param {MouseEvent} ev
+ */
+ _onNewNoteClick: function (ev) {
+ ev.stopPropagation();
+ },
+ /**
+ * Opens datetime picker for note.
+ * Quick FIX due to no option for set custom icon instead of caret in datepicker.
+ *
+ * @private
+ * @param {MouseEvent} ev
+ */
+ _onNoteDateTimeSetClick: function (ev) {
+ ev.preventDefault();
+ ev.stopPropagation();
+ this.noteDateTimeWidget.$input.click();
+ },
+ /**
+ * Saving note (quick create) and updating activity preview
+ *
+ * @private
+ * @param {MouseEvent} ev
+ */
+ _onNoteSaveClick: function (ev) {
+ this._saveNote();
+ },
+ /**
+ * Handling Enter key for quick create note.
+ *
+ * @private
+ * @param {KeyboardEvent} ev
+ */
+ _onNoteInputKeyDown: function (ev) {
+ if (ev.which === $.ui.keyCode.ENTER) {
+ this._saveNote();
+ }
+ },
+});
+});