updated email digest ui

This commit is contained in:
Rushabh Mehta
2011-07-27 17:43:21 +05:30
parent 90495e0d1f
commit 5f3010735b
9 changed files with 129 additions and 69 deletions

View File

@@ -3,9 +3,9 @@
# These values are common in all dictionaries # These values are common in all dictionaries
{ {
'creation': '2011-07-27 13:14:29', 'creation': '2011-07-27 16:17:04',
'docstatus': 0, 'docstatus': 0,
'modified': '2011-07-27 13:14:29', 'modified': '2011-07-27 16:17:04',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'owner': 'Administrator' 'owner': 'Administrator'
}, },

View File

@@ -3,9 +3,9 @@
# These values are common in all dictionaries # These values are common in all dictionaries
{ {
'creation': '2011-07-27 13:14:29', 'creation': '2011-07-27 16:17:04',
'docstatus': 0, 'docstatus': 0,
'modified': '2011-07-27 13:14:29', 'modified': '2011-07-27 16:17:04',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'owner': 'Administrator' 'owner': 'Administrator'
}, },

View File

@@ -3,9 +3,9 @@
# These values are common in all dictionaries # These values are common in all dictionaries
{ {
'creation': '2011-07-27 13:14:29', 'creation': '2011-07-27 16:17:04',
'docstatus': 0, 'docstatus': 0,
'modified': '2011-07-27 13:14:29', 'modified': '2011-07-27 16:17:04',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'owner': 'Administrator' 'owner': 'Administrator'
}, },

View File

@@ -3,9 +3,9 @@
# These values are common in all dictionaries # These values are common in all dictionaries
{ {
'creation': '2011-07-27 13:14:29', 'creation': '2011-07-27 16:17:04',
'docstatus': 0, 'docstatus': 0,
'modified': '2011-07-27 13:14:29', 'modified': '2011-07-27 16:17:04',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'owner': 'Administrator' 'owner': 'Administrator'
}, },

View File

@@ -3,9 +3,9 @@
# These values are common in all dictionaries # These values are common in all dictionaries
{ {
'creation': '2011-07-27 13:14:29', 'creation': '2011-07-27 16:17:04',
'docstatus': 0, 'docstatus': 0,
'modified': '2011-07-27 13:14:29', 'modified': '2011-07-27 16:17:04',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'owner': 'Administrator' 'owner': 'Administrator'
}, },

View File

@@ -3,9 +3,9 @@
# These values are common in all dictionaries # These values are common in all dictionaries
{ {
'creation': '2011-07-27 13:14:29', 'creation': '2011-07-27 16:17:04',
'docstatus': 0, 'docstatus': 0,
'modified': '2011-07-27 13:14:29', 'modified': '2011-07-27 16:17:04',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'owner': 'Administrator' 'owner': 'Administrator'
}, },

View File

@@ -1,29 +1,46 @@
content_items = ['Sales','Expenses','Bank Balance','Activity'] content_items = ['Sales','Expenses','Bank Balance','Activity']
freq = ['Daily', 'Weekly']
# make a grid with items and columns of checkboxes # make a grid with items and columns of checkboxes
# Parameters: # Parameters:
# parent
# label (main heading) # label (main heading)
# items = [] (rows) # items = [] (rows)
# columns = [] (columns of checks) # columns = [] (columns of checks)
# widths
# description
class CheckGrid class CheckGrid
constructor: (@parent, @label, @items, @columns) -> constructor: (@args) ->
@tab = make_table @parent, @items.length + 1, @columns.length + 1, '80%' $.extend @, args
@wrapper = $a @parent, 'div', 'check-grid round'
@render()
render: ->
$a @wrapper, 'h3', 'check-grid-title', null, @label
if @description
$a @wrapper, 'div', 'help-box', null, @description
@tab = make_table @wrapper, @items.length + 1, @columns.length, '100%', @widths
@checks = {} @checks = {}
# render heads # render heads
for i in [0..@columns.length-1] for i in [0..@columns.length-1]
$td(@tab, 0, i+1).innerHTML = @columns[i] $($td(@tab, 0, i))
.addClass('check-grid-head gradient')
.html @columns[i]
@render_rows()
render_rows: ->
# render rows # render rows
for i in [0..@items.length-1] for i in [0..@items.length-1]
$td(@tab, i+1, 0).innerHTML = @items[i] $td(@tab, i+1, 0).innerHTML = @items[i]
# render checkboxes for this row # render checkboxes for this row
@checks[@items[i]] = {} @checks[@items[i]] = {}
for c in [0..@columns.length-1] for c in [1..@columns.length-1]
check = $a_input $td(@tab, i+1, c+1), 'checkbox' check = $a_input $td(@tab, i+1, c), 'checkbox'
# tag keys to checkbox # tag keys to checkbox
check.item = @items[i] check.item = @items[i]
@@ -38,8 +55,7 @@ class CheckGrid
for item in keys @checks for item in keys @checks
for column in keys @checks[item] for column in keys @checks[item]
check = @checks[item][column] check = @checks[item][column]
if not val[check.item] val[check.item] or= {}
val[check.item] = {}
val[check.item][check.column] = if check.checked then 1 else 0 val[check.item][check.column] = if check.checked then 1 else 0
val val
@@ -47,25 +63,39 @@ class CheckGrid
set: (val) => set: (val) =>
for item in keys @checks for item in keys @checks
for column in keys @checks[item] for column in keys @checks[item]
check = @checks[item][column] if val[item][column]
check.checked = val[check.item][check.row] @checks[item][column] .checked = val[item][column]
return
# attach it to onload # attach it to onload
cx = cur_frm.cscript cx = cur_frm.cscript
cx.onload = (doc, dt, dn) -> cx.onload = (doc, dt, dn) ->
# make the content grid # make the content grid
cx.content_grid = new CheckGrid cur_frm.fields_dict.Body.wrapper, 'Email Settings', cx.content_grid = new CheckGrid
content_items, freq parent: cur_frm.fields_dict.Body.wrapper
label: 'Email Settings'
items: content_items
columns: ['Item','Daily','Weekly']
widths: ['60%', '20%', '20%']
description: 'Select items to be compiled for Email Digest'
# make the email grid # make the email grid
cx.email_grid = new CheckGrid cur_frm.fields_dict.Body.wrapper, 'Send To', cx.email_grid = new CheckGrid
['test1@erpnext', 'test2@erpnext'], freq parent: cur_frm.fields_dict.Body.wrapper
label: 'Send To'
items: ['test1@erpnext', 'test2@erpnext']
columns: ['Email','Daily','Weekly']
widths: ['60%', '20%', '20%']
description: 'Select who gets daily and weekly mails'
cx.content_grid.set JSON.parse doc.content_config if doc.content_config
cx.email_grid.set JSON.parse doc.email_config if doc.email_config
return
# update the data before sending # update the data before sending
cx.validate = (doc, dt, dn) -> cx.validate = (doc, dt, dn) ->
doc.content_config = JSON.stringify cx.content_grid.get() doc.content_config = JSON.stringify cx.content_grid.get()
doc.email_config = JSON.stringify cx.email_grid.get() doc.email_config = JSON.stringify cx.email_grid.get()

View File

@@ -1,35 +1,51 @@
(function() { (function() {
var CheckGrid, content_items, cx, freq; var CheckGrid, content_items, cx;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
content_items = ['Sales', 'Expenses', 'Bank Balance', 'Activity']; content_items = ['Sales', 'Expenses', 'Bank Balance', 'Activity'];
freq = ['Daily', 'Weekly'];
CheckGrid = (function() { CheckGrid = (function() {
function CheckGrid(parent, label, items, columns) { function CheckGrid(args) {
var c, check, i, _ref, _ref2, _ref3; this.args = args;
this.parent = parent;
this.label = label;
this.items = items;
this.columns = columns;
this.set = __bind(this.set, this); this.set = __bind(this.set, this);
this.get = __bind(this.get, this); this.get = __bind(this.get, this);
this.tab = make_table(this.parent, this.items.length + 1, this.columns.length + 1, '80%'); $.extend(this, args);
this.wrapper = $a(this.parent, 'div', 'check-grid round');
this.render();
}
CheckGrid.prototype.render = function() {
var i, _ref;
$a(this.wrapper, 'h3', 'check-grid-title', null, this.label);
if (this.description) {
$a(this.wrapper, 'div', 'help-box', null, this.description);
}
this.tab = make_table(this.wrapper, this.items.length + 1, this.columns.length, '100%', this.widths);
this.checks = {}; this.checks = {};
for (i = 0, _ref = this.columns.length - 1; 0 <= _ref ? i <= _ref : i >= _ref; 0 <= _ref ? i++ : i--) { for (i = 0, _ref = this.columns.length - 1; 0 <= _ref ? i <= _ref : i >= _ref; 0 <= _ref ? i++ : i--) {
$td(this.tab, 0, i + 1).innerHTML = this.columns[i]; $($td(this.tab, 0, i)).addClass('check-grid-head gradient').html(this.columns[i]);
} }
for (i = 0, _ref2 = this.items.length - 1; 0 <= _ref2 ? i <= _ref2 : i >= _ref2; 0 <= _ref2 ? i++ : i--) { return this.render_rows();
};
CheckGrid.prototype.render_rows = function() {
var c, check, i, _ref, _results;
_results = [];
for (i = 0, _ref = this.items.length - 1; 0 <= _ref ? i <= _ref : i >= _ref; 0 <= _ref ? i++ : i--) {
$td(this.tab, i + 1, 0).innerHTML = this.items[i]; $td(this.tab, i + 1, 0).innerHTML = this.items[i];
this.checks[this.items[i]] = {}; this.checks[this.items[i]] = {};
for (c = 0, _ref3 = this.columns.length - 1; 0 <= _ref3 ? c <= _ref3 : c >= _ref3; 0 <= _ref3 ? c++ : c--) { _results.push((function() {
check = $a_input($td(this.tab, i + 1, c + 1), 'checkbox'); var _ref2, _results2;
check.item = this.items[i]; _results2 = [];
check.column = this.columns[c]; for (c = 1, _ref2 = this.columns.length - 1; 1 <= _ref2 ? c <= _ref2 : c >= _ref2; 1 <= _ref2 ? c++ : c--) {
this.checks[this.items[i]][this.columns[c]] = check; check = $a_input($td(this.tab, i + 1, c), 'checkbox');
} check.item = this.items[i];
check.column = this.columns[c];
_results2.push(this.checks[this.items[i]][this.columns[c]] = check);
}
return _results2;
}).call(this));
} }
} return _results;
};
CheckGrid.prototype.get = function() { CheckGrid.prototype.get = function() {
var check, column, item, val, _i, _j, _len, _len2, _ref, _ref2; var check, column, item, val, _i, _j, _len, _len2, _name, _ref, _ref2;
val = {}; val = {};
_ref = keys(this.checks); _ref = keys(this.checks);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -38,40 +54,52 @@
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
column = _ref2[_j]; column = _ref2[_j];
check = this.checks[item][column]; check = this.checks[item][column];
if (!val[check.item]) { val[_name = check.item] || (val[_name] = {});
val[check.item] = {};
}
val[check.item][check.column] = check.checked ? 1 : 0; val[check.item][check.column] = check.checked ? 1 : 0;
} }
} }
return val; return val;
}; };
CheckGrid.prototype.set = function(val) { CheckGrid.prototype.set = function(val) {
var check, column, item, _i, _len, _ref, _results; var column, item, _i, _j, _len, _len2, _ref, _ref2;
_ref = keys(this.checks); _ref = keys(this.checks);
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
item = _ref[_i]; item = _ref[_i];
_results.push((function() { _ref2 = keys(this.checks[item]);
var _j, _len2, _ref2, _results2; for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
_ref2 = keys(this.checks[item]); column = _ref2[_j];
_results2 = []; if (val[item][column]) {
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { this.checks[item][column].checked = val[item][column];
column = _ref2[_j];
check = this.checks[item][column];
_results2.push(check.checked = val[check.item][check.row]);
} }
return _results2; }
}).call(this));
} }
return _results;
}; };
return CheckGrid; return CheckGrid;
})(); })();
cx = cur_frm.cscript; cx = cur_frm.cscript;
cx.onload = function(doc, dt, dn) { cx.onload = function(doc, dt, dn) {
cx.content_grid = new CheckGrid(cur_frm.fields_dict.Body.wrapper, 'Email Settings', content_items, freq); cx.content_grid = new CheckGrid({
return cx.email_grid = new CheckGrid(cur_frm.fields_dict.Body.wrapper, 'Send To', ['test1@erpnext', 'test2@erpnext'], freq); parent: cur_frm.fields_dict.Body.wrapper,
label: 'Email Settings',
items: content_items,
columns: ['Item', 'Daily', 'Weekly'],
widths: ['60%', '20%', '20%'],
description: 'Select items to be compiled for Email Digest'
});
cx.email_grid = new CheckGrid({
parent: cur_frm.fields_dict.Body.wrapper,
label: 'Send To',
items: ['test1@erpnext', 'test2@erpnext'],
columns: ['Email', 'Daily', 'Weekly'],
widths: ['60%', '20%', '20%'],
description: 'Select who gets daily and weekly mails'
});
if (doc.content_config) {
cx.content_grid.set(JSON.parse(doc.content_config));
}
if (doc.email_config) {
cx.email_grid.set(JSON.parse(doc.email_config));
}
}; };
cx.validate = function(doc, dt, dn) { cx.validate = function(doc, dt, dn) {
doc.content_config = JSON.stringify(cx.content_grid.get()); doc.content_config = JSON.stringify(cx.content_grid.get());

View File

@@ -5,14 +5,14 @@
{ {
'creation': '2011-07-27 14:23:09', 'creation': '2011-07-27 14:23:09',
'docstatus': 0, 'docstatus': 0,
'modified': '2011-07-27 15:22:11', 'modified': '2011-07-27 17:32:27',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'owner': 'Administrator' 'owner': 'Administrator'
}, },
# These values are common for all DocType # These values are common for all DocType
{ {
'_last_update': '1311759390', '_last_update': '1311760331',
'colour': 'White:FFF', 'colour': 'White:FFF',
'doctype': 'DocType', 'doctype': 'DocType',
'issingle': 1, 'issingle': 1,
@@ -20,7 +20,7 @@
'name': '__common__', 'name': '__common__',
'section_style': 'Simple', 'section_style': 'Simple',
'show_in_menu': 0, 'show_in_menu': 0,
'version': 3 'version': 4
}, },
# These values are common for all DocField # These values are common for all DocField
@@ -72,6 +72,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'content_config', 'fieldname': 'content_config',
'fieldtype': 'Text', 'fieldtype': 'Text',
'hidden': 1,
'idx': 2, 'idx': 2,
'label': 'Content Config' 'label': 'Content Config'
}, },
@@ -81,6 +82,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'email_config', 'fieldname': 'email_config',
'fieldtype': 'Text', 'fieldtype': 'Text',
'hidden': 1,
'idx': 3, 'idx': 3,
'label': 'Email Config' 'label': 'Email Config'
} }