소스 검색

Merge pull request #2843 from rmehta/remove-push-notifications

[minor] remove push notifications
version-14
Nabin Hait 8 년 전
committed by GitHub
부모
커밋
e3b63b7348
4개의 변경된 파일63개의 추가작업 그리고 226개의 파일을 삭제
  1. +0
    -1
      frappe/public/build.json
  2. +0
    -3
      frappe/public/js/frappe/desk.js
  3. +63
    -28
      frappe/public/js/frappe/misc/utils.js
  4. +0
    -194
      frappe/public/js/lib/notify.js

+ 0
- 1
frappe/public/build.json 파일 보기

@@ -59,7 +59,6 @@
"public/js/lib/jquery/jquery-ui.min.js",
"public/js/lib/Sortable.min.js",
"public/js/lib/tag-it.min.js",
"public/js/lib/notify.js",
"public/js/lib/bootstrap.min.js",
"public/js/lib/moment/moment-with-locales.min.js",
"public/js/lib/moment/moment-timezone-with-data.min.js",


+ 0
- 3
frappe/public/js/frappe/desk.js 파일 보기

@@ -62,9 +62,6 @@ frappe.Application = Class.extend({
this.show_notes();
}

// ask to allow notifications
frappe.utils.if_notify_permitted();

// listen to csrf_update
frappe.realtime.on("csrf_generated", function(data) {
// handles the case when a user logs in again from another tab


+ 63
- 28
frappe/public/js/frappe/misc/utils.js 파일 보기

@@ -185,20 +185,21 @@ frappe.utils = {
me.intro_area = null;
}
},
set_footnote: function(me, wrapper, txt) {
if(!me.footnote_area) {
me.footnote_area = $('<div class="text-muted footnote-area">')
set_footnote: function(footnote_area, wrapper, txt) {
if(!footnote_area) {
footnote_area = $('<div class="text-muted footnote-area">')
.appendTo(wrapper);
}

if(txt) {
if(txt.search(/<p>/)==-1) txt = '<p>' + txt + '</p>';
me.footnote_area.html(txt);
if(!txt.includes('<p>'))
txt = '<p>' + txt + '</p>';
footnote_area.html(txt);
} else {
me.footnote_area.remove();
me.footnote_area = null;
footnote_area.remove();
footnote_area = null;
}
return me.footnote_area;
return footnote_area;
},
get_args_dict_from_url: function(txt) {
var args = {};
@@ -517,27 +518,8 @@ frappe.utils = {
frappe.msgprint("Note: Changing the Page Name will break previous URL to this page.");
},

if_notify_permitted: function(callback) {
if (Notify.needsPermission) {
Notify.requestPermission(callback);
} else {
callback && callback();
}
},

notify: function(subject, body, route, onclick) {
if(!route) route = "messages";
if(!onclick) onclick = function() {
frappe.set_route(route);
}

frappe.utils.if_notify_permitted(function() {
var notify = new Notify(subject, {
body: body.replace(/<[^>]*>/g, ""),
notifyClick: onclick
});
notify.show();
});
console.log('push notifications are evil and deprecated');
},

set_title: function(title) {
@@ -593,3 +575,56 @@ frappe.utils = {
return email_list;
}
};

// String.prototype.includes polyfill
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/includes
if (!String.prototype.includes) {
String.prototype.includes = function(search, start) {
'use strict';
if (typeof start !== 'number') {
start = 0;
}
if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
};
}
// Array.prototype.includes polyfill
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
if (!Array.prototype.includes) {
Object.defineProperty(Array.prototype, 'includes', {
value: function(searchElement, fromIndex) {
if (this == null) {
throw new TypeError('"this" is null or not defined');
}
var o = Object(this);
var len = o.length >>> 0;
if (len === 0) {
return false;
}
var n = fromIndex | 0;
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
while (k < len) {
if (o[k] === searchElement) {
return true;
}
k++;
}
return false;
}
});
}
// Array de duplicate
if (!Array.prototype.uniqBy) {
Object.defineProperty(Array.prototype, 'uniqBy', {
value: function (key) {
var seen = {};
return this.filter(function (item) {
var k = key(item);
return seen.hasOwnProperty(k) ? false : (seen[k] = true);
})
}
})
}

+ 0
- 194
frappe/public/js/lib/notify.js 파일 보기

@@ -1,194 +0,0 @@
/*
* Author: Alex Gibson
* https://github.com/alexgibson/notify.js
* License: MIT license
*/

(function(global, factory) {
if (typeof define === 'function' && define.amd) {
// AMD environment
define(function() {
return factory(global, global.document);
});
} else if (typeof module !== 'undefined' && module.exports) {
// CommonJS environment
module.exports = factory(global, global.document);
} else {
// Browser environment
global.Notify = factory(global, global.document);
}
} (typeof window !== 'undefined' ? window : this, function (w, d) {

'use strict';

function isFunction (item) {
return typeof item === 'function';
}

function Notify(title, options) {

if (typeof title !== 'string') {
throw new Error('Notify(): first arg (title) must be a string.');
}

this.title = title;

this.options = {
icon: '',
body: '',
tag: '',
notifyShow: null,
notifyClose: null,
notifyClick: null,
notifyError: null,
timeout: null
};

this.permission = null;

if (!Notify.isSupported) {
return;
}

//User defined options for notification content
if (typeof options === 'object') {

for (var i in options) {
if (options.hasOwnProperty(i)) {
this.options[i] = options[i];
}
}

//callback when notification is displayed
if (isFunction(this.options.notifyShow)) {
this.onShowCallback = this.options.notifyShow;
}

//callback when notification is closed
if (isFunction(this.options.notifyClose)) {
this.onCloseCallback = this.options.notifyClose;
}

//callback when notification is clicked
if (isFunction(this.options.notifyClick)) {
this.onClickCallback = this.options.notifyClick;
}

//callback when notification throws error
if (isFunction(this.options.notifyError)) {
this.onErrorCallback = this.options.notifyError;
}
}
}

// true if the browser supports HTML5 Notification
Notify.isSupported = 'Notification' in w;

// true if the permission is not granted
Notify.needsPermission = !(Notify.isSupported && Notification.permission === 'granted');

// returns current permission level ('granted', 'default', 'denied' or null)
Notify.permissionLevel = (Notify.isSupported ? Notification.permission : null);

// asks the user for permission to display notifications. Then calls the callback functions is supplied.
Notify.requestPermission = function (onPermissionGrantedCallback, onPermissionDeniedCallback) {
if (!Notify.isSupported) {
return;
}
w.Notification.requestPermission(function (perm) {
switch (perm) {
case 'granted':
Notify.needsPermission = false;
if (isFunction(onPermissionGrantedCallback)) {
onPermissionGrantedCallback();
}
break;
case 'denied':
if (isFunction(onPermissionDeniedCallback)) {
onPermissionDeniedCallback();
}
break;
}
});
};


Notify.prototype.show = function () {

if (!Notify.isSupported) {
return;
}

this.myNotify = new Notification(this.title, {
'body': this.options.body,
'tag' : this.options.tag,
'icon' : this.options.icon
});

if (this.options.timeout && !isNaN(this.options.timeout)) {
setTimeout(this.close.bind(this), this.options.timeout * 1000);
}

this.myNotify.addEventListener('show', this, false);
this.myNotify.addEventListener('error', this, false);
this.myNotify.addEventListener('close', this, false);
this.myNotify.addEventListener('click', this, false);
};

Notify.prototype.onShowNotification = function (e) {
if (this.onShowCallback) {
this.onShowCallback(e);
}
};

Notify.prototype.onCloseNotification = function (e) {
if (this.onCloseCallback) {
this.onCloseCallback(e);
}
this.destroy();
};

Notify.prototype.onClickNotification = function (e) {
if (this.onClickCallback) {
this.onClickCallback(e);
}
};

Notify.prototype.onErrorNotification = function (e) {
if (this.onErrorCallback) {
this.onErrorCallback(e);
}
this.destroy();
};

Notify.prototype.destroy = function () {
this.myNotify.removeEventListener('show', this, false);
this.myNotify.removeEventListener('error', this, false);
this.myNotify.removeEventListener('close', this, false);
this.myNotify.removeEventListener('click', this, false);
};

Notify.prototype.close = function () {
this.myNotify.close();
};

Notify.prototype.handleEvent = function (e) {
switch (e.type) {
case 'show':
this.onShowNotification(e);
break;
case 'close':
this.onCloseNotification(e);
break;
case 'click':
this.onClickNotification(e);
break;
case 'error':
this.onErrorNotification(e);
break;
}
};

return Notify;

}));

불러오는 중...
취소
저장