moved directory structure

This commit is contained in:
Rushabh Mehta
2012-09-24 19:13:42 +05:30
parent e47a6779e9
commit 2fa2f7178d
1637 changed files with 47 additions and 11450 deletions

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,169 @@
/**** CALENDAR ****/
div.cal_body {
margin: 16px;
background-color: #DDD;
position: relative;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
padding: 16px;
-moz-box-shadow: 1px 1px 8px #555;
-webkit-box-shadow: 1px 1px 8px #555;
box-shadow: 1px 1px 8px #555;
}
div.cal_body h4 {
text-align: center;
}
div.cal_head {
margin: 16px;
margin-bottom: 0px;
}
div.cal_head div {
font-size: 18px;
color: #666;
padding-top: 8px;
}
div.cal_toolbar {
width: 80%;
}
div.cal_toolbar .btn {
text-align: center;
margin: 0px;
margin-left: -1px;
}
div.cal_view_body {
}
div.cal_view_body_plain {
margin: 16px;
}
div.cal_month_head {
margin: 8px 0px 8px 0px;
height: 30px;
}
div.cal_month_head .btn {
float: right;
}
span.cal_view_title {
display: inline-block;
font-size: 20px;
}
div.cal_month_body {
}
.cal_month_headtable {
/*table-layout:fixed;*/
width: 100%;
}
.cal_month_name {
width: 100%;
color: #888;
font-size: 14px;
font-weight: bold;
text-align: center;
}
.cal_month_headtable tr td{
font-size: 12px;
font-weight: bold;
text-align: center;
padding: 4px;
}
table.cal_month_table {
border-collapse: collapse;
/*table-layout:fixed;*/
width: 100%;
}
table.cal_month_table td {
width: 14.29%;
height: 20%;
/*overflow:hidden;*/
padding:0px;
}
div.cal_month_date {
width:100%;
font-size: 10px;
/*background-color: #EEF;*/
}
div.cal_month_date_holiday {
/*background-color: #FFF;*/
}
div.cal_month_unit {
width:100%;
min-height: 100px;
overflow:hidden;
cursor:pointer;
/*background-color:#FFF;*/
}
div.cal_vu_disabled {
background-color:#FFF;
cursor:default;
}
table.cal_day_table {
border-collapse: collapse;
width: 100%;
}
table.cal_day_table td {
}
div.cal_day_body {
width: 100%;
overflow-x: hidden;
border-top: 1px solid #AAA;
}
div.cal_day_unit{
width:100%;
cursor:pointer;
}
table.cal_week_table {
border-collapse: collapse;
width: 100%;
}
table.cal_week_table td {
width: 12.5%;
}
div.cal_week_body {
width: 100%;
overflow-x: hidden;
border-top: 1px solid #888;
}
div.cal_week_unit{
width: 100%;
cursor:pointer;
}
div.cal_event_Public {
color: GREEN;
}
div.cal_event_Private {
color: BLUE;
}
div.cal_event_hover {
text-decoration: underline;
}

View File

@@ -0,0 +1,26 @@
<div class="cal_body">
<a class="close" onclick="window.history.back();">&times;</a>
<div class="cal_toolbar btn-group">
<button class="btn btn-small" onclick="erpnext.calendar.add_event()">
<i class="icon-plus"></i> Add Event
</button>
<button class="btn btn-small" onclick="erpnext.calendar.refresh('Day')">
Day View
</button>
<button class="btn btn-small" onclick="erpnext.calendar.refresh('Week')">
Week View
</button>
<button class="btn btn-small" onclick="erpnext.calendar.refresh('Month')">
Month View
</button>
</div>
<div class="cal_month_head">
<span class="cal_view_title"></span>
<button class="btn btn-small" onclick="erpnext.calendar.cur_view.next()">
<i class="icon-arrow-right"></i>
</button>
<button class="btn btn-small" onclick="erpnext.calendar.cur_view.prev()">
<i class="icon-arrow-left"></i>
</button>
</div>
</div>

View File

@@ -0,0 +1,690 @@
// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
//
// MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
pscript.onload_calendar = function(wrapper) {
if(!erpnext.calendar) {
erpnext.calendar = new Calendar();
erpnext.calendar.init(wrapper);
var me = this;
$(document).bind('rename', function(event, dt, old_name, new_name) {
erpnext.calendar.rename_notify(dt, old_name, new_name)
});
}
}
///// CALENDAR
Calendar=function() {
this.views=[];
this.events = {};
this.events_by_name = {};
this.weekdays = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
}
Calendar.prototype.init=function (parent) {
this.wrapper = parent;
this.body = $('.cal_body').get(0);
//this.make_head_buttons();
//this.make_header();
this.view_title = $('.cal_view_title').get(0);
this.todays_date = new Date();
this.selected_date = this.todays_date;
this.selected_hour = 8;
// Create views
this.views['Month'] = new Calendar.MonthView(this);
this.views['Week'] = new Calendar.WeekView(this);
this.views['Day'] = new Calendar.DayView(this);
// Month view as initial
this.cur_view = this.views['Month'];
this.views['Month'].show();
}
Calendar.prototype.rename_notify = function(dt, old_name, new_name) {
// calendar
if(dt = 'Event'){
if(this.events_by_name[old_name]) {
delete this.events_by_name[old_name];
}
}
}
//------------------------------------------------------
Calendar.prototype.show_event = function(ev, cal_ev) {
var me = this;
if(!this.event_dialog) {
var d = new Dialog(400, 400, 'Calendar Event');
d.make_body([
['HTML','Heading']
,['Text','Description']
,['HTML', 'Ref Link']
,['Check', 'Public Event']
,['Check', 'Cancel Event']
,['HTML', 'Event Link']
,['Button', 'Save']
])
// show the event when the dialog opens
d.onshow = function() {
// heading
var c = me.selected_date;
var tmp = time_to_ampm(this.ev.event_hour);
tmp = tmp[0]+':'+tmp[1]+' '+tmp[2];
this.widgets['Heading'].innerHTML =
'<div style="text-align: center; padding:4px; font-size: 14px">'
+ erpnext.calendar.weekdays[c.getDay()] + ', ' + c.getDate() + ' ' + month_list_full[c.getMonth()] + ' ' + c.getFullYear()
+ ' - <b>'+tmp+'</b></div>';
// set
this.widgets['Description'].value = cstr(this.ev.description);
this.widgets['Public Event'].checked = false;
this.widgets['Cancel Event'].checked = false;
if(this.ev.event_type=='Public')
this.widgets['Public Event'].checked = true;
this.widgets['Event Link'].innerHTML = '';
this.widgets['Ref Link'].innerHTML = '';
if(this.ev.ref_type) {
$(repl('<span>Reference: <a href="#Form/%(ref_type)s/%(ref_name)s" \
onclick="cur_dialog.hide()">%(ref_type)s: %(ref_name)s</a></span>', this.ev))
.appendTo(this.widgets['Ref Link'])
}
$(repl('<a href="#Form/Event/%(name)s" \
onclick="cur_dialog.hide()">More Options</a>', this.ev))
.appendTo(this.widgets['Event Link'])
}
// event save
d.widgets['Save'].onclick = function() {
var d = me.event_dialog;
// save values
d.ev.description = d.widgets['Description'].value;
if(d.widgets['Cancel Event'].checked)
d.ev.event_type='Cancel';
else if(d.widgets['Public Event'].checked)
d.ev.event_type='Public';
me.event_dialog.hide();
// if new event
me.save_event(d.ev);
}
this.event_dialog = d;
}
this.event_dialog.ev = ev;
this.event_dialog.cal_ev = cal_ev ? cal_ev : null;
this.event_dialog.show();
}
Calendar.prototype.save_event = function(doc) {
var me = this;
save_doclist('Event', doc.name, 'Save', function(r) {
var doc = locals['Event'][r.docname];
var cal = erpnext.calendar;
cal.cur_view.refresh();
// if cancelled, hide
if(doc.event_type=='Cancel') {
$(cal.events_by_name[doc.name].body).toggle(false);
}
});
}
//------------------------------------------------------
Calendar.prototype.add_event = function() {
var ev = LocalDB.create('Event');
ev = locals['Event'][ev];
ev.event_date = dateutil.obj_to_str(this.selected_date);
ev.event_hour = this.selected_hour+':00';
ev.event_type = 'Private';
this.show_event(ev);
}
//------------------------------------------------------
Calendar.prototype.get_month_events = function(call_back) {
// ret fn
var me = this;
var f = function(r, rt) {
if(me.cur_view) me.cur_view.refresh();
if(call_back)call_back();
}
//load
var y=this.selected_date.getFullYear(); var m = this.selected_date.getMonth();
if(!this.events[y] || !this.events[y][m]) {
$c('webnotes.widgets.event.load_month_events', args = {
'month': m + 1,
'year' : y},
f);
}
}
//------------------------------------------------------
Calendar.prototype.get_daily_event_list=function(day) {
var el = [];
var d = day.getDate(); var m = day.getMonth(); var y = day.getFullYear()
if(this.events[y] && this.events[y][m] &&
this.events[y][m][d]) {
var l = this.events[y][m][d]
for(var i in l) {
for(var j in l[i]) el[el.length] = l[i][j];
}
return el;
}
else return [];
}
//------------------------------------------------------
Calendar.prototype.set_event = function(ev) {
// don't duplicate
if(this.events_by_name[ev.name]) {
return this.events_by_name[ev.name];
}
var dt = dateutil.str_to_obj(ev.event_date);
var m = dt.getMonth();
var d = dt.getDate();
var y = dt.getFullYear();
if(!this.events[y]) this.events[y] = [];
if(!this.events[y][m]) this.events[y][m] = [];
if(!this.events[y][m][d]) this.events[y][m][d] = [];
if(!this.events[y][m][d][cint(ev.event_hour)])
this.events[y][m][d][cint(ev.event_hour)] = [];
var cal_ev = new Calendar.CalEvent(ev, this);
this.events[y][m][d][cint(ev.event_hour)].push(cal_ev);
this.events_by_name[ev.name] = cal_ev;
return cal_ev;
}
//------------------------------------------------------
Calendar.prototype.refresh = function(viewtype){//Sets the viewtype of the Calendar and Calls the View class based on the viewtype
if(viewtype)
this.viewtype = viewtype;
// switch view if reqd
if(this.cur_view.viewtype!=this.viewtype) {
this.cur_view.hide();
this.cur_view = this.views[this.viewtype];
this.cur_view.in_home = false; // for home page
this.cur_view.show();
}
else{
this.cur_view.refresh(this);
}
}
//------------------------------------------------------
Calendar.CalEvent= function(doc, cal) {
this.body = document.createElement('div');
this.link = $a(this.body, 'a', '', {}, locals['Event'][doc.name].description || '');
this.doc = doc;
var me = this;
this.link.onclick = function() {
if(me.doc.name) {
cal.show_event(me.doc, me);
}
}
}
Calendar.CalEvent.prototype.show = function(vu) {
var t = this.doc.event_type;
this.my_class = 'cal_event_'+ t;
if(this.body.parentNode)
this.body.parentNode.removeChild(this.body);
vu.body.appendChild(this.body);
// refresh
this.link.innerHTML = this.doc.description || '';
this.body.className = this.my_class;
}
// ----------
Calendar.View =function() { this.daystep = 0; this.monthstep = 0; }
Calendar.View.prototype.init=function(cal) {
this.cal = cal;
this.body = $a(cal.body, 'div', 'cal_view_body');
this.body.style.display = 'none';
this.create_table();
}
Calendar.View.prototype.show=function() {
this.get_events(); this.refresh(); this.body.style.display = 'block';
}
Calendar.View.prototype.hide=function() { this.body.style.display = 'none';}
Calendar.View.prototype.next = function() {
var s = this.cal.selected_date;
this.cal.selected_date = new Date(s.getFullYear(), s.getMonth() + this.monthstep, s.getDate() + this.daystep);
this.get_events(); this.refresh();
}
Calendar.View.prototype.prev = function() {
var s = this.cal.selected_date;
this.cal.selected_date = new Date(s.getFullYear(), s.getMonth() - this.monthstep, s.getDate() - this.daystep);
this.get_events(); this.refresh();
}
Calendar.View.prototype.get_events = function() {
this.cal.get_month_events();
}
Calendar.View.prototype.add_unit = function(vu) {
this.viewunits[this.viewunits.length] = vu;
}
Calendar.View.prototype.refresh_units = function() {
// load the events
if(locals['Event']) {
for(var name in locals['Event']) {
this.cal.set_event(locals['Event'][name]);
}
}
for(var r in this.table.rows) {
for(var c in this.table.rows[r].cells) {
if(this.table.rows[r].cells[c].viewunit) {
this.table.rows[r].cells[c].viewunit.refresh();
}
}
}
}
// ................. Month View..........................
Calendar.MonthView = function(cal) { this.init(cal); this.monthstep = 1; this.rows = 5; this.cells = 7; }
Calendar.MonthView.prototype=new Calendar.View();
Calendar.MonthView.prototype.create_table = function() {
// create head
this.head_wrapper = $a(this.body, 'div', 'cal_month_head');
// create headers
this.headtable = $a(this.head_wrapper, 'table', 'cal_month_headtable');
var r = this.headtable.insertRow(0);
for(var j=0;j<7;j++) {
var cell = r.insertCell(j);
cell.innerHTML = erpnext.calendar.weekdays[j]; $w(cell, (100 / 7) + '%');
}
this.main = $a(this.body, 'div', 'cal_month_body');
this.table = $a(this.main, 'table', 'cal_month_table');
var me = this;
// create body
for(var i=0;i<5;i++) {
var r = this.table.insertRow(i);
for(var j=0;j<7;j++) {
var cell = r.insertCell(j);
cell.viewunit = new Calendar.MonthViewUnit(cell);
}
}
}
Calendar.MonthView.prototype.refresh = function() {
var c =this.cal.selected_date;
var me=this;
// fill other days
var cur_row = 0;
var cur_month = c.getMonth();
var cur_year = c.getFullYear();
var d = new Date(cur_year, cur_month, 1);
var day = 1 - d.getDay();
// set day headers
var d = new Date(cur_year, cur_month, day);
this.cal.view_title.innerHTML = month_list_full[cur_month] + ' ' + cur_year;
for(var i=0;i<6;i++) {
if((i<5) || cur_month==d.getMonth()) { // if this month
for(var j=0;j<7;j++) {
var cell = this.table.rows[cur_row].cells[j];
if((i<5) || cur_month==d.getMonth()) { // if this month
cell.viewunit.day = d;
cell.viewunit.hour = 8;
if(cur_month == d.getMonth()) {
cell.viewunit.is_disabled = false;
if(same_day(this.cal.todays_date, d))
cell.viewunit.is_today = true;
else
cell.viewunit.is_today = false;
} else {
cell.viewunit.is_disabled = true;
}
}
// new date
day++;
d = new Date(cur_year, cur_month, day);
}
}
cur_row++;
if(cur_row == 5) {cur_row = 0;} // back to top
}
this.refresh_units();
}
// ................. Daily View..........................
Calendar.DayView=function(cal){ this.init(cal); this.daystep = 1; }
Calendar.DayView.prototype=new Calendar.View();
Calendar.DayView.prototype.create_table = function() {
// create body
this.main = $a(this.body, 'div', 'cal_day_body');
this.table = $a(this.main, 'table', 'cal_day_table');
var me = this;
for(var i=0;i<24;i++) {
var r = this.table.insertRow(i);
for(var j=0;j<2;j++) {
var cell = r.insertCell(j);
if(j==0) {
var tmp = time_to_ampm((i)+':00');
cell.innerHTML = tmp[0]+':'+tmp[1]+' '+tmp[2];
$w(cell, '10%');
} else {
cell.viewunit = new Calendar.DayViewUnit(cell);
cell.viewunit.hour = i;
$w(cell, '90%');
if((i>=7)&&(i<=20)) {
cell.viewunit.is_daytime = true;
}
}
}
}
}
Calendar.DayView.prototype.refresh = function() {
var c =this.cal.selected_date;
// fill other days
var me=this;
this.cal.view_title.innerHTML = erpnext.calendar.weekdays[c.getDay()] + ', '
+ c.getDate() + ' ' + month_list_full[c.getMonth()] + ' ' + c.getFullYear();
// headers
var d = c;
for(var i=0;i<24;i++) {
var cell = this.table.rows[i].cells[1];
if(same_day(this.cal.todays_date, d)) cell.viewunit.is_today = true;
else cell.viewunit.is_today = false;
cell.viewunit.day = d;
}
this.refresh_units();
}
// ................. Weekly View..........................
Calendar.WeekView=function(cal) { this.init(cal); this.daystep = 7; }
Calendar.WeekView.prototype=new Calendar.View();
Calendar.WeekView.prototype.create_table = function() {
// create head
this.head_wrapper = $a(this.body, 'div', 'cal_month_head');
// day headers
this.headtable = $a(this.head_wrapper, 'table', 'cal_month_headtable');
var r = this.headtable.insertRow(0);
for(var j=0;j<8;j++) {
var cell = r.insertCell(j);
$w(cell, (100 / 8) + '%');
}
// hour header
// create body
this.main = $a(this.body, 'div', 'cal_week_body');
this.table = $a(this.main, 'table', 'cal_week_table');
var me = this;
for(var i=0;i<24;i++) {
var r = this.table.insertRow(i);
for(var j=0;j<8;j++) {
var cell = r.insertCell(j);
if(j==0) {
var tmp = time_to_ampm(i+':00');
cell.innerHTML = tmp[0]+':'+tmp[1]+' '+tmp[2];
$w(cell, '10%');
} else {
cell.viewunit = new Calendar.WeekViewUnit(cell);
cell.viewunit.hour = i;
if((i>=7)&&(i<=20)) {
cell.viewunit.is_daytime = true;
}
}
}
}
}
Calendar.WeekView.prototype.refresh = function() {
var c =this.cal.selected_date;
// fill other days
var me=this;
this.cal.view_title.innerHTML = month_list_full[c.getMonth()] + ' ' + c.getFullYear();
// headers
var d = new Date(c.getFullYear(), c.getMonth(), c.getDate() - c.getDay());
for (var k=1;k<8;k++) {
this.headtable.rows[0].cells[k].innerHTML = erpnext.calendar.weekdays[d.getDay()] + ' ' + d.getDate();
for(var i=0;i<24;i++) {
var cell = this.table.rows[i].cells[k];
if(same_day(this.cal.todays_date, d))
cell.viewunit.is_today = true;
else cell.viewunit.is_today = false;
cell.viewunit.day = d;
//cell.viewunit.refresh();
}
d=new Date(d.getFullYear(),d.getMonth(),d.getDate() + 1);
}
this.refresh_units();
}
//------------------------------------------------------.
Calendar.ViewUnit = function() {}
Calendar.ViewUnit.prototype.init = function(parent) {
parent.style.border = "1px solid #CCC" ;
this.body = $a(parent, 'div', this.default_class);
this.parent = parent;
var me = this;
this.body.onclick = function() {
erpnext.calendar.selected_date = me.day;
erpnext.calendar.selected_hour = me.hour;
if(erpnext.calendar.cur_vu && erpnext.calendar.cur_vu!=me){
erpnext.calendar.cur_vu.deselect();
me.select();
erpnext.calendar.cur_vu = me;
}
}
this.body.ondblclick = function() {
erpnext.calendar.add_event();
}
}
Calendar.ViewUnit.prototype.set_header=function(v) {
this.header.innerHTML = v;
}
Calendar.ViewUnit.prototype.set_today = function() {
this.is_today = true;
this.set_display();
}
Calendar.ViewUnit.prototype.clear = function() {
if(this.header)this.header.innerHTML = '';
// clear body
while(this.body.childNodes.length)
this.body.removeChild(this.body.childNodes[0]);
}
Calendar.ViewUnit.prototype.set_display = function() {
var cn = '#FFF';
// colors
var col_tod_sel = '#EEE';
var col_tod = '#FFF';
var col_sel = '#EEF';
if(this.is_today) {
if(this.selected) cn = col_tod_sel;
else cn = col_tod;
} else
if(this.selected) cn = col_sel;
if(this.header) {
if(this.is_disabled) {
this.body.className = this.default_class + ' cal_vu_disabled';
this.header.style.color = '#BBB';
} else {
this.body.className = this.default_class;
this.header.style.color = '#000';
}
if(this.day&&this.day.getDay()==0)
this.header.style.backgroundColor = '#FEE';
else
this.header.style.backgroundColor = '';
}
this.parent.style.backgroundColor = cn;
}
Calendar.ViewUnit.prototype.is_selected = function() {
return (same_day(this.day, erpnext.calendar.selected_date)
&& this.hour==erpnext.calendar.selected_hour)
}
Calendar.ViewUnit.prototype.get_event_list = function() {
var y = this.day.getFullYear();
var m = this.day.getMonth();
var d = this.day.getDate();
if(erpnext.calendar.events[y] && erpnext.calendar.events[y][m] &&
erpnext.calendar.events[y][m][d] &&
erpnext.calendar.events[y][m][d][this.hour]) {
return erpnext.calendar.events[y][m][d][this.hour];
} else
return [];
}
Calendar.ViewUnit.prototype.refresh = function() {
this.clear();
if(this.is_selected()) {
if(erpnext.calendar.cur_vu)erpnext.calendar.cur_vu.deselect();
this.selected = true;
erpnext.calendar.cur_vu = this;
}
this.set_display();
this.el = this.get_event_list();
if(this.onrefresh)this.onrefresh();
for(var i in this.el) {
this.el[i].show(this);
}
var me = this;
}
Calendar.ViewUnit.prototype.select=function() { this.selected = true; this.set_display(); }
Calendar.ViewUnit.prototype.deselect=function() { this.selected = false; this.set_display(); }
Calendar.ViewUnit.prototype.setevent=function() { }
Calendar.MonthViewUnit=function(parent) {
this.header = $a(parent, 'div' , "cal_month_date");
this.default_class = "cal_month_unit";
this.init(parent);
this.onrefresh = function() {
this.header.innerHTML = this.day.getDate();
}
}
Calendar.MonthViewUnit.prototype = new Calendar.ViewUnit();
Calendar.MonthViewUnit.prototype.is_selected = function() {
return same_day(this.day, erpnext.calendar.selected_date)
}
Calendar.MonthViewUnit.prototype.get_event_list = function() {
return erpnext.calendar.get_daily_event_list(this.day);
}
Calendar.DayViewUnit= function(parent) {
this.default_class = "cal_day_unit"; this.init(parent);
}
Calendar.DayViewUnit.prototype = new Calendar.ViewUnit();
Calendar.DayViewUnit.prototype.onrefresh = function() {
if(this.el.length<3)
this.body.style.height = '30px';
else this.body.style.height = '';
}
Calendar.WeekViewUnit=function(parent) {
this.default_class = "cal_week_unit"; this.init(parent);
}
Calendar.WeekViewUnit.prototype = new Calendar.ViewUnit();
Calendar.WeekViewUnit.prototype.onrefresh = function() {
if(this.el.length<3) this.body.style.height = '30px';
else this.body.style.height = '';
}

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,28 @@
# Page, calendar
[
# These values are common in all dictionaries
{
'creation': '2012-02-24 11:24:12',
'docstatus': 0,
'modified': '2012-02-24 11:24:12',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
# These values are common for all Page
{
'doctype': 'Page',
'module': u'Utilities',
'name': '__common__',
'page_name': u'calendar',
'standard': u'Yes',
'title': u'Calendar'
},
# Page, calendar
{
'doctype': 'Page',
'name': u'calendar'
}
]

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,150 @@
<div class="layout-wrapper layout-wrapper-background">
<div class="layout-appframe">
<div class="appframe-titlebar">
<span class="appframe-title">Markdown Reference</span>
<span class="close" onclick="window.history.back()">&times;</span>
</div>
</div>
<div class="layout-main">
<div style="width: 60%" class="markdown">
<h3>Phrase Emphasis</h3>
<pre><code>*italic* **bold**
_italic_ __bold__
</code></pre>
<h3>Links</h3>
<p>Inline:</p>
<pre><code>An [example](http://url.com/ "Title")
</code></pre>
<p>Reference-style labels (titles are optional):</p>
<pre><code>An [example][id]. Then, anywhere
else in the doc, define the link:
[id]: http://example.com/ "Title"
</code></pre>
<h3>Images</h3>
<p>Inline (titles are optional):</p>
<pre><code>![alt text](/path/img.jpg "Title")
</code></pre>
<p>Reference-style:</p>
<pre><code>![alt text][id]
[id]: /url/to/img.jpg "Title"
</code></pre>
<h3>Headers</h3>
<p>Setext-style:</p>
<pre><code>Header 1
========
Header 2
--------
</code></pre>
<p>atx-style (closing #'s are optional):</p>
<pre><code># Header 1 #
</code></pre>
<h3>Lists</h3>
<p>Ordered, without paragraphs:</p>
<pre><code>1. Foo
2. Bar
</code></pre>
<p>Unordered, with paragraphs:</p>
<pre><code>* A list item.
With multiple paragraphs.
* Bar
</code></pre>
<p>You can nest them:</p>
<pre><code>* Abacus
* ass
* Bastard
1. bitch
2. bupkis
* BELITTLER
3. burper
* Cunning
</code></pre>
<h3>Blockquotes</h3>
<pre><code>&gt; Email-style angle brackets
&gt; are used for blockquotes.
&gt; &gt; And, they can be nested.
&gt; &gt;
&gt; * You can quote a list.
&gt; * Etc.
</code></pre>
<h3>Code Spans</h3>
<pre><code>`&lt;code&gt;` spans are delimited
by backticks.
You can include literal backticks
like `` `this` ``.
</code></pre>
<h3>Preformatted Code Blocks</h3>
<p>Indent every line of a code block by at least 4 spaces or 1 tab, and use a colon at the end of the preceding paragraph.</p>
<pre><code>This is a normal paragraph:
This is a preformatted
code block.
Preceded by a space, the colon
disappears. :
This is a preformatted
code block.
</code></pre>
<h3>Horizontal Rules</h3>
<p>Three or more dashes or asterisks:</p>
<pre><code>---
* * *
- - - -
</code></pre>
<h3>Manual Line Breaks</h3>
<p>End a line with two or more spaces:</p>
<pre><code>Roses are red,
Violets are blue.
</code></pre>
</div>
</div>
</div>

View File

@@ -0,0 +1 @@
wn.pages['markdown-reference'].onload = function(wrapper) { }

View File

@@ -0,0 +1,2 @@
from __future__ import unicode_literals
import webnotes

View File

@@ -0,0 +1,28 @@
# Page, markdown-reference
[
# These values are common in all dictionaries
{
'creation': '2012-08-07 12:35:30',
'docstatus': 0,
'modified': '2012-08-07 12:35:30',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
# These values are common for all Page
{
'doctype': 'Page',
'module': u'Utilities',
'name': '__common__',
'page_name': u'Markdown Reference',
'standard': u'Yes',
'title': u'Markdown Reference'
},
# Page, markdown-reference
{
'doctype': 'Page',
'name': u'markdown-reference'
}
]

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,35 @@
#message-post-text {
width: 50%;
}
#message-list {
}
.message {
border-radius: 5px;
max-width: 60%;
min-width: 40%;
padding: 7px;
margin-bottom: 7px;
}
.message .help {
margin-bottom: 0px;
padding-bottom: 0px;
color: #888;
font-size: 11px;
}
.message-other {
background-color: #EBFF9C;
border: 1px solid #C3CF78;
float: right;
text-align: right;
}
.message-self {
background-color: #eee;
border: 1px solid #ccc;
float: left;
}

View File

@@ -0,0 +1,28 @@
<div class="layout-wrapper layout-wrapper-background">
<div class="layout-main-section">
<a class="close" onclick="window.history.back();">&times;</a>
<h1>Messages</h1>
<div class="well">
<input id="message-post-text"></input>
<button disabled="disabled" id="message-post" class="btn btn-small"><i class="icon-play"></i> Post</button>
</div>
<div id="message-list">
</div>
</div>
<div class="layout-side-section">
<div class="psidebar">
<div class="section">
<div class="section-head">
Messages By
</div>
<div class="section-body">
<div class="section-item">
<a href="#!messages"><b>All messages</b></a>
</div>
</div>
</div>
</div>
</div>
<div style="clear: both;">
</div>
</div>

View File

@@ -0,0 +1,163 @@
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
wn.provide('erpnext.messages');
wn.pages.messages.onload = function(wrapper) {
erpnext.messages.show_active_users();
erpnext.messages.make_list();
erpnext.update_messages('reset'); //Resets notification icons
// post message
$('#message-post').click(function() {
var txt = $('#message-post-text').val();
if(txt) {
wn.call({
module:'utilities',
page:'messages',
method:'post',
args: {
txt: txt,
contact: erpnext.messages.contact
},
callback:function(r,rt) {
$('#message-post-text').val('')
erpnext.messages.list.run();
},
btn: this
});
}
});
// enable, disable button
$('#message-post-text').keyup(function(e) {
if($(this).val()) {
$('#message-post').attr('disabled', false);
} else {
$('#message-post').attr('disabled', true);
}
if(e.which==13) {
$('#message-post').click();
}
})
}
$(wn.pages.messages).bind('show', function() {
erpnext.messages.show();
setTimeout(erpnext.messages.refresh, 7000);
$('#message-post-text').focus();
})
erpnext.messages = {
show: function() {
var contact = erpnext.messages.get_contact();
// can't send message to self
$(wn.pages.messages).find('.well').toggle(contact==user ? false : true);
$(wn.pages.messages).find('h1:first').html('Messages: '
+ (user==contact ? 'From everyone' : wn.user_info(contact).fullname));
erpnext.messages.contact = contact;
erpnext.messages.list.opts.args.contact = contact;
erpnext.messages.list.run();
},
// check for updates every 5 seconds if page is active
refresh: function() {
setTimeout(erpnext.messages.refresh, 7000);
if(wn.container.page.label != 'Messages') return;
erpnext.messages.show();
},
get_contact: function() {
var route = location.hash;
if(route.indexOf('/')!=-1) {
var name = decodeURIComponent(route.split('/')[1]);
if(name.indexOf('__at__')!=-1) {
name = name.replace('__at__', '@');
}
return name;
}
return user;
},
make_list: function() {
erpnext.messages.list = new wn.ui.Listing({
parent: $('#message-list').get(0),
method: 'utilities.page.messages.messages.get_list',
args: {
contact: null
},
render_row: function(wrapper, data) {
$(wrapper).removeClass('list-row');
data.creation = dateutil.comment_when(data.creation);
data.comment_by_fullname = wn.user_info(data.owner).fullname;
data.reply_html = '';
if(data.owner==user) {
data.cls = 'message-self';
data.comment_by_fullname = 'You';
data.delete_html = repl('<a class="close" \
onclick="erpnext.messages.delete(this)"\
data-name="%(name)s">&times;</a>', data);
} else {
data.cls = 'message-other';
data.delete_html = '';
if(erpnext.messages.contact==user) {
data.reply_html = repl('<a href="#!messages/%(owner)s">\
<i class="icon-share-alt"></i> Reply</a>', data)
}
}
wrapper.innerHTML = repl('<div class="message %(cls)s">%(delete_html)s\
<b>%(comment)s</b>\
<div class="help">by %(comment_by_fullname)s, %(creation)s</div>\
%(reply_html)s</div>\
<div style="clear: both;"></div>', data);
}
});
},
delete: function(ele) {
$(ele).parent().css('opacity', 0.6);
wn.call({
method:'utilities.page.messages.messages.delete',
args: {name : $(ele).attr('data-name')},
callback: function() {
$(ele).parent().toggle(false);
}
});
},
show_active_users: function() {
wn.call({
module:'utilities',
page:'messages',
method:'get_active_users',
callback: function(r,rt) {
var $body = $(wn.pages.messages).find('.section-body');
for(var i in r.message) {
var p = r.message[i];
p.fullname = wn.user_info(p.name).fullname;
p.name = p.name.replace('@', '__at__');
$body.append(repl('<div class="section-item">\
<a href="#!messages/%(name)s">%(fullname)s</a></div>', p))
}
}
});
}
}

View File

@@ -0,0 +1,108 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
@webnotes.whitelist()
def get_list(arg=None):
"""get list of messages"""
webnotes.form_dict['limit_start'] = int(webnotes.form_dict['limit_start'])
webnotes.form_dict['limit_page_length'] = int(webnotes.form_dict['limit_page_length'])
webnotes.form_dict['user'] = webnotes.session['user']
if webnotes.form_dict['contact'] == webnotes.session['user']:
# set all messages as read
webnotes.conn.sql("""UPDATE `tabComment`
set docstatus = 1 where comment_doctype in ('My Company', 'Message')
and comment_docname = %s
""", webnotes.user.name)
# return messages
return webnotes.conn.sql("""select * from `tabComment`
where (owner=%(contact)s or comment_docname=%(user)s)
and comment_doctype in ('My Company', 'Message')
order by creation desc
limit %(limit_start)s, %(limit_page_length)s""", webnotes.form_dict, as_dict=1)
else:
return webnotes.conn.sql("""select * from `tabComment`
where (owner=%(contact)s and comment_docname=%(user)s)
or (owner=%(user)s and comment_docname=%(contact)s)
and comment_doctype in ('My Company', 'Message')
order by creation desc
limit %(limit_start)s, %(limit_page_length)s""", webnotes.form_dict, as_dict=1)
@webnotes.whitelist()
def get_active_users(arg=None):
return webnotes.conn.sql("""select name from tabProfile
where ifnull(enabled,0)=1 and
docstatus < 2 and
name not in ('Administrator', 'Guest')
order by first_name""", as_dict=1)
@webnotes.whitelist()
def post(arg=None):
import webnotes
"""post message"""
if arg:
import json
arg = json.loads(arg)
else:
arg = {}
arg.update(webnotes.form_dict)
from webnotes.model.doc import Document
d = Document('Comment')
d.comment = arg['txt']
d.comment_docname = arg['contact']
d.comment_doctype = 'Message'
d.save()
import webnotes.utils
if webnotes.utils.cint(arg.get('notify')):
notify(arg)
@webnotes.whitelist()
def delete(arg=None):
webnotes.conn.sql("""delete from `tabComment` where name=%s""",
webnotes.form_dict['name']);
def notify(arg=None):
from webnotes.utils import cstr
fn = webnotes.conn.sql('select first_name, last_name from tabProfile where name=%s', webnotes.user.name)[0]
if fn[0] or f[1]:
fn = cstr(fn[0]) + (fn[0] and ' ' or '') + cstr(fn[1])
else:
fn = webnotes.user.name
message = '''A new comment has been posted on your page by %s:
<b>Comment:</b> %s
To answer, please login to your erpnext account!
''' % (fn, arg['txt'])
from webnotes.model.code import get_obj
note = get_obj('Notification Control')
email_msg = note.prepare_message({
'type': 'New Comment',
'message': message
})
sender = webnotes.user.name!='Administrator' and webnotes.user.name or 'support+admin_post@erpnext.com'
from webnotes.utils.email_lib import sendmail
sendmail([arg['contact']], sender, email_msg, fn + ' has posted a new comment')

View File

@@ -0,0 +1,28 @@
# Page, messages
[
# These values are common in all dictionaries
{
'creation': '2012-02-24 11:21:57',
'docstatus': 0,
'modified': '2012-02-24 11:21:57',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
# These values are common for all Page
{
'doctype': 'Page',
'module': u'Utilities',
'name': '__common__',
'page_name': u'messages',
'standard': u'Yes',
'title': u'Messages'
},
# Page, messages
{
'doctype': 'Page',
'name': u'messages'
}
]

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,44 @@
.qv-body {
padding: 13px;
}
.qv-input {
font-size: 14px;
height: 2.5em;
width: 100%;
}
.qv-text {
font-size: 20px;
font-weight: bold;
}
.qv-ans-input {
height: 5em;
}
.qv-ans-text {
color: #444;
line-height: 1.7em;
}
.qv-question-wrapper {
}
.qv-add-answer {
width: 50%;
margin: 7px 0px;
padding: 7px;
background-color: #E2E2EE;
display: none;
}
.qv-add-answer textarea {
height: 17em;
font-size: 12px;
}
.qv-answer {
}

View File

@@ -0,0 +1,11 @@
<div class="layout-wrapper layout-wrapper-appframe">
<div class="layout-appframe"></div>
<div class="layout-main" style="min-height: 400px">
<div class="qv-question-wrapper">
</div>
<hr>
<div class="qv-answer-wrapper">
</div>
<div class="add-answer-area"></div>
</div>
</div>

View File

@@ -0,0 +1,189 @@
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pscript['onload_question-view'] = function(wrapper) {
wrapper.appframe = new wn.ui.AppFrame($(wrapper).find('.layout-appframe'));
wrapper.appframe.title('<span class="breadcrumbs"><a href="#questions">Knowledge Base</a></span>');
wrapper.add_answer_area = $('.add-answer-area').get(0);
}
pscript['refresh_question-view'] = function(wrapper) {
// href
var qid = window.location.hash.split('/')[1];
if(qid) {
pscript.question_view(qid);
}
}
pscript.question_view = function(qid, qtext) {
var w = wn.pages['question-view'];
new KBQuestionView(w, qid, qtext);
}
KBQuestionView = function(w, qid, qtext) {
var me = this;
this.make_question = function() {
$(w).find('.qv-question-wrapper').empty();
$(w.add_answer_area).empty();
new EditableText({
parent: $(w).find('.qv-question-wrapper').get(0),
dt: 'Question',
dn: qid,
fieldname: 'question',
text: qtext,
inp_class: 'qv-input',
disp_class: 'qv-text'
});
// show tags
}
// answer list
this.make_answer_list = function() {
$(w).find('.qv-answer-wrapper').empty();
this.ans_list = new KBAnswerList({
parent: $(w).find('.qv-answer-wrapper').get(0),
qid: qid
})
}
// check if users has answered
// (if no) then add a box to add a new answer
this.make_add_answer = function() {
$c_page('utilities', 'question_view', 'has_answered', qid, function(r, rt) {
if(r.message=='No') {
me.make_answer_box_link();
}
});
}
// add a link to open add answer
this.make_answer_box_link = function() {
wn.pages['question-view'].appframe.add_button('Add your answer', function() {
$(this).toggle(false);
me.make_answer_box();
}, 'icon-plus');
}
// answer box
// text area + add button
this.make_answer_box = function() {
$ds(w.add_answer_area);
$(w.add_answer_area, '<h3>Add your Answer</h3>\
<div class="help">In markdown format</div>');
this.input = $a(w.add_answer_area, 'textarea');
//wn.tinymce.add_simple(this.input);
this.btn = $btn($a(w.add_answer_area, 'div'), 'Post', function() {
var v = $(me.input).val();
if(!v) { msgprint('Write something!'); return; }
me.btn.set_working();
$c_page('utilities', 'question_view', 'add_answer', {qid: qid, answer:v},
function(r, rt) {
me.btn.done_working();
me.ans_list.list.run();
$dh(w.add_answer_area);
}
);
});
}
this.setup = function() {
if(qtext) {
this.make();
}
else {
$c_page('utilities', 'question_view', 'get_question', qid, function(r, rt) {
qtext = r.message;
me.make();
});
}
}
this.make = function() {
set_title(qtext);
this.make_question();
this.make_answer_list();
this.make_add_answer();
}
this.setup();
}
// kb answer list
KBAnswerList = function(args) {
var me = this;
$.extend(this, args);
this.make_list = function() {
wn.pages['question-view'].appframe.clear_buttons();
this.list = new wn.ui.Listing({
parent: me.parent,
appframe: wn.pages['question-view'].appframe,
as_dict: 1,
no_result_message: 'No answers yet, be the first one to answer!',
render_row: function(body, data) {
new KBAnswer(body, data, me)
},
get_query: function() {
return repl("SELECT t1.name, t1.owner, t1.answer, t1._users_voted, t2.first_name, "
+"t2.last_name, t1.modified from tabAnswer t1, tabProfile t2 "
+"where question='%(qid)s' and t1.owner = t2.name "
+"order by t1.modified desc", {qid: me.qid})
}
});
this.list.run();
}
this.make_list();
}
// kb answer
// answer
// by xxx | on xxx
KBAnswer = function(body, data, ans_list) {
body.className = 'qv-answer';
var edtxt = new EditableText({
parent: body,
dt: 'Answer',
dn: data.name,
fieldname: 'answer',
text: data.answer,
inp_class: 'qv-ans-input',
disp_class: 'qv-ans-text',
height: '300px'
});
$(edtxt.wrapper).addClass('well');
var div = $a(body, 'div', '', {})
new KBItemToolbar({
parent: div,
det: data,
with_tags: 0,
doctype: 'Answer'
}, ans_list)
}
wn.require('erpnext/utilities/page/kb_common/kb_common.js');

View File

@@ -0,0 +1,48 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
from webnotes.utils import load_json, cstr, now
@webnotes.whitelist()
def update_item(args):
args = load_json(args)
webnotes.conn.sql("update `tab%s` set `%s`=%s, modified=%s where name=%s" \
% (args['dt'], args['fn'], '%s', '%s', '%s'), (args['text'], now(), args['dn']))
@webnotes.whitelist()
def has_answered(arg):
return webnotes.conn.sql("select name from tabAnswer where owner=%s and question=%s", (webnotes.user.name, arg)) and 'Yes' or 'No'
@webnotes.whitelist()
def get_question(arg):
return cstr(webnotes.conn.sql("select question from tabQuestion where name=%s", arg)[0][0])
@webnotes.whitelist()
def add_answer(args):
args = load_json(args)
from webnotes.model.doc import Document
a = Document('Answer')
a.answer = args['answer']
a.question = args['qid']
a.points = 1
a.save(1)
webnotes.conn.set_value('Question', args['qid'], 'modified', now())

View File

@@ -0,0 +1,27 @@
# Page, question-view
[
# These values are common in all dictionaries
{
'creation': '2011-05-04 11:09:50',
'docstatus': 0,
'modified': '2011-03-29 13:54:27',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
# These values are common for all Page
{
'doctype': 'Page',
'module': 'Utilities',
'name': '__common__',
'page_name': 'Question View',
'standard': 'Yes'
},
# Page, question-view
{
'doctype': 'Page',
'name': 'question-view'
}
]

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,31 @@
div.kb-search-wrapper textarea {
height: 2.2em;
width: 80%;
font-size: 14px;
padding: 3px;
margin-bottom: 7px;
}
.kb-question-wrapper {
padding-bottom: 3px;
margin-bottom: 3px;
}
.kb-questions {
}
.un-answered {
color: #f33;
}
.kb-question-details {
margin: 11px 0px 11px 29px;
}
.kb-tag-filter-area {
padding: 7px;
background-color: #F2F2E8;
color: #222;
margin: 7px 0px;
display: none;
}

View File

@@ -0,0 +1,19 @@
<div class="layout-wrapper layout-wrapper-background">
<div class="layout-appframe"></div>
<div class="layout-main-section">
<div class="kb-search-wrapper">
<textarea></textarea>
<div>
<button class="btn btn-small search" onclick="">
<i class="icon-search"></i> Search</button>
<button class="btn btn-small ask">
<i class="icon-question-sign"></i> Ask</button>
</div>
</div>
</div>
<div class="layout-side-section">
<div class="questions-tags"></div>
<p class="help">A wiki or Q&A for your organization</p>
</div>
<div style="clear: both;"></div>
</div>

View File

@@ -0,0 +1,218 @@
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pscript.onload_questions = function(wrapper) {
body = $(wrapper).find('.layout-main-section').get(0);
wrapper.appframe = new wn.ui.AppFrame($(wrapper).find('.layout-appframe'));
wrapper.appframe.title('Knowledge Base');
// kb
var kb = new KnowledgeBase(body);
// sidebar
this.sidebar = new wn.widgets.PageSidebar($(wrapper).find('.questions-tags').get(0), {
sections: [
{
title: 'Top Tags',
render: function(body) {
new wn.widgets.TagCloud(body, 'Question', function(tag)
{ kb.set_tag_filter(tag) });
}
}
]
});
set_title('Knowledge Base');
}
// knowledge base object
// has a box for search or ask a question
// and list of top rated search results
//
function KnowledgeBase(w) {
var me = this;
this.sort_by = 'modified';
this.tag_filter_dict = {};
this.make_search_bar = function() {
this.search = $(w).find('.kb-search-wrapper textarea').get(0);
$(w).find('.btn.search').click(function() {
me.run();
})
$(w).find('.btn.ask').click(function() {
me.ask();
})
}
// ask a new question
this.ask = function() {
if(this.search.value==$(this.search).attr('default_text')) {
msgprint('Please enter some text'); return;
}
this.add_question([]);
}
// suggest a few users who can answer
this.suggest = function() {
this.dialog = new wn.widgets.Dialog({
title: 'Suggest a users',
width: 400,
fields: [
{fieldtype:'HTML', options:'Optional: Suggest a few users who can help you answer this question<br>'},
{fieldtype:'Link', fieldname:'profile1', label:'1st User',options:'Profile'},
{fieldtype:'Link', fieldname:'profile2', label:'2nd User',options:'Profile'},
{fieldtype:'Link', fieldname:'profile3', label:'3rd User',options:'Profile'},
{fieldtype:'Button', fieldname:'ask', label:'Add the Question'}
]
});
this.dialog.fields_dict.ask.input.onclick = function() {
me.dialog.hide();
me.add_question(values(me.dialog.get_values()));
}
this.dialog.show();
}
// add a new question to the database
this.add_question = function(suggest_list) {
$c_page('utilities', 'questions', 'add_question', {
question: this.search.value,
suggest: suggest_list
}, function(r,rt) {
$(me.search).val('').blur();
me.run();
})
}
// where tags that filter will be displayed
this.make_tag_filter_area = function() {
this.tag_filters = $a(w, 'div', 'kb-tag-filter-area');
$a(this.tag_filters,'span','',{marginRight:'4px',color:'#442'}, '<i>Showing for:</i>');
this.tag_area = $a(this.tag_filters, 'span');
}
// make a list of questions
this.make_list = function() {
this.make_tag_filter_area();
this.list_area = $a(w, 'div', '', {marginRight:'13px'})
this.no_result = $a(w, 'div','help_box',{display:'none'},'No questions asked yet! Be the first one to ask')
this.list = new wn.ui.Listing({
parent: this.list_area,
no_results_message: 'No questions found. Ask a new question!',
appframe: wn.pages.questions.appframe,
as_dict: 1,
method: 'utilities.page.questions.questions.get_questions',
get_args: function() {
var args = {};
if(me.search.value) {
args.search_text = me.search.value;
}
if(me.tag_filter_dict) {
args.tag_filters = keys(me.tag_filter_dict);
}
return args
},
render_row: function(parent, data, listing) {
new KBQuestion(parent, data, me);
}
});
this.list.run();
}
// add a tag filter to the search in the
// main page
this.set_tag_filter = function(tag) {
// check if exists
if(in_list(keys(me.tag_filter_dict), tag.label)) return;
// create a tag in filters
var filter_tag = new SingleTag({
parent: me.tag_area,
label: tag.label,
dt: 'Question',
color: tag.color
});
// remove tag from filters
filter_tag.remove = function(tag_remove) {
$(tag_remove.body).fadeOut();
delete me.tag_filter_dict[tag_remove.label];
// hide everything?
if(!keys(me.tag_filter_dict).length) {
$(me.tag_filters).slideUp(); // hide
}
// run
me.run();
}
// add to dict
me.tag_filter_dict[tag.label] = filter_tag;
$ds(me.tag_filters);
// run
me.run();
}
this.run = function() {
this.list.run();
}
this.make_search_bar();
this.make_list();
}
// single kb question
// "question
// points | tag list"
KBQuestion = function(parent, det, kb) {
this.make = function() {
this.wrapper = $a(parent, 'div', 'kb-question-wrapper');
this.q_area = $a($a(this.wrapper, 'div'), 'h3',
'kb-questions link_type', {display:'inline', textDecoration:'none'}, det.question);
if(det.answers==0) {
$(this.q_area).addClass('un-answered')
}
this.q_area.onclick = function() {
var q = this;
window.location.href = '#!question-view/' + q.id;
//loadpage('question-view', function() { pscript.question_view(q.id, q.txt) })
}
this.q_area.id = det.name; this.q_area.txt = det.question;
new KBItemToolbar({
parent: this.wrapper,
det: det,
with_tags: 1,
doctype: 'Question'
}, kb)
}
this.make()
}
wn.require('app/js/kb_common.js');

View File

@@ -0,0 +1,74 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
from webnotes.utils import load_json, cint, cstr
import json
@webnotes.whitelist()
def get_questions():
"""get list of questions"""
import json
conds = ''
if 'search_text' in webnotes.form_dict:
conds = ' and t1.question like "%'+ webnotes.form_dict['search_text'] + '%"'
if 'tag_filters' in webnotes.form_dict:
tag_filters = json.loads(webnotes.form_dict['tag_filters'])
for t in tag_filters:
conds += ' and t1._user_tags like "%'+ t +'%"'
return webnotes.conn.sql("""select t1.name, t1.owner, t1.question, t1.modified, t1._user_tags,
t2.first_name, t2.last_name, (select count(*) from tabAnswer where
tabAnswer.question = t1.name) as answers
from tabQuestion t1, tabProfile t2
where t1.docstatus!=2
and t1.owner = t2.name
%(conds)s
order by t1.modified desc""" % {"conds":conds}, as_dict=1)
# add a new question
@webnotes.whitelist()
def add_question(arg):
args = load_json(arg)
from webnotes.model.doc import Document
d = Document('Question')
d.question = args['question']
d.points = 1
d.save(1)
if args['suggest']:
from utilities.page.messages import messages
for s in args['suggest']:
if s:
messages.post(json.dumps({
'contact': s,
'txt': 'Please help me and answer the question "%s" in the Knowledge Base' % d.question,
'notify': 1
}))
@webnotes.whitelist()
def delete(arg):
"""
delete a question or answer (called from kb toolbar)
"""
args = load_json(arg)
from webnotes.model import delete_doc
delete_doc(args['dt'], args['dn'])

View File

@@ -0,0 +1,27 @@
# Page, questions
[
# These values are common in all dictionaries
{
'creation': '2011-05-04 11:09:49',
'docstatus': 0,
'modified': '2011-03-29 13:53:57',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
# These values are common for all Page
{
'doctype': 'Page',
'module': 'Utilities',
'name': '__common__',
'page_name': 'Questions',
'standard': 'Yes'
},
# Page, questions
{
'doctype': 'Page',
'name': 'questions'
}
]

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,50 @@
.todoitem {
padding-bottom: 3px;
min-height: 45px;
clear: both;
}
.todoitem .label {
width: 50px;
display: inline-block;
text-align: center;
margin-right: 11px;
margin-top: 3px;
float: left;
}
.todoitem .close {
margin-left: 5px;
font-size: 17px;
}
.todoitem .close-span {
display: inline-block;
float: right;
}
.todoitem .description {
padding: 3px 0px;
display: inline-block;
width: 80%;
}
#todo-list, #assigned-todo-list {
float: left;
width: 50%;
}
.todo-separator {
border-bottom: 1px solid #DEB85F;
margin-bottom: 5px;
clear: both;
}
.todo-content {
padding-right: 15px;
}
.todo-layout {
background-color: #FFFDC9;
min-height: 300px;
}

View File

@@ -0,0 +1,16 @@
<div class="layout-wrapper layout-wrapper-background">
<div class="appframe-area"></div>
<div class="layout-main todo-layout">
<div>
<div id="todo-list">
<h4>My List</h4><br>
<div class="todo-content"></div>
</div>
<div id="assigned-todo-list">
<h4>Assigned to others</h4><br>
<div class="todo-content"></div>
</div>
</div>
<div style="clear: both"></div>
</div>
</div>

205
utilities/page/todo/todo.js Normal file
View File

@@ -0,0 +1,205 @@
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
wn.provide('erpnext.todo');
erpnext.todo.refresh = function() {
wn.call({
method: 'utilities.page.todo.todo.get',
callback: function(r,rt) {
var todo_list = $('#todo-list div.todo-content');
var assigned_todo_list = $('#assigned-todo-list div.todo-content');
todo_list.empty();
assigned_todo_list.empty();
var nothing_to_do = function() {
$('#todo-list div.todo-content')
.html('<div class="help-box">Nothing to do :)</div>');
}
var nothing_delegated = function() {
$('#assigned-todo-list div.todo-content')
.html('<div class="help-box">Nothing assigned to other users. \
Use "Assign To" in a form to delegate work.</div>');
}
if(r.message) {
for(var i in r.message) {
new erpnext.todo.ToDoItem(r.message[i]);
}
if (!todo_list.html()) { nothing_to_do(); }
if (!assigned_todo_list.html()) { nothing_delegated(); }
} else {
nothing_to_do();
nothing_delegated();
}
}
});
}
erpnext.todo.ToDoItem = Class.extend({
init: function(todo) {
label_map = {
'High': 'label-important',
'Medium': 'label-info',
'Low':''
}
todo.labelclass = label_map[todo.priority];
todo.userdate = dateutil.str_to_user(todo.date) || '';
todo.fullname = '';
if(todo.assigned_by) {
var assigned_by = wn.boot.user_info[todo.assigned_by]
todo.fullname = repl("[By %(fullname)s] &nbsp;", {
fullname: (assigned_by ? assigned_by.fullname : todo.assigned_by),
});
}
var parent_list = "#todo-list";
if(todo.owner !== user) {
parent_list = "#assigned-todo-list";
var owner = wn.boot.user_info[todo.owner];
todo.fullname = repl("[To %(fullname)s] &nbsp;", {
fullname: (owner ? owner.fullname : todo.owner),
});
}
parent_list += " div.todo-content";
if(todo.reference_name && todo.reference_type) {
todo.link = repl('<br><a href="#!Form/%(reference_type)s/%(reference_name)s">\
%(reference_type)s: %(reference_name)s</a>', todo);
} else if(todo.reference_type) {
todo.link = repl('<br><a href="#!List/%(reference_type)s">\
%(reference_type)s</a>', todo);
} else {
todo.link = '';
}
if(!todo.description) todo.description = '';
todo.desc = wn.markdown(todo.description);
$(parent_list).append(repl('\
<div class="todoitem">\
<span class="label %(labelclass)s">%(priority)s</span>\
<span class="description">\
<span class="help" style="margin-right: 7px">%(userdate)s</span>\
%(fullname)s%(desc)s\
<span class="popup-on-click"><a href="#"> [edit]</a></span>\
<span class="ref_link">%(link)s</span>\
</span>\
<span class="close-span"><a href="#" class="close">&times;</a></span>\
</div>\
<div class="todo-separator"></div>', todo));
$todo = $(parent_list + ' div.todoitem:last');
if(todo.checked) {
$todo.find('.description').css('text-decoration', 'line-through');
}
if(!todo.reference_type)
$todo.find('.ref_link').toggle(false);
$todo.find('.popup-on-click')
.data('todo', todo)
.click(function() {
erpnext.todo.make_dialog($(this).data('todo'));
return false;
});
$todo.find('.close')
.data('name', todo.name)
.click(function() {
$(this).parent().css('opacity', 0.5);
wn.call({
method:'utilities.page.todo.todo.delete',
args: {name: $(this).data('name')},
callback: function() {
erpnext.todo.refresh();
}
});
return false;
})
}
});
erpnext.todo.make_dialog = function(det) {
if(!erpnext.todo.dialog) {
var dialog = new wn.widgets.Dialog();
dialog.make({
width: 480,
title: 'To Do',
fields: [
{fieldtype:'Text', fieldname:'description', label:'Description',
reqd:1, description:'Use <a href="#markdown-reference">markdown</a> to \
format content'},
{fieldtype:'Date', fieldname:'date', label:'Event Date', reqd:1},
{fieldtype:'Check', fieldname:'checked', label:'Completed'},
{fieldtype:'Select', fieldname:'priority', label:'Priority', reqd:1, 'options':['Medium','High','Low'].join('\n')},
{fieldtype:'Button', fieldname:'save', label:'Save'}
]
});
dialog.fields_dict.save.input.onclick = function() {
erpnext.todo.save(this);
}
erpnext.todo.dialog = dialog;
}
if(det) {
erpnext.todo.dialog.set_values({
date: det.date,
priority: det.priority,
description: det.description,
checked: det.checked
});
erpnext.todo.dialog.det = det;
}
erpnext.todo.dialog.show();
}
erpnext.todo.save = function(btn) {
var d = erpnext.todo.dialog;
var det = d.get_values();
if(!det) {
return;
}
det.name = d.det.name || '';
wn.call({
method:'utilities.page.todo.todo.edit',
args: det,
btn: btn,
callback: function() {
erpnext.todo.dialog.hide();
erpnext.todo.refresh();
}
});
}
wn.pages.todo.onload = function(wrapper) {
// create app frame
wrapper.appframe = new wn.ui.AppFrame($(wrapper).find('.appframe-area'), 'To Do');
wrapper.appframe.add_button('Refresh', erpnext.todo.refresh, 'icon-refresh');
wrapper.appframe.add_button('Add', function() {
erpnext.todo.make_dialog({
date:get_today(), priority:'Medium', checked:0, description:''});
}, 'icon-plus');
// load todos
erpnext.todo.refresh();
}

View File

@@ -0,0 +1,64 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
from webnotes.model.doc import Document
@webnotes.whitelist()
def get(arg=None):
"""get todo list"""
return webnotes.conn.sql("""select name, owner, description, date,
priority, checked, reference_type, reference_name, assigned_by
from `tabToDo` where (owner=%s or assigned_by=%s)
order by field(priority, 'High', 'Medium', 'Low') asc, date asc""",
(webnotes.session['user'], webnotes.session['user']), as_dict=1)
@webnotes.whitelist()
def edit(arg=None):
import markdown2
args = webnotes.form_dict
d = Document('ToDo', args.get('name') or None)
d.description = args['description']
d.date = args['date']
d.priority = args['priority']
d.checked = args.get('checked', 0)
if not d.owner: d.owner = webnotes.session['user']
d.save(not args.get('name') and 1 or 0)
if args.get('name') and d.checked:
notify_assignment(d)
return d.name
@webnotes.whitelist()
def delete(arg=None):
name = webnotes.form_dict['name']
d = Document('ToDo', name)
if d and d.name and d.owner != webnotes.session['user']:
notify_assignment(d)
webnotes.conn.sql("delete from `tabToDo` where name = %s", name)
def notify_assignment(d):
doc_type = d.reference_type
doc_name = d.reference_name
assigned_by = d.assigned_by
if doc_type and doc_name and assigned_by:
from webnotes.widgets.form import assign_to
assign_to.notify_assignment(assigned_by, d.owner, doc_type, doc_name)

View File

@@ -0,0 +1,28 @@
# Page, todo
[
# These values are common in all dictionaries
{
'creation': '2012-02-23 13:59:03',
'docstatus': 0,
'modified': '2012-02-23 13:59:03',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
# These values are common for all Page
{
'doctype': 'Page',
'module': u'Utilities',
'name': '__common__',
'page_name': u'todo',
'standard': u'Yes',
'title': u'To Do'
},
# Page, todo
{
'doctype': 'Page',
'name': u'todo'
}
]

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,4 @@
<div class="layout_wrapper">
<div id="trash_header"></div>
<div id="trash_div" style="margin: 0px;"></div>
</div>

View File

@@ -0,0 +1,144 @@
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pscript['onload_Trash'] = function() {
// header and toolbar
var h = new PageHeader('trash_header','Trash Bin','Restore the documents that you have trashed')
if(!pscript.trash_bin) pscript.trash_bin = new pscript.Trash();
}
pscript.Trash = function() {
// create UI elements
this.wrapper = $i('trash_div');
this.head = $a(this.wrapper, 'div');
this.body = $a(this.wrapper, 'div');
$y(this.body, {margin:'8px'})
this.make_head();
this.load_masters();
}
// Make Button
// ------------
pscript.Trash.prototype.make_button = function(label, area){
var me = this;
var w = $a(area, 'div', '', {margin:'8px'});
var t = make_table(w,1,1,'400px',['50%','50%']);
var s = $a($td(t,0,0),'button');
s.innerHTML = label;
s.wrapper = w;
return s;
}
// Make Head
// -------------
pscript.Trash.prototype.make_head = function() {
var me = this;
var make_select = function(label) {
var w = $a(me.head, 'div', '', {margin:'8px'});
var t = make_table(w,1,2,'400px',['50%','50%']);
$td(t,0,0).innerHTML = label;
var s = $a($td(t,0,1),'select','',{width:'140px'});
s.wrapper = w;
return s;
}
// Select Master Name
this.master_select = make_select('Select Master');
var me = this;
// Get Records
this.get_records_button = me.make_button('Get Records', me.head);
this.get_records_button.onclick = function() {
me.get_records();
}
}
// Load Masters
// -------------
pscript.Trash.prototype.load_masters = function(){
var me = this;
var callback = function(r, rt){
// Masters
empty_select(me.master_select);
add_sel_options(me.master_select,add_lists(['All'], r.message), 'All');
}
$c_obj('Trash Control','get_masters','',callback);
}
// Get Records
// -----------
pscript.Trash.prototype.get_records = function(){
var me = this;
me.body.innerHTML = '';
var callback = function(r, rt){
if(r.message) me.generate_trash_records(r.message);
else msgprint("No Records Found");
}
$c_obj('Trash Control','get_trash_records',sel_val(me.master_select),callback);
}
// Generate Trash Records
// -----------------------
pscript.Trash.prototype.generate_trash_records = function(rec_dict){
var me = this;
pscript.all_checkboxes = [];
mnames = keys(rec_dict).sort();
for(var i = 0; i < mnames.length; i ++){
var head = $a(me.body, 'h3'); head.innerHTML = mnames[i];
var rec_table = make_table(me.body,rec_dict[mnames[i]].length,2,'375px',['350px','25px'],{border:'1px solid #AAA',padding:'2px'});
for(var j = 0; j < rec_dict[mnames[i]].length; j++){
$a_input($td(rec_table,j,0), 'data');
$td(rec_table,j,0).innerHTML = rec_dict[mnames[i]][j];
var chk = $a_input($td(rec_table,j,1), 'checkbox');
chk.master = mnames[i];
chk.record = rec_dict[mnames[i]][j];
pscript.all_checkboxes.push(chk);
}
}
this.restore_button = me.make_button('Restore Selected', me.body);
this.restore_button.onclick = function() {
me.restore_records(0);
}
this.restore_all_button = me.make_button('Restore All', me.body);
this.restore_all_button.onclick = function() {
me.restore_records(1);
}
}
// Restore Records
// ---------------
pscript.Trash.prototype.restore_records = function(restore_all){
var me = this;
var out = {};
for(i in pscript.all_checkboxes) {
c = pscript.all_checkboxes[i];
if (restore_all || (!restore_all && c.checked)) {
if(!out[c.master]) out[c.master] = [c.record];
else {out[c.master].push(c.record);}
}
}
$c_obj('Trash Control','restore_records',JSON.stringify(out),function(r, rt){me.get_records();})
}

View File

@@ -0,0 +1,72 @@
# Page, Trash
[
# These values are common in all dictionaries
{
'creation': '2010-10-12 15:19:32',
'docstatus': 0,
'modified': '2010-12-30 11:44:36',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
# These values are common for all Page
{
'doctype': 'Page',
'module': 'Utilities',
'name': '__common__',
'page_name': 'Trash',
'show_in_menu': 0,
'standard': 'Yes'
},
# These values are common for all Page Role
{
'doctype': 'Page Role',
'name': '__common__',
'parent': 'Trash',
'parentfield': 'roles',
'parenttype': 'Page'
},
# Page, Trash
{
'doctype': 'Page',
'name': 'Trash'
},
# Page Role
{
'doctype': 'Page Role',
'idx': 1,
'role': 'Administrator'
},
# Page Role
{
'doctype': 'Page Role',
'idx': 2,
'role': 'Sales Master Manager'
},
# Page Role
{
'doctype': 'Page Role',
'idx': 3,
'role': 'Material Master Manager'
},
# Page Role
{
'doctype': 'Page Role',
'idx': 4,
'role': 'Purchase Master Manager'
},
# Page Role
{
'doctype': 'Page Role',
'idx': 5,
'role': 'Accounts Manager'
}
]

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,46 @@
.user-card {
border-radius: 5px;
width: 200px;
margin: 11px;
padding: 11px;
background-color: #FFEDBD;
box-shadow: 3px 3px 5px #888;
float: left;
overflow: hidden;
}
.user-card.disabled {
background-color: #eee;
}
.user-card img {
height: 60px;
}
.user-role {
padding: 5px;
width: 45%;
float: left;
}
table.user-perm {
border-collapse: collapse;
}
table.user-perm td, table.user-perm th {
padding: 5px;
text-align: center;
border-bottom: 1px solid #aaa;
min-width: 30px;
}
.subscription-info-box {
margin: 0px 11px;
background-color: #EEEEEE;
border: 1px solid #DDDBDB;
padding: 5px 3px;
}
.subscription-info {
padding: 0px 10px;
}

View File

View File

@@ -0,0 +1,415 @@
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
$.extend(wn.pages.users, {
onload: function(wrapper) {
var w = wn.pages.users;
wn.ui.make_app_page({
parent: w,
title: "Users",
single_column: true
});
w.profiles = {};
w.refresh();
w.setup();
w.role_editor = new erpnext.RoleEditor();
},
setup: function() {
wn.pages.users.appframe.add_button('+ Add User', function() {
wn.pages.users.add_user();
});
// set roles
var w = wn.pages.users;
$(w).on('click', '.btn.user-roles', function() {
var uid = $(this).parent().parent().attr('data-name');
wn.pages.users.role_editor.show(uid);
});
// settings
$(w).on('click', '.btn.user-settings', function() {
var uid = $(this).parent().parent().attr('data-name');
wn.pages.users.show_settings(uid);
});
// delete
$(w).on('click', 'a.close', function() {
$card = $(this).parent();
var uid = $card.attr('data-name');
$card.css('opacity', 0.6);
wn.call({
method: 'utilities.page.users.users.delete',
args: {'uid': uid},
callback: function(r,rt) {
if(!r.exc)
$card.fadeOut()
}
});
})
},
refresh: function() {
// make the list
wn.call({
method:'utilities.page.users.users.get',
callback: function(r, rt) {
$(wn.pages.users).find('.layout-main').empty();
for(var i in r.message) {
var p = r.message[i];
wn.pages.users.profiles[p.name] = p;
wn.pages.users.render(p);
}
}
});
if(!$('.subscription-info').length && (wn.boot.max_users || wn.boot.expires_on)) {
var $sub_info = $('<div class="subscription-info-box"><div>')
.insertAfter($(wn.pages.users).find('.help'));
if(wn.boot.max_users) {
$sub_info.append(repl('\
<span class="subscription-info"> \
Max Users: <b>%(max_users)s</b> \
</span>', { max_users: wn.boot.max_users }));
}
if(wn.boot.expires_on) {
$sub_info.append(repl('\
<span class="subscription-info"> \
Expires On: <b>%(expires_on)s</b> \
</span>', { expires_on: dateutil.str_to_user(wn.boot.expires_on) }));
}
}
},
render: function(data) {
if(data.file_list) {
data.imgsrc = 'files/' + data.file_list.split('\n')[0].split(',')[1];
} else {
data.imgsrc = 'images/lib/ui/no_img_' + (data.gender=='Female' ? 'f' : 'm') + '.gif';
}
data.fullname = wn.user_info(data.name).fullname;
data.delete_html = '';
if(!data.enabled)
data.delete_html = '<a class="close" title="delete">&times;</a>';
$(wn.pages.users).find('.layout-main').append(repl('<div class="user-card" data-name="%(name)s">\
%(delete_html)s\
<img src="%(imgsrc)s">\
<div class="user-info">\
<b class="user-fullname">%(fullname)s</b><br>\
%(name)s<br>\
<button class="btn btn-small user-roles"><i class="icon-user"></i> Roles</button>\
<button class="btn btn-small user-settings"><i class="icon-cog"></i> Settings</button>\
</div>\
</div>', data));
if(!data.enabled) {
$(wn.pages.users).find('.layout-main .user-card:last')
.addClass('disabled')
.find('.user-fullname').html('Disabled');
}
},
show_settings: function(uid) {
var me = wn.pages.users;
if(!me.settings_dialog)
me.make_settings_dialog();
var p = me.profiles[uid];
me.uid = uid;
me.settings_dialog.set_values({
restrict_ip: p.restrict_ip || '',
login_before: p.login_before || '',
login_after: p.login_after || '',
enabled: p.enabled || 0,
new_password: ''
});
me.settings_dialog.show();
},
make_settings_dialog: function() {
var me = wn.pages.users;
me.settings_dialog = new wn.widgets.Dialog({
title: 'Set User Security',
width: 500,
fields: [
{
label:'Enabled',
description: 'Uncheck to disable',
fieldtype: 'Check', fieldname: 'enabled'
},
{
label:'IP Address',
description: 'Restrict user login by IP address, partial ips (111.111.111), \
multiple addresses (separated by commas) allowed',
fieldname:'restrict_ip', fieldtype:'Data'
},
{
label:'Login After',
description: 'User can only login after this hour (0-24)',
fieldtype: 'Int', fieldname: 'login_after'
},
{
label:'Login Before',
description: 'User can only login before this hour (0-24)',
fieldtype: 'Int', fieldname: 'login_before'
},
{
label:'New Password',
description: 'Update the current user password',
fieldtype: 'Data', fieldname: 'new_password'
},
{
label:'Update', fieldtype:'Button', fieldname:'update'
}
]
});
this.settings_dialog.fields_dict.update.input.onclick = function() {
var btn = this;
var args = me.settings_dialog.get_values();
args.user = me.uid;
if (args.new_password) {
me.get_password(btn, args);
} else {
me.update_security(btn, args);
}
};
},
update_security: function(btn, args) {
var me = wn.pages.users;
$(btn).set_working();
$c_page('utilities', 'users', 'update_security', JSON.stringify(args), function(r,rt) {
$(btn).done_working();
if(r.exc) {
msgprint(r.exc);
return;
}
me.settings_dialog.hide();
$.extend(me.profiles[me.uid], me.settings_dialog.get_values());
me.refresh();
});
},
get_password: function(btn, args) {
var me = wn.pages.users;
var pass_d = new wn.widgets.Dialog({
title: 'Your Password',
width: 300,
fields: [
{
label: 'Please Enter <b style="color: black">Your Password</b>',
description: "Your password is required to update the user's password",
fieldtype: 'Password', fieldname: 'sys_admin_pwd', reqd: 1
},
{
label: 'Continue', fieldtype: 'Button', fieldname: 'continue'
}
]
});
pass_d.fields_dict.continue.input.onclick = function() {
btn.pwd_dialog.hide();
args.sys_admin_pwd = btn.pwd_dialog.get_values().sys_admin_pwd;
btn.set_working();
me.update_security(btn, args);
btn.done_working();
}
pass_d.show();
btn.pwd_dialog = pass_d;
btn.done_working();
},
add_user: function() {
var me = wn.pages.users;
var active_users = $('.user-card:not(.disabled)');
if(wn.boot.max_users && (active_users.length >= wn.boot.max_users)) {
msgprint(repl("You already have <b>%(active_users)s</b> active users, \
which is the maximum number that you are currently allowed to add. <br /><br /> \
So, to add more users, you can:<br /> \
1. <b>Upgrade to the unlimited users plan</b>, or<br /> \
2. <b>Disable one or more of your existing users and try again</b>",
{active_users: active_users.length}));
return;
}
var d = new wn.widgets.Dialog({
title: 'Add User',
width: 400,
fields: [{
fieldtype: 'Data', fieldname: 'user', reqd: 1,
label: 'Email Id of the user to add'
}, {
fieldtype: 'Data', fieldname: 'first_name', reqd: 1, label: 'First Name'
}, {
fieldtype: 'Data', fieldname: 'last_name', label: 'Last Name'
}, {
fieldtype: 'Data', fieldname: 'password', reqd: 1, label: 'Password'
}, {
fieldtype: 'Button', label: 'Add', fieldname: 'add'
}]
});
d.make();
d.fields_dict.add.input.onclick = function() {
v = d.get_values();
if(v) {
d.fields_dict.add.input.set_working();
$c_page('utilities', 'users', 'add_user', v, function(r,rt) {
if(r.exc) { msgprint(r.exc); return; }
else {
wn.boot.user_info[v.user] = {fullname:v.first_name + ' ' + (v.last_name || '')};
d.hide();
me.refresh();
}
})
}
}
d.show();
}
});
erpnext.RoleEditor = Class.extend({
init: function() {
this.dialog = new wn.widgets.Dialog({
title: 'Set Roles'
});
var me = this;
$(this.dialog.body).html('<div class="help">Loading...</div>')
wn.call({
method:'utilities.page.users.users.get_roles',
callback: function(r) {
me.roles = r.message;
me.show_roles();
}
});
},
show_roles: function() {
var me = this;
$(this.dialog.body).empty();
for(var i in this.roles) {
$(this.dialog.body).append(repl('<div class="user-role" \
data-user-role="%(role)s">\
<input type="checkbox"> \
<a href="#"><i class="icon-question-sign"></i></a> %(role)s\
</div>', {role: this.roles[i]}));
}
$(this.dialog.body).append('<div style="clear: both">\
<button class="btn btn-small btn-info">Save</button></div>');
$(this.dialog.body).find('button.btn-info').click(function() {
me.save();
});
$(this.dialog.body).find('.user-role a').click(function() {
me.show_permissions($(this).parent().attr('data-user-role'))
return false;
})
},
show: function(uid) {
var me = this;
this.uid = uid;
this.dialog.show();
// set user roles
wn.call({
method:'utilities.page.users.users.get_user_roles',
args: {uid:uid},
callback: function(r, rt) {
$(me.dialog.body).find('input[type="checkbox"]').attr('checked', false);
for(var i in r.message) {
$(me.dialog.body)
.find('[data-user-role="'+r.message[i]
+'"] input[type="checkbox"]').attr('checked',true);
}
}
})
},
save: function() {
var set_roles = [];
var unset_roles = [];
$(this.dialog.body).find('[data-user-role]').each(function() {
var $check = $(this).find('input[type="checkbox"]');
if($check.attr('checked')) {
set_roles.push($(this).attr('data-user-role'));
} else {
unset_roles.push($(this).attr('data-user-role'));
}
})
wn.call({
method:'utilities.page.users.users.update_roles',
args: {
set_roles: JSON.stringify(set_roles),
unset_roles: JSON.stringify(unset_roles),
uid: this.uid
},
btn: $(this.dialog.body).find('.btn-info').get(0),
callback: function() {
}
})
},
show_permissions: function(role) {
// show permissions for a role
var me = this;
if(!this.perm_dialog)
this.make_perm_dialog()
$(this.perm_dialog.body).empty();
wn.call({
method:'utilities.page.users.users.get_perm_info',
args: {role: role},
callback: function(r) {
var $body = $(me.perm_dialog.body);
$body.append('<table class="user-perm"><tbody><tr>\
<th style="text-align: left">Document Type</th>\
<th>Level</th>\
<th>Read</th>\
<th>Write</th>\
<th>Submit</th>\
<th>Cancel</th>\
<th>Amend</th></tr></tbody></table>');
for(var i in r.message) {
var perm = r.message[i];
// if permission -> icon
for(key in perm) {
if(key!='parent' && key!='permlevel') {
if(perm[key]) {
perm[key] = '<i class="icon-ok"></i>';
} else {
perm[key] = '';
}
}
}
$body.find('tbody').append(repl('<tr>\
<td style="text-align: left">%(parent)s</td>\
<td>%(permlevel)s</td>\
<td>%(read)s</td>\
<td>%(write)s</td>\
<td>%(submit)s</td>\
<td>%(cancel)s</td>\
<td>%(amend)s</td>\
</tr>', perm))
}
me.perm_dialog.show();
}
});
},
make_perm_dialog: function() {
this.perm_dialog = new wn.widgets.Dialog({
title:'Role Permissions',
width: 500
});
}
})

View File

@@ -0,0 +1,202 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
import json
from webnotes.model.doc import Document
from webnotes.utils import cint
@webnotes.whitelist()
def get(arg=None):
"""return all users"""
return webnotes.conn.sql("""select name, file_list, enabled, gender,
restrict_ip, login_before, login_after from tabProfile
where docstatus<2 and name not in ('Administrator', 'Guest') order by
ifnull(enabled,0) desc, name""", as_dict=1)
@webnotes.whitelist()
def get_roles(arg=None):
"""return all roles except standard"""
return _get_roles(webnotes.form_dict['uid'])
def _get_roles(user):
"""return all roles except standard"""
return [r[0] for r in webnotes.conn.sql("""select name from tabRole
where name not in ('Administrator', 'Guest', 'All') order by name""", user)]
@webnotes.whitelist()
def get_user_roles(arg=None):
"""get roles for a user"""
return [r[0] for r in webnotes.conn.sql("""select role from tabUserRole
where parent=%s""", webnotes.form_dict['uid'])]
@webnotes.whitelist()
def get_perm_info(arg=None):
"""get permission info"""
return webnotes.conn.sql("""select parent, permlevel, `read`, `write`, submit,
cancel, amend from tabDocPerm where role=%s
and docstatus<2 order by parent, permlevel""",
webnotes.form_dict['role'], as_dict=1)
@webnotes.whitelist()
def update_roles(arg=None):
"""update set and unset roles"""
# remove roles
unset = json.loads(webnotes.form_dict['unset_roles'])
webnotes.conn.sql("""delete from tabUserRole where parent='%s'
and role in ('%s')""" % (webnotes.form_dict['uid'], "','".join(unset)))
# check for 1 system manager
if not webnotes.conn.sql("""select parent from tabUserRole where role='System Manager'
and docstatus<2"""):
webnotes.msgprint("Sorry there must be atleast one 'System Manager'")
raise webnotes.ValidationError
# add roles
roles = get_user_roles()
toset = json.loads(webnotes.form_dict['set_roles'])
for role in toset:
if not role in roles:
d = Document('UserRole')
d.role = role
d.parent = webnotes.form_dict['uid']
d.save()
webnotes.msgprint('Roles Updated')
@webnotes.whitelist()
def update_security(args=''):
args = json.loads(args)
webnotes.conn.set_value('Profile', args['user'], 'restrict_ip', args.get('restrict_ip') or '')
webnotes.conn.set_value('Profile', args['user'], 'login_after', args.get('login_after') or None)
webnotes.conn.set_value('Profile', args['user'], 'login_before', args.get('login_before') or None)
webnotes.conn.set_value('Profile', args['user'], 'enabled', int(args.get('enabled',0)) or 0)
# logout a disabled user
if not int(args.get('enabled',0) or 0):
webnotes.login_manager.logout(user=args['user'])
if args.get('new_password') and args.get('sys_admin_pwd'):
from webnotes.utils import cint
webnotes.conn.sql("update tabProfile set password=password(%s) where name=%s",
(args['new_password'], args['user']))
else:
webnotes.msgprint('Settings Updated')
#
# user addition
#
@webnotes.whitelist()
def add_user(args):
args = json.loads(args)
add_profile(args)
@webnotes.whitelist()
def add_profile(args):
from webnotes.utils import validate_email_add, now
email = args['user']
sql = webnotes.conn.sql
# validate max number of users exceeded or not
import conf
if hasattr(conf, 'max_users'):
active_users = sql("""select count(*) from tabProfile
where ifnull(enabled, 0)=1 and docstatus<2
and name not in ('Administrator', 'Guest')""")[0][0]
if active_users >= conf.max_users and conf.max_users:
# same message as in users.js
webnotes.msgprint("""Alas! <br />\
You already have <b>%(active_users)s</b> active users, \
which is the maximum number that you are currently allowed to add. <br /><br /> \
So, to add more users, you can:<br /> \
1. <b>Upgrade to the unlimited users plan</b>, or<br /> \
2. <b>Disable one or more of your existing users and try again</b>""" \
% {'active_users': active_users}, raise_exception=1)
if not email:
email = webnotes.form_dict.get('user')
if not validate_email_add(email):
raise Exception
return 'Invalid Email Id'
if sql("select name from tabProfile where name = %s", email):
# exists, enable it
sql("update tabProfile set enabled = 1, docstatus=0 where name = %s", email)
webnotes.msgprint('Profile exists, enabled it with new password')
else:
# does not exist, create it!
pr = Document('Profile')
pr.name = email
pr.email = email
pr.first_name = args.get('first_name')
pr.last_name = args.get('last_name')
pr.enabled = 1
pr.user_type = 'System User'
pr.save(1)
if args.get('password'):
sql("""
UPDATE tabProfile
SET password = PASSWORD(%s), modified = %s
WHERE name = %s""", (args.get('password'), now, email))
send_welcome_mail(email, args)
@webnotes.whitelist()
def send_welcome_mail(email, args):
"""send welcome mail to user with password and login url"""
pr = Document('Profile', email)
from webnotes.utils.email_lib import sendmail_md
args.update({
'company': webnotes.conn.get_default('company'),
'password': args.get('password'),
'account_url': webnotes.conn.get_value('Website Settings',
'Website Settings', 'subdomain') or ""
})
if not args.get('last_name'): args['last_name'] = ''
sendmail_md(pr.email, subject="Welcome to ERPNext", msg=welcome_txt % args)
#
# delete user
#
@webnotes.whitelist()
def delete(arg=None):
"""delete user"""
webnotes.conn.sql("update tabProfile set enabled=0, docstatus=2 where name=%s",
webnotes.form_dict['uid'])
webnotes.login_manager.logout(user=webnotes.form_dict['uid'])
welcome_txt = """
## %(company)s
Dear %(first_name)s %(last_name)s
Welcome!
A new account has been created for you, here are your details:
login-id: %(user)s
password: %(password)s
To login to your new ERPNext account, please go to:
%(account_url)s
"""

View File

@@ -0,0 +1,28 @@
# Page, users
[
# These values are common in all dictionaries
{
'creation': '2012-02-28 10:29:39',
'docstatus': 0,
'modified': '2012-02-28 10:29:39',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
# These values are common for all Page
{
'doctype': 'Page',
'module': u'Utilities',
'name': '__common__',
'page_name': u'users',
'standard': u'Yes',
'title': u'Users'
},
# Page, users
{
'doctype': 'Page',
'name': u'users'
}
]

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,2 @@
<div id="wip_head"></div>
<div id="wip_body" style="margin:16px"></div>

View File

@@ -0,0 +1,104 @@
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pscript['onload_WIP Monitor'] = function(){
wip = new WIP_Monitor();
var h = new PageHeader('wip_head','Work in Progress Monitor','A quick glance at your work in progress and pipeline');
h.add_button('Refresh', function(){ wip = new WIP_Monitor();}, 1, 'ui-icon-refresh');
}
// Work In Progress Monitor
// =========================================================================================================================================================
WIP_Monitor = function(){
var me = this;
this.row_index = 0;
$c_obj('Home Control','get_wip_counts','',function(r,rt){
me.make_wip_dashboard(r.message);
});
}
// Make wip dashboard
// ------------------
WIP_Monitor.prototype.make_wip_dashboard = function(wip_dict)
{
var me = this;
// list of doctypes which user can read
var can_read_dt = ['Lead', 'Opportunity', 'Sales Order', 'Sales Invoice', 'Purchase Request', 'Purchase Order', 'Purchase Invoice', 'Delivery Note', 'Task', 'Serial No'];
$i('wip_body').innerHTML = '';
this.tab = make_table('wip_body',1,0,'100%',[],{padding:'4px'});
for(var k=0; k<can_read_dt.length; k++){
// check if the user can read these doctypes
if(in_list(profile.can_read, get_doctype_label(can_read_dt[k])))
{
var work = can_read_dt[k];
if(this.tab.rows[this.row_index].cells.length==2){
this.row_index = this.row_index + 1;
this.tab.insertRow(this.tab.rows.length);
}
var parent = this.tab.rows[this.row_index].insertCell(this.tab.rows[this.row_index].cells.length);
$y(parent, {paddingBottom:'16px', width:'50%', paddingLeft:'8px'})
me.show_wip_dashboard(parent, work, wip_dict[work]);
}
}
}
// Show wip dashboard
// ------------------
WIP_Monitor.prototype.show_wip_dashboard = function(parent, head, report_dict)
{
var me = this;
var report_dt
// dictionary for labels to be displayed
var wip_lbl_map = {'Lead':'Lead', 'Opportunity':'Enquiries', 'Sales Order':'Sales Order', 'Sales Invoice':'Invoices', 'Purchase Request':'Purchase Request', 'Purchase Order':'Purchase Order', 'Purchase Invoice':'Bills', 'Delivery Note':'Delivery Note', 'Task':'Tasks', 'Serial No':'Maintenance'};
// header
var h = $a(parent,'h3');
h.innerHTML = wip_lbl_map[head];
report_dt = head;
for(report in report_dict){
me.make_report_body(parent, report, report_dict[report], report_dt);
}
}
// Make wip report body
// --------------------
WIP_Monitor.prototype.make_report_body = function(parent, lbl, records, rep_dt)
{
var me = this;
dt_color = lbl=='Overdue' ? 'red' : 'black';
var tab2 = make_table(parent,1,2, '70%', ['10%', '90%'], {padding:'4px'});
// no of records
var s1 = $a($td(tab2,0,0), 'span', '', {fontWeight:'bold', fontSize:'12px', color:dt_color});
s1.innerHTML = records;
// link to report
var s1 = $a($td(tab2,0,1), 'span', 'link_type', {cursor:'pointer', color:'#DFH'});
s1.dt = rep_dt; s1.cn = rep_dt + '-' + lbl; s1.innerHTML = lbl;
s1.onclick = function() { loadreport(this.dt, this.cn); }
}

View File

@@ -0,0 +1,28 @@
# Page, WIP Monitor
[
# These values are common in all dictionaries
{
'creation': '2010-12-14 10:23:29',
'docstatus': 0,
'modified': '2011-01-04 11:12:39',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
# These values are common for all Page
{
'doctype': 'Page',
'module': 'Utilities',
'name': '__common__',
'page_name': 'WIP Monitor',
'show_in_menu': 0,
'standard': 'Yes'
},
# Page, WIP Monitor
{
'doctype': 'Page',
'name': 'WIP Monitor'
}
]