(59) 解决在列表视图复制导致打开详细内容
現象:
在列表視圖中,當你要復制一個內容,就觸發click事件,就打開form視圖了
為了區分click mousedown mousemove muuseup 事件,從而放棄click事件
用后面那幾個事件組合來解決是要打開,還是復制內容事件
改動代碼如下:
\addons\web\static\src\js\view_list.js
var hasMove =false;
??????? this.$current = $('<tbody>')
??????????? .delegate('input[readonly=readonly]', 'click', function (e) {
??????????????? /*
??????????????????? Against all logic and sense, as of right now @readonly
??????????????????? apparently does nothing on checkbox and radio inputs, so
??????????????????? the trick of using @readonly to have, well, readonly
??????????????????? checkboxes (which still let clicks go through) does not
??????????????????? work out of the box. We *still* need to preventDefault()
??????????????????? on the event, otherwise the checkbox's state *will* toggle
??????????????????? on click
???????????????? */
??????????????? e.preventDefault();
??????????? })
??????????? .delegate('th.oe_list_record_selector', 'click', function (e) {
??????????????? e.stopPropagation();
??????????????? var selection = self.get_selection();
??????????????? var checked = $(e.currentTarget).find('input').prop('checked');
??????????????? $(self).trigger(
??????????????????????? 'selected', [selection.ids, selection.records, ! checked]);
??????????? })
??????????? .delegate('td.oe_list_record_delete button', 'click', function (e) {
??????????????? e.stopPropagation();
??????????????? var $row = $(e.target).closest('tr');
??????????????? $(self).trigger('deleted', [[self.row_id($row)]]);
??????????? })
??????????? .delegate('td.oe_list_field_cell button', 'click', function (e) {
??????????????? e.stopPropagation();
??????????????? var $target = $(e.currentTarget),
????????????????????? field = $target.closest('td').data('field'),
?????????????????????? $row = $target.closest('tr'),
????????????????? record_id = self.row_id($row);
???????????????
??????????????? if ($target.attr('disabled')) {
??????????????????? return;
??????????????? }
??????????????? $target.attr('disabled', 'disabled');
??????????????? // note: $.data converts data to number if it's composed only
??????????????? // of digits, nice when storing actual numbers, not nice when
??????????????? // storing strings composed only of digits. Force the action
??????????????? // name to be a string
??????????????? $(self).trigger('action', [field.toString(), record_id, function (id) {
??????????????????? $target.removeAttr('disabled');
??????????????????? return self.reload_record(self.records.get(id));
??????????????? }]);
??????????? })
??????????? .delegate('a', 'click', function (e) {
??????????????? e.stopPropagation();
??????????? })
?????????? .delegate('tr', 'mousedown', function (e) {
??????????????? if (e.button ==0){
?????????????????? hasMove=false;
??????????????? }else {
?????????????????? hasMove=true;
??????????????? }
??????????? })
??????????? .delegate('tr', 'mousemove', function (e) {
??????????????? hasMove=true;
??????????? })
??????????? .delegate('tr', 'mouseup', function (e) {
??????????????? if (hasMove || (e.srcElement.type && e.srcElement.type=='checkbox')){
??????????????? }else{
??????????????? var row_id = self.row_id(e.currentTarget);
??????????????? if (row_id) {
??????????????????? e.stopPropagation();
??????????????????? if (!self.dataset.select_id(row_id)) {
??????????????????????? throw new Error(_t("Could not find id in dataset"));
??????????????????? }
??????????????????? self.row_clicked(e);
??????????????? }
??????????????? }
??????????????? hasMove =false;
??????????? });
====================================
上面是一種解決方案,但當ommousemove 事件,移動鼠標觸發事件過多,導致客戶端會死掉,最終用下面的方法
得到較好的解決
當鼠標移動時,有復制到內容,則不進入詳細面,判斷沒有內容來決定:
\addons\web\static\src\js\view_list.js
.delegate('tr', 'click', function (e) {
??????????????? var txt = window.getSelection?window.getSelection():document.selection.createRange().text;
??????????????? if (txt!=''){
????????????????? e.stopPropagation();
??????????????? }else{
??????????????????? var row_id = self.row_id(e.currentTarget);
??????????????????? if (row_id) {
??????????????????????? e.stopPropagation();
??????????????????????? if (!self.dataset.select_id(row_id)) {
??????????????????????????? throw new Error(_t("Could not find id in dataset"));
??????????????????????? }
??????????????????????? self.row_clicked(e);
??????????????????? }
??????????????? }
??????????? });
轉載于:https://www.cnblogs.com/toby2chen/p/8177267.html
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的(59) 解决在列表视图复制导致打开详细内容的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WF4.0实战(十一):邮件通知
- 下一篇: “爸爸,什么是机器学习呀?”