Commit 3383383c authored by Sacred Seven's avatar Sacred Seven

Jalali Calendar in milestone pages fixed

parent 1773195d
......@@ -46,7 +46,7 @@
%li
= link_to project_filter_path(milestone_id: milestone.id) do
%strong= milestone.title
%small.light= milestone.expires_at
%small.light expires at #{JalaliDate.new(Date.parse(milestone.expires_at)).strftime("%A %d %b %Y")}
.pull-right
= render 'shared/sort_dropdown'
......
= stylesheet_link_tag "JalaliJSCalendar-1.4/calendar-blue"
= javascript_include_tag "JalaliJSCalendar-1.4/jalali"
= javascript_include_tag "JalaliJSCalendar-1.4/calendar"
= javascript_include_tag "JalaliJSCalendar-1.4/calendar-setup"
= javascript_include_tag "JalaliJSCalendar-1.4/lang/calendar-fa"
%h3.page-title= @milestone.new_record? ? "New Milestone" : "Edit Milestone ##{@milestone.iid}"
.back-link
= link_to project_milestones_path(@project) do
......@@ -16,7 +21,7 @@
.form-group
= f.label :title, "Title", class: "control-label"
.col-sm-10
= f.text_field :title, maxlength: 255, class: "form-control", dir: "auto"
= f.text_field :title, maxlength: 255, class: "form-control", dir: :auto
%p.hint Required
.form-group
= f.label :description, "Description", class: "control-label"
......@@ -31,8 +36,8 @@
.form-group
= f.label :due_date, "Due Date", class: "control-label"
.col-sm-10= f.hidden_field :due_date
.col-sm-10
.datepicker
.col-sm-10{ style: "width: auto" }
#datepicker
.form-actions
- if @milestone.new_record?
......@@ -45,9 +50,12 @@
:javascript
disableButtonIfEmptyField("#milestone_title", ".btn-save");
$( ".datepicker" ).datepicker({
dateFormat: "yy-mm-dd",
onSelect: function(dateText, inst) { $("#milestone_due_date").val(dateText) }
}).datepicker("setDate", $.datepicker.parseDate('yy-mm-dd', $('#milestone_due_date').val()));
Calendar.setup({
flat : "datepicker", // id of the input field
flatCallback : function(calendar) {$('#milestone_due_date').val(calendar.date.toLocaleFormat("%Y/%m/%d"))},
ifFormat : "%Y/%m/%d", // format of the input field
dateType : 'jalali',
weekNumbers : false
});
window.project_image_path_upload = "#{upload_image_project_path @project}";
......@@ -10,7 +10,7 @@
- if milestone.expired? and not milestone.closed?
%span.cred (Expired)
%small
= milestone.expires_at
= "expires at #{JalaliDate.new(Date.parse(milestone.expires_at)).strftime("%A %d %b %Y")}"
- if milestone.is_empty?
%span.muted Empty
- else
......
......@@ -30,7 +30,7 @@
- else
Open
.creator
= @milestone.expires_at
= JalaliDate.new(Date.parse(@milestone.expires_at)).strftime("%A %d %b %Y")
%h4.title{ dir: :auto }
= gfm escape_once(@milestone.title)
......@@ -49,7 +49,7 @@
#{@milestone.open_items_count} open
 
%span.light #{@milestone.percent_complete}% complete
%span.pull-right= @milestone.expires_at
%span.pull-right= "expires at #{JalaliDate.new(Date.parse(@milestone.expires_at)).strftime("%A %d %b %Y")}"
.progress.progress-info
.progress-bar{style: "width: #{@milestone.percent_complete}%;"}
......
This diff is collapsed.
JalaliJSCalendar v1.4
-------------------
Author: Ali Farhadi (http://farhadi.ir/)
Released under the terms of the GNU Public License.
See the GPL for details (http://www.gnu.org/licenses/gpl.html).
Based on The DHTML Calendar
-------------------
Author: Mihai Bazon, <mihai_bazon@yahoo.com>
http://dynarch.com/mishoo/
Contents
---------
calendar.js -- the main program file
calendar-setup.js -- calendar setup script
jalali.js -- jalali extensions for Date Object
lang/*.js -- internalization files
skins/ -- color themes
examples/ -- example usage files
doc/ -- documentation, in PDF and HTML
/* JalaliJSCalendar - Setup Script
* Copyright (c) 2008-2009 Ali Farhadi (http://farhadi.ir/)
*
* Released under the terms of the GNU General Public License.
* See the GPL for details (http://www.gnu.org/licenses/gpl.html).
*
* Based on The DHTML Calendar developed by Dynarch.com. (http://www.dynarch.com/projects/calendar/)
* Copyright Mihai Bazon, 2002-2005 (www.bazon.net/mishoo)
*
*
* This file defines helper functions for setting up the calendar. They are
* intended to help non-programmers get a working calendar on their site
* quickly. This script should not be seen as part of the calendar. It just
* shows you what one can do with the calendar, while in the same time
* providing a quick and simple method for setting it up. If you need
* exhaustive customization of the calendar creation process feel free to
* modify this code to suit your needs (this is recommended and much better
* than modifying calendar.js itself).
*/
/**
* This function "patches" an input field (or other element) to use a calendar
* widget for date selection.
*
* The "params" is a single object that can have the following properties:
*
* prop. name | description
* -------------------------------------------------------------------------------------------------
* inputField | the ID of an input field to store the date
* displayArea | the ID of a DIV or other element to show the date
* button | ID of a button or other element that will trigger the calendar
* eventName | event that will trigger the calendar, without the "on" prefix (default: "click")
* ifFormat | date format that will be stored in the input field
* daFormat | the date format that will be used to display the date in displayArea
* singleClick | (true/false) wether the calendar is in single click mode or not (default: true)
* firstDay | numeric: 0 to 6. "0" means display Sunday first, "1" means display Monday first, etc.
* align | alignment (default: "Br"); if you don't know what's this see the calendar documentation
* range | array with 2 elements. Default: [1900, 2999] -- the range of years available
* weekNumbers | (true/false) if it's true (default) the calendar will display week numbers
* flat | null or element ID; if not null the calendar will be a flat calendar having the parent with the given ID
* flatCallback | function that receives a JS Date object and returns an URL to point the browser to (for flat calendar)
* disableFunc | function that receives a JS Date object and should return true if that date has to be disabled in the calendar
* onSelect | function that gets called when a date is selected. You don't _have_ to supply this (the default is generally okay)
* onClose | function that gets called when the calendar is closed. [default]
* onUpdate | function that gets called after the date is updated in the input field. Receives a reference to the calendar.
* date | the date that the calendar will be initially displayed to
* showsTime | default: false; if true the calendar will include a time selector
* timeFormat | the time format; can be "12" or "24", default is "12"
* electric | if true (default) then given fields/date areas are updated for each move; otherwise they're updated only on close
* step | configures the step of the years in drop-down boxes; default: 2
* position | configures the calendar absolute position; default: null
* showOthers | if "true" (but default: "false") it will show days from other months too
* dateType | "gregorian" or "jalali" (default: "gregorian")
* ifDateType | date type that will be stored in the input field (by default it is same as dateType)
* langNumbers | if "true" it will use number characters specified in language file.
* autoShowOnFocus | if "true", popup calendars will also be shown when their input field gets focus
* autoFillAtStart | if "true", inputField and displayArea will be filled on initialize.
*
* None of them is required, they all have default values. However, if you
* pass none of "inputField", "displayArea" or "button" you'll get a warning
* saying "nothing to setup".
*/
Calendar.setup = function (params) {
function param_default(pname, def) { if (typeof params[pname] == "undefined") { params[pname] = def; } };
param_default("inputField", null);
param_default("displayArea", null);
param_default("button", null);
param_default("eventName", "click");
param_default("ifFormat", "%Y/%m/%d");
param_default("daFormat", "%Y/%m/%d");
param_default("singleClick", true);
param_default("disableFunc", null);
param_default("dateStatusFunc", params["disableFunc"]); // takes precedence if both are defined
param_default("dateText", null);
param_default("firstDay", null);
param_default("align", "Br");
param_default("range", [1000, 3000]);
param_default("weekNumbers", true);
param_default("flat", null);
param_default("flatCallback", null);
param_default("onSelect", null);
param_default("onClose", null);
param_default("onUpdate", null);
param_default("date", null);
param_default("showsTime", false);
param_default("timeFormat", "24");
param_default("electric", true);
param_default("step", 2);
param_default("position", null);
param_default("showOthers", false);
param_default("multiple", null);
param_default("dateType", "gregorian");
param_default("ifDateType", null);
param_default("langNumbers", false);
param_default("autoShowOnFocus", false);
param_default("autoFillAtStart", false);
var tmp = ["inputField", "displayArea", "button"];
for (var i in tmp) {
if (typeof params[tmp[i]] == "string") {
params[tmp[i]] = document.getElementById(params[tmp[i]]);
}
}
if (!(params.flat || params.multiple || params.inputField || params.displayArea || params.button)) {
alert("Calendar.setup:\n Nothing to setup (no fields found). Please check your code");
return false;
}
if (params.autoFillAtStart) {
if (params.inputField && !params.inputField.value)
params.inputField.value = new Date(params.date).print(params.ifFormat, params.ifDateType || params.dateType, params.langNumbers);
if (params.displayArea && !params.displayArea.innerHTML)
params.displayArea.innerHTML = new Date(params.date).print(params.ifFormat, params.ifDateType || params.dateType, params.langNumbers);
}
function onSelect(cal) {
var p = cal.params;
var update = (cal.dateClicked || p.electric);
if (update && p.inputField) {
p.inputField.value = cal.date.print(cal.dateFormat, p.ifDateType || cal.dateType, cal.langNumbers);
if (typeof p.inputField.onchange == "function")
p.inputField.onchange();
}
if (update && p.displayArea)
p.displayArea.innerHTML = cal.date.print(p.daFormat, cal.dateType, cal.langNumbers);
if (update && typeof p.onUpdate == "function")
p.onUpdate(cal);
if (update && p.flat) {
if (typeof p.flatCallback == "function")
p.flatCallback(cal);
}
if (update && p.singleClick && cal.dateClicked)
cal.callCloseHandler();
};
if (!params.flat) {
var cal = new Calendar(params.firstDay,
params.date,
params.onSelect || onSelect,
params.onClose || function(cal) { cal.hide(); });
} else {
if (typeof params.flat == "string")
params.flat = document.getElementById(params.flat);
if (!params.flat) {
alert("Calendar.setup:\n Flat specified but can't find parent.");
return false;
}
var cal = new Calendar(params.firstDay, params.date, params.onSelect || onSelect);
if (params.inputField && typeof params.inputField.value == "string" && params.inputField.value) {
cal.parseDate(params.inputField.value, null, params.ifDateType || cal.dateType);
}
}
cal.showsTime = params.showsTime;
cal.time24 = (params.timeFormat == "24");
cal.weekNumbers = params.weekNumbers;
cal.dateType = params.dateType;
cal.langNumbers = params.langNumbers;
cal.showsOtherMonths = params.showOthers;
cal.yearStep = params.step;
cal.setRange(params.range[0], params.range[1]);
cal.params = params;
cal.setDateStatusHandler(params.dateStatusFunc);
cal.getDateText = params.dateText;
cal.setDateFormat(params.inputField ? params.ifFormat : params.daFormat);
if (params.multiple) {
cal.multiple = {};
for (var i = params.multiple.length; --i >= 0;) {
var d = params.multiple[i];
var ds = d.print("%Y%m%d", cal.dateType, cal.langNumbers);
cal.multiple[ds] = d;
}
}
if (!params.flat) {
var triggerEl = params.button || params.displayArea || params.inputField;
triggerEl["on" + params.eventName] = function() {
if (!cal.element) cal.create();
var dateEl = params.inputField || params.displayArea;
var dateType = params.inputField ? params.ifDateType || cal.dateType : cal.dateType;
if (dateEl && (dateEl.value || dateEl.innerHTML)) params.date = Date.parseDate(dateEl.value || dateEl.innerHTML, cal.dateFormat, dateType);
if (params.date) cal.setDate(params.date);
cal.refresh();
if (!params.position)
cal.showAtElement(params.button || params.displayArea || params.inputField, params.align);
else
cal.showAt(params.position[0], params.position[1]);
return false;
};
if (params.autoShowOnFocus && params.inputField) {
params.inputField["onfocus"] = triggerEl["on" + params.eventName];
};
} else {
cal.create(params.flat);
cal.show();
}
return cal;
};
This diff is collapsed.
/*
* JalaliJSCalendar - Jalali Extension for Date Object
* Copyright (c) 2008 Ali Farhadi (http://farhadi.ir/)
* Released under the terms of the GNU General Public License.
* See the GPL for details (http://www.gnu.org/licenses/gpl.html).
*
* Based on code from http://farsiweb.info
*/
JalaliDate = {
g_days_in_month: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
j_days_in_month: [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29]
};
JalaliDate.jalaliToGregorian = function(j_y, j_m, j_d)
{
j_y = parseInt(j_y);
j_m = parseInt(j_m);
j_d = parseInt(j_d);
var jy = j_y-979;
var jm = j_m-1;
var jd = j_d-1;
var j_day_no = 365*jy + parseInt(jy / 33)*8 + parseInt((jy%33+3) / 4);
for (var i=0; i < jm; ++i) j_day_no += JalaliDate.j_days_in_month[i];
j_day_no += jd;
var g_day_no = j_day_no+79;
var gy = 1600 + 400 * parseInt(g_day_no / 146097); /* 146097 = 365*400 + 400/4 - 400/100 + 400/400 */
g_day_no = g_day_no % 146097;
var leap = true;
if (g_day_no >= 36525) /* 36525 = 365*100 + 100/4 */
{
g_day_no--;
gy += 100*parseInt(g_day_no/ 36524); /* 36524 = 365*100 + 100/4 - 100/100 */
g_day_no = g_day_no % 36524;
if (g_day_no >= 365)
g_day_no++;
else
leap = false;
}
gy += 4*parseInt(g_day_no/ 1461); /* 1461 = 365*4 + 4/4 */
g_day_no %= 1461;
if (g_day_no >= 366) {
leap = false;
g_day_no--;
gy += parseInt(g_day_no/ 365);
g_day_no = g_day_no % 365;
}
for (var i = 0; g_day_no >= JalaliDate.g_days_in_month[i] + (i == 1 && leap); i++)
g_day_no -= JalaliDate.g_days_in_month[i] + (i == 1 && leap);
var gm = i+1;
var gd = g_day_no+1;
return [gy, gm, gd];
}
JalaliDate.checkDate = function(j_y, j_m, j_d)
{
return !(j_y < 0 || j_y > 32767 || j_m < 1 || j_m > 12 || j_d < 1 || j_d >
(JalaliDate.j_days_in_month[j_m-1] + (j_m == 12 && !((j_y-979)%33%4))));
}
JalaliDate.gregorianToJalali = function(g_y, g_m, g_d)
{
g_y = parseInt(g_y);
g_m = parseInt(g_m);
g_d = parseInt(g_d);
var gy = g_y-1600;
var gm = g_m-1;
var gd = g_d-1;
var g_day_no = 365*gy+parseInt((gy+3) / 4)-parseInt((gy+99)/100)+parseInt((gy+399)/400);
for (var i=0; i < gm; ++i)
g_day_no += JalaliDate.g_days_in_month[i];
if (gm>1 && ((gy%4==0 && gy%100!=0) || (gy%400==0)))
/* leap and after Feb */
++g_day_no;
g_day_no += gd;
var j_day_no = g_day_no-79;
var j_np = parseInt(j_day_no/ 12053);
j_day_no %= 12053;
var jy = 979+33*j_np+4*parseInt(j_day_no/1461);
j_day_no %= 1461;
if (j_day_no >= 366) {
jy += parseInt((j_day_no-1)/ 365);
j_day_no = (j_day_no-1)%365;
}
for (var i = 0; i < 11 && j_day_no >= JalaliDate.j_days_in_month[i]; ++i) {
j_day_no -= JalaliDate.j_days_in_month[i];
}
var jm = i+1;
var jd = j_day_no+1;
return [jy, jm, jd];
}
Date.prototype.setJalaliFullYear = function(y, m, d) {
var gd = this.getDate();
var gm = this.getMonth();
var gy = this.getFullYear();
var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
if (y < 100) y += 1300;
j[0] = y;
if (m != undefined) {
if (m > 11) {
j[0] += Math.floor(m / 12);
m = m % 12;
}
j[1] = m + 1;
}
if (d != undefined) j[2] = d;
var g = JalaliDate.jalaliToGregorian(j[0], j[1], j[2]);
return this.setFullYear(g[0], g[1]-1, g[2]);
}
Date.prototype.setJalaliMonth = function(m, d) {
var gd = this.getDate();
var gm = this.getMonth();
var gy = this.getFullYear();
var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
if (m > 11) {
j[0] += math.floor(m / 12);
m = m % 12;
}
j[1] = m+1;
if (d != undefined) j[2] = d;
var g = JalaliDate.jalaliToGregorian(j[0], j[1], j[2]);
return this.setFullYear(g[0], g[1]-1, g[2]);
}
Date.prototype.setJalaliDate = function(d) {
var gd = this.getDate();
var gm = this.getMonth();
var gy = this.getFullYear();
var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
j[2] = d;
var g = JalaliDate.jalaliToGregorian(j[0], j[1], j[2]);
return this.setFullYear(g[0], g[1]-1, g[2]);
}
Date.prototype.getJalaliFullYear = function() {
var gd = this.getDate();
var gm = this.getMonth();
var gy = this.getFullYear();
var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
return j[0];
}
Date.prototype.getJalaliMonth = function() {
var gd = this.getDate();
var gm = this.getMonth();
var gy = this.getFullYear();
var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
return j[1]-1;
}
Date.prototype.getJalaliDate = function() {
var gd = this.getDate();
var gm = this.getMonth();
var gy = this.getFullYear();
var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
return j[2];
}
Date.prototype.getJalaliDay = function() {
var day = this.getDay();
day = (day + 1) % 7;
return day;
}
/**
* Jalali UTC functions
*/
Date.prototype.setJalaliUTCFullYear = function(y, m, d) {
var gd = this.getUTCDate();
var gm = this.getUTCMonth();
var gy = this.getUTCFullYear();
var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
if (y < 100) y += 1300;
j[0] = y;
if (m != undefined) {
if (m > 11) {
j[0] += Math.floor(m / 12);
m = m % 12;
}
j[1] = m + 1;
}
if (d != undefined) j[2] = d;
var g = JalaliDate.jalaliToGregorian(j[0], j[1], j[2]);
return this.setUTCFullYear(g[0], g[1]-1, g[2]);
}
Date.prototype.setJalaliUTCMonth = function(m, d) {
var gd = this.getUTCDate();
var gm = this.getUTCMonth();
var gy = this.getUTCFullYear();
var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
if (m > 11) {
j[0] += math.floor(m / 12);
m = m % 12;
}
j[1] = m+1;
if (d != undefined) j[2] = d;
var g = JalaliDate.jalaliToGregorian(j[0], j[1], j[2]);
return this.setUTCFullYear(g[0], g[1]-1, g[2]);
}
Date.prototype.setJalaliUTCDate = function(d) {
var gd = this.getUTCDate();
var gm = this.getUTCMonth();
var gy = this.getUTCFullYear();
var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
j[2] = d;
var g = JalaliDate.jalaliToGregorian(j[0], j[1], j[2]);
return this.setUTCFullYear(g[0], g[1]-1, g[2]);
}
Date.prototype.getJalaliUTCFullYear = function() {
var gd = this.getUTCDate();
var gm = this.getUTCMonth();
var gy = this.getUTCFullYear();
var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
return j[0];
}
Date.prototype.getJalaliUTCMonth = function() {
var gd = this.getUTCDate();
var gm = this.getUTCMonth();
var gy = this.getUTCFullYear();
var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
return j[1]-1;
}
Date.prototype.getJalaliUTCDate = function() {
var gd = this.getUTCDate();
var gm = this.getUTCMonth();
var gy = this.getUTCFullYear();
var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
return j[2];
}
Date.prototype.getJalaliUTCDay = function() {
var day = this.getUTCDay();
day = (day + 1) % 7;
return day;
}
\ No newline at end of file
// ** I18N Afrikaans
Calendar._DN = new Array
("Sondag",
"Maandag",
"Dinsdag",
"Woensdag",
"Donderdag",
"Vrydag",
"Saterdag",
"Sondag");
Calendar._MN = new Array
("Januarie",
"Februarie",
"Maart",
"April",
"Mei",
"Junie",
"Julie",
"Augustus",
"September",
"Oktober",
"November",
"Desember");
// tooltips
Calendar._TT = {};
Calendar._TT["TOGGLE"] = "Verander eerste dag van die week";
Calendar._TT["PREV_YEAR"] = "Vorige jaar (hou vir keuselys)";
Calendar._TT["PREV_MONTH"] = "Vorige maand (hou vir keuselys)";
Calendar._TT["GO_TODAY"] = "Gaan na vandag";
Calendar._TT["NEXT_MONTH"] = "Volgende maand (hou vir keuselys)";
Calendar._TT["NEXT_YEAR"] = "Volgende jaar (hou vir keuselys)";
Calendar._TT["SEL_DATE"] = "Kies datum";
Calendar._TT["DRAG_TO_MOVE"] = "Sleep om te skuif";
Calendar._TT["PART_TODAY"] = " (vandag)";
Calendar._TT["MON_FIRST"] = "Vertoon Maandag eerste";
Calendar._TT["SUN_FIRST"] =<