(59) 解决在列表视图复制导致打开详细内容
現(xiàn)象:
在列表視圖中,當(dāng)你要復(fù)制一個(gè)內(nèi)容,就觸發(fā)click事件,就打開(kāi)form視圖了
為了區(qū)分click mousedown mousemove muuseup 事件,從而放棄click事件
用后面那幾個(gè)事件組合來(lái)解決是要打開(kāi),還是復(fù)制內(nèi)容事件
改動(dòng)代碼如下:
\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;
??????????? });
====================================
上面是一種解決方案,但當(dāng)ommousemove 事件,移動(dòng)鼠標(biāo)觸發(fā)事件過(guò)多,導(dǎo)致客戶(hù)端會(huì)死掉,最終用下面的方法
得到較好的解決
當(dāng)鼠標(biāo)移動(dòng)時(shí),有復(fù)制到內(nèi)容,則不進(jìn)入詳細(xì)面,判斷沒(méi)有內(nèi)容來(lái)決定:
\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);
??????????????????? }
??????????????? }
??????????? });
轉(zhuǎn)載于:https://www.cnblogs.com/toby2chen/p/8177267.html
超強(qiáng)干貨來(lái)襲 云風(fēng)專(zhuān)訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生總結(jié)
以上是生活随笔為你收集整理的(59) 解决在列表视图复制导致打开详细内容的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: WF4.0实战(十一):邮件通知
- 下一篇: “爸爸,什么是机器学习呀?”