Improve note button
* Add resources method to ModelStorage * Support badge on icon * Display unread and total of notes * Add two extra colors for icon issue8122 review70561002
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
* Display unread and total of notes
|
||||
* Use resources method
|
||||
* Rename roundup.url configuration to bug.url
|
||||
* Use separate XML parser in Views
|
||||
* Add range selection with Shift-click
|
||||
|
||||
+1
-1
@@ -2736,7 +2736,7 @@
|
||||
},
|
||||
_convert: function(data) {
|
||||
var xml = jQuery.parseXML(data);
|
||||
jQuery(xml).find('svg').attr('fill', Sao.config.icon_color);
|
||||
jQuery(xml).find('svg').attr('fill', Sao.config.icon_colors[0]);
|
||||
data = new XMLSerializer().serializeToString(xml);
|
||||
var blob = new Blob([data],
|
||||
{type: 'image/svg+xml'});
|
||||
|
||||
+11
-41
@@ -494,8 +494,7 @@
|
||||
this._loaded = {};
|
||||
this.fields = {};
|
||||
this._timestamp = null;
|
||||
this.attachment_count = -1;
|
||||
this.unread_note = -1;
|
||||
this.resources = null;
|
||||
this.button_clicks = {};
|
||||
this.state_attrs = {};
|
||||
this.autocompletion = {};
|
||||
@@ -1270,46 +1269,17 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
get_attachment_count: function(reload) {
|
||||
var prm = jQuery.Deferred();
|
||||
if (this.id < 0) {
|
||||
prm.resolve(0);
|
||||
return prm;
|
||||
}
|
||||
if ((this.attachment_count < 0) || reload) {
|
||||
prm = Sao.rpc({
|
||||
method: 'model.ir.attachment.search_count',
|
||||
params: [
|
||||
[['resource', '=', this.model.name + ',' + this.id]],
|
||||
this.get_context()]
|
||||
}, this.model.session).then(function(count) {
|
||||
this.attachment_count = count;
|
||||
return count;
|
||||
}.bind(this));
|
||||
get_resources: function(reload) {
|
||||
var prm;
|
||||
if ((this.id >= 0) && (!this.resources || reload)) {
|
||||
prm = this.model.execute(
|
||||
'resources', [this.id], this.get_context())
|
||||
.then(function(resources) {
|
||||
this.resources = resources;
|
||||
return resources;
|
||||
}.bind(this));
|
||||
} else {
|
||||
prm.resolve(this.attachment_count);
|
||||
}
|
||||
return prm;
|
||||
},
|
||||
get_unread_note: function(reload) {
|
||||
var prm = jQuery.Deferred();
|
||||
if (this.id < 0) {
|
||||
prm.resolve(0);
|
||||
return prm;
|
||||
}
|
||||
if ((this.unread_note < 0) || reload) {
|
||||
prm = Sao.rpc({
|
||||
method: 'model.ir.note.search_count',
|
||||
params: [
|
||||
[['resource', '=', this.model.name + ',' + this.id],
|
||||
['unread', '=', true]],
|
||||
this.get_context()]
|
||||
}, this.model.session).then(function(count) {
|
||||
this.unread_note = count;
|
||||
return count;
|
||||
}.bind(this));
|
||||
} else {
|
||||
prm.resolve(this.unread_note);
|
||||
prm = jQuery.when(this.resources);
|
||||
}
|
||||
return prm;
|
||||
},
|
||||
|
||||
+1
-1
@@ -246,7 +246,7 @@ var Sao = {};
|
||||
Sao.config.display_size = 20;
|
||||
Sao.config.bug_url = 'https://bugs.tryton.org/';
|
||||
Sao.config.title = 'Tryton';
|
||||
Sao.config.icon_color = '#3465a4';
|
||||
Sao.config.icon_colors = '#3465a4,#555753,#cc0000'.split(',');
|
||||
Sao.config.bus_timeout = 10 * 60 * 1000;
|
||||
|
||||
Sao.i18n = i18n();
|
||||
|
||||
+3
-6
@@ -1185,13 +1185,10 @@
|
||||
}
|
||||
if (this.tab) {
|
||||
if (record) {
|
||||
record.get_attachment_count().always(
|
||||
this.tab.attachment_count.bind(this.tab));
|
||||
record.get_unread_note().always(
|
||||
this.tab.update_unread_note.bind(this.tab));
|
||||
record.get_resources().always(
|
||||
this.tab.update_resources.bind(this.tab));
|
||||
} else {
|
||||
this.tab.attachment_count(0);
|
||||
this.tab.update_unread_note(0);
|
||||
this.tab.update_resources();
|
||||
}
|
||||
this.tab.record_message();
|
||||
}
|
||||
|
||||
+62
-53
@@ -1022,7 +1022,7 @@
|
||||
attach: function(evt) {
|
||||
var window_ = function() {
|
||||
return new Sao.Window.Attachment(record, function() {
|
||||
this.update_attachment_count(true);
|
||||
this.refresh_resources(true);
|
||||
}.bind(this));
|
||||
}.bind(this);
|
||||
var dropdown = this.buttons.attach.parents('.dropdown');
|
||||
@@ -1140,7 +1140,7 @@
|
||||
}
|
||||
|
||||
var window_ = new Sao.Window.Attachment(record, function() {
|
||||
this.update_attachment_count(true);
|
||||
this.refresh_resources(true);
|
||||
}.bind(this));
|
||||
files.forEach(function(file) {
|
||||
Sao.common.get_file_data(file, function(data, filename) {
|
||||
@@ -1168,68 +1168,77 @@
|
||||
evt.dataTransfer.clearData();
|
||||
}
|
||||
},
|
||||
update_attachment_count: function(reload) {
|
||||
var record = this.screen.current_record;
|
||||
if (record) {
|
||||
record.get_attachment_count(reload).always(
|
||||
this.attachment_count.bind(this));
|
||||
} else {
|
||||
this.attachment_count(0);
|
||||
}
|
||||
},
|
||||
attachment_count: function(count) {
|
||||
var badge = this.buttons.attach.find('.badge');
|
||||
if (!badge.length) {
|
||||
badge = jQuery('<span/>', {
|
||||
'class': 'badge'
|
||||
}).appendTo(this.buttons.attach);
|
||||
}
|
||||
var text = count || '';
|
||||
if (count > 99) {
|
||||
text = '99+';
|
||||
}
|
||||
badge.text(text);
|
||||
this.buttons.attach.attr(
|
||||
'title', Sao.i18n.gettext("Attachment(%1)", count));
|
||||
var record_id = this.screen.get_id();
|
||||
this.buttons.attach.prop('disabled',
|
||||
record_id < 0 || record_id === null);
|
||||
},
|
||||
note: function() {
|
||||
var record = this.screen.current_record;
|
||||
if (!record || (record.id < 0)) {
|
||||
return;
|
||||
}
|
||||
new Sao.Window.Note(record, function() {
|
||||
this.update_unread_note(true);
|
||||
this.refresh_resources(true);
|
||||
}.bind(this));
|
||||
},
|
||||
update_unread_note: function(reload) {
|
||||
refresh_resources: function(reload) {
|
||||
var record = this.screen.current_record;
|
||||
if (record) {
|
||||
record.get_unread_note(reload).always(
|
||||
this._unread_note.bind(this));
|
||||
record.get_resources(reload).always(
|
||||
this.update_resources.bind(this));
|
||||
} else {
|
||||
this._unread_note(0);
|
||||
this.update_resources();
|
||||
}
|
||||
},
|
||||
_unread_note: function(unread) {
|
||||
var badge = this.buttons.note.find('.badge');
|
||||
if (!badge.length) {
|
||||
badge = jQuery('<span/>', {
|
||||
'class': 'badge'
|
||||
}).appendTo(this.buttons.note);
|
||||
update_resources: function(resources) {
|
||||
if (!resources) {
|
||||
resources = {};
|
||||
}
|
||||
var text = unread || '';
|
||||
if (unread > 99) {
|
||||
text = '99+';
|
||||
}
|
||||
badge.text(text);
|
||||
this.buttons.note.attr(
|
||||
'title', Sao.i18n.gettext("Note(%1)", unread));
|
||||
var record_id = this.screen.get_id();
|
||||
this.buttons.note.prop('disabled',
|
||||
record_id < 0 || record_id === null);
|
||||
var disabled = record_id < 0 || record_id === null;
|
||||
|
||||
var update = function(name, title, text, color) {
|
||||
var button = this.buttons[name];
|
||||
|
||||
var badge = button.find('.badge');
|
||||
if (!badge.length) {
|
||||
badge = jQuery('<span/>', {
|
||||
'class': 'badge'
|
||||
}).appendTo(button);
|
||||
}
|
||||
if (color) {
|
||||
color = Sao.config.icon_colors[color];
|
||||
} else {
|
||||
color = '';
|
||||
}
|
||||
badge.css('background-color', color);
|
||||
badge.text(text);
|
||||
button.attr('title', title);
|
||||
button.prop('disabled', disabled);
|
||||
}.bind(this);
|
||||
|
||||
var count = resources.attachment_count || 0;
|
||||
var badge = count || '';
|
||||
if (count > 99) {
|
||||
badge = '99+';
|
||||
}
|
||||
var title= Sao.i18n.gettext("Attachment (%1)", count);
|
||||
update('attach', title, badge, 1);
|
||||
|
||||
count = resources.note_count || 0;
|
||||
var unread = resources.note_unread || 0;
|
||||
badge = '';
|
||||
var color = unread > 0 ? 2 : 1;
|
||||
if (count) {
|
||||
if (count > 9) {
|
||||
badge = '+';
|
||||
} else {
|
||||
badge = count;
|
||||
}
|
||||
if (unread > 9) {
|
||||
badge = '+/' + badge;
|
||||
} else {
|
||||
badge = unread + '/' + badge;
|
||||
}
|
||||
}
|
||||
title = Sao.i18n.gettext("Note (%1/%2)", unread, count);
|
||||
update('note', title, badge, color);
|
||||
},
|
||||
record_message: function(data) {
|
||||
if (data) {
|
||||
@@ -1344,12 +1353,12 @@
|
||||
action.update_domain(this.board.actions);
|
||||
}
|
||||
},
|
||||
attachment_count: function() {
|
||||
},
|
||||
note: function() {
|
||||
},
|
||||
update_unread_note: function() {
|
||||
}
|
||||
refresh_resources: function() {
|
||||
},
|
||||
update_resources: function() {
|
||||
},
|
||||
});
|
||||
|
||||
Sao.Tab.Wizard = Sao.class_(Sao.Tab, {
|
||||
|
||||
Reference in New Issue
Block a user