-
Notifications
You must be signed in to change notification settings - Fork 7
Задание выполнено частично #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NBronina
wants to merge
1
commit into
cripi-javascript:gh-pages
Choose a base branch
from
NBronina:gh-pages
base: gh-pages
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function asyncXHR(method, url, data, writeToFile) { | ||
'use strict'; | ||
/* var xhr = new XMLHttpRequest(); | ||
xhr.open(method, url, true); | ||
xhr.addEventListener('readystatechange', function () { | ||
if (xhr.readyState === 4) { | ||
if (xhr.status === 200) { | ||
readToFile(xhr.responseText); | ||
} else { | ||
console.log("error: status != 200 "); | ||
} | ||
} | ||
}); | ||
xhr.send(data); | ||
readToFile('test'); */ | ||
} | ||
|
||
readToFile = function (text) { | ||
'use strict'; | ||
var newEvents, key; | ||
text = '[{"name": "Pewpe", "start": "11.12.2012", "end": "13.12.2012"},{"name": "Pewpe", "start": "11.12.2012", "end": "13.12.2012"}]'; | ||
newEvents = JSON.parse(text); | ||
for (key in newEvents) { | ||
var OneEvents = new Event(newEvents[key]); | ||
hash.add(OneEvents); | ||
} | ||
template ("oneEvent", hash); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Collection - абстрактная коллекция объектов | ||
* Collection.prototype.add - добавление объекта в коллекцию | ||
* | ||
*/ | ||
var Collection = function (elem) { | ||
'use strict'; | ||
this.elem = []; | ||
var key; | ||
for (key in elem) { | ||
this.elem.push(elem[key]); | ||
} | ||
}; | ||
|
||
|
||
Collection.prototype.add = function (model) { | ||
'use strict'; | ||
var key; | ||
if (model.length > 0) { | ||
for (key in model) { | ||
if (model.elem[key].validate() === true) { | ||
this.elem.push(model[key]); | ||
} | ||
} | ||
} else { | ||
if (model.validate() === true) { | ||
this.elem.push(model); | ||
} | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
* function FormEvent(collection) - для сохдания объекта из формы | ||
* @param {collection} - массив со значениями полей | ||
* function create() - добавляет событие в список событий при отправке данных из формы | ||
* function content() - выводит полную информацию о событии при наведении на событие | ||
* function filterAll() - функция фильтрует или сортирует события в зависимости от значений формы фильтрации | ||
* function all() - выводит полный список событий по нажатию на кнопку "Вывести все события" | ||
* function template (nameClass, mass) - шаблон для вывода списка событий | ||
* @param {nameClass} - название классов для событий | ||
* @param {mass} - коллекция событий типа Events | ||
* function passive () - реакция на событие mouseout | ||
*/ | ||
var hash = new Events(); | ||
var collection = new Events(); | ||
function FormEvent(collection) { | ||
"use strict"; | ||
if (typeof collection.start.value === "undefined" || collection.start.value.length === 0) { | ||
alert("Дата начала встречи задана не корректно"); | ||
throw new TypeError("should be date"); | ||
} | ||
return { | ||
"name": collection.name.value || "Встреча", | ||
"start": collection.start.value, | ||
"end": collection.end.value, | ||
"place": collection.place.value || {}, | ||
"info": collection.info.value || {}, | ||
"reminder": collection.reminder.value || "За день до встречи", | ||
"type": collection.type.value || "Работа", | ||
"party": collection.party.value || "да" | ||
}; | ||
} | ||
|
||
function create() { | ||
"use strict"; | ||
var newEvent, fact, el; | ||
newEvent = new FormEvent(document.forms[0]); | ||
fact = new Event(newEvent); | ||
hash.elem[hash.elem.length] = fact; | ||
$('#spisok').empty(); | ||
template("oneEvent", hash); | ||
} | ||
|
||
function content() { | ||
"use strict"; | ||
var s, $idParents, newEvent, $list, k, $el; | ||
$(this).attr("class", $(this).attr("class") + " js_active"); | ||
s = $(this).attr("class"); | ||
$idParents = $(this).attr("id"); | ||
$('#contecsk').empty(); | ||
newEvent = hash.elem[0]; | ||
$el = $('#meeting').clone(true); | ||
$el.attr("class", "elements"); | ||
$list = $('#meeting label').clone(true); | ||
$list.children().each(function () { | ||
if (this.nodeType === 1) { | ||
$(this).remove(); | ||
} | ||
}); | ||
$list.each(function (i) { | ||
for (k in newEvent) { | ||
if (k === document.forms[0].elements[i].name) { | ||
if (s === 'oneEventCollection js_active') { | ||
$(this).text($(this).text() + " " + collection.elem[$idParents.charAt($idParents.length - 1)][k]); | ||
} else { | ||
$(this).text($(this).text() + " " + hash.elem[$idParents.charAt($idParents.length - 1)][k]); | ||
} | ||
} | ||
} | ||
}); | ||
$list.appendTo('#contekst'); | ||
} | ||
|
||
window.onload = function () { | ||
"use strict"; | ||
document.getElementById('submitEvent').addEventListener('click', create, true); | ||
document.getElementById('sort').addEventListener('click', filterAll, true); | ||
document.getElementById('all').addEventListener('click', all, true); | ||
asyncXHR('get', 'test.json', null, readToFile); | ||
} | ||
|
||
function filterAll() { | ||
"use strict"; | ||
var collection2 = new Events(); | ||
$('#spisok').empty(); | ||
var op1 = document.forms[1].elements[0].value; | ||
var op2 = document.forms[1].elements[1].value; | ||
switch (op1) { | ||
case "предстоящие": | ||
collection2 = hash.FilterToDate(1); | ||
break; | ||
case "прошедшие": | ||
collection2 = hash.FilterToDate(-1); | ||
break; | ||
case "я не участвую": | ||
collection2 = hash.FilterToParty(-1); | ||
break; | ||
case "я участвую": | ||
collection2 = hash.FilterToParty(1); | ||
break; | ||
} | ||
switch (op2) { | ||
case "предстоящие": | ||
collection = collection2.FilterToDate(1); | ||
break; | ||
case "прошедшие": | ||
collection = collection2.FilterToDate(-1); | ||
break; | ||
case "я не участвую": | ||
collection = collection2.FilterToParty(-1); | ||
break; | ||
case "я участвую": | ||
collection = collection2.FilterToParty(1); | ||
break; | ||
case "сортировать по дате": | ||
collection = collection2.SortToDate(); | ||
break; | ||
} | ||
template("oneEventCollection", collection); | ||
} | ||
|
||
function all () { | ||
"use strict"; | ||
$('#spisok').empty(); | ||
template ('oneEvent', hash); | ||
} | ||
|
||
function template(nameClass, mass) { | ||
"use strict"; | ||
var i; | ||
for (i = 0; i < mass.elem.length; i++) { | ||
var $el = $('<div />', { | ||
class : [nameClass], | ||
id : 'oneEvent' + i, | ||
text : mass.elem[i].start + "-" + mass.elem[i].end + " " + mass.elem[i].name, | ||
mouseout: passive, | ||
mouseover: content | ||
}).appendTo('#spisok'); | ||
} | ||
} | ||
|
||
function passive() { | ||
"use strict"; | ||
if ($(this).attr("class") === 'oneEvent js_active') { | ||
$(this).attr("class","oneEvent"); | ||
} else { | ||
$(this).attr("class", "oneEventCollection"); | ||
} | ||
$('#contekst').empty(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Event - объект события в календаре. Объект наследуется от Model | ||
* Event.prototype.validate - проверяет корректность полей объекта | ||
* | ||
* function inherits(Constructor, SuperConstructor) - функция для чистого наследования | ||
*/ | ||
var Event = function (data) { | ||
"use strict"; | ||
Model.apply(this, arguments); | ||
this.name = this.name || "Встреча"; | ||
this.place = this.place || {}; | ||
this.info = this.info || {}; | ||
this.reminder = this.reminder || "За день до встречи"; | ||
this.type = this.type || "Работа"; | ||
this.party = this.party || "да"; | ||
}; | ||
|
||
function inherits(Constructor, SuperConstructor) { | ||
"use strict"; | ||
var F = function () {}; | ||
F.prototype = SuperConstructor.prototype; | ||
Constructor.prototype = new F(); | ||
} | ||
|
||
inherits(Event, Model); | ||
|
||
Event.prototype.validate = function () { | ||
"use strict"; | ||
if (this.start === "undefined") { | ||
console.log("starts is can not be null"); | ||
return "starts is can not be null"; | ||
} | ||
if (this.end !== "undefined" && this.end < this.start) { | ||
console.log("can't end before it starts"); | ||
return "can't end before it starts"; | ||
} | ||
return true; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Events - коллекция событий в календаре. Объект наследуется от Collection | ||
* | ||
* Event - объект события в календаре | ||
* Event.prototype.validate - проверяет корректность полей объекта | ||
* Events.prototype.filterToDate - возвращает предстоящие или прощедшие события в зависимости от входящего параметра flag | ||
* Events.prototype.FilterToParty - возвращает события, в которых я принимаю/ не принимаю участие в зависимости от входящего параметра flag | ||
* Events.prototype.sortToDate - сортирует события по дате | ||
* function str2date(s) - преобразует строку в дату | ||
*/ | ||
var Events = function (items) { | ||
"use strict"; | ||
Collection.apply(this, arguments); | ||
}; | ||
inherits(Events, Collection); | ||
|
||
Events.prototype.constructor = Events; | ||
|
||
function str2date(s) { | ||
"use strict"; | ||
var dateParts = s.split('.'); | ||
if (typeof dateParts[2] === 'string') { | ||
return new Date(dateParts[2], dateParts[1], dateParts[0]); | ||
} | ||
if (typeof dateParts[2] === 'undefined') { | ||
dateParts = s.split('-'); | ||
console.log(new Date(dateParts[0], dateParts[1], dateParts[2])); | ||
return new Date(dateParts[0], dateParts[1], dateParts[2]); | ||
} | ||
} | ||
|
||
Events.prototype.SortToDate = function () { | ||
"use strict"; | ||
var mass = this.elem; | ||
mass.sort(function (a, b) { | ||
return str2date(a.start) > str2date(b.start) ? 1 : -1; | ||
}); | ||
var results = new Events(mass); | ||
return results; | ||
}; | ||
|
||
Events.prototype.FilterToDate = function (flag) { | ||
"use strict"; | ||
var result, collection; | ||
result = new Events(); | ||
collection = this.elem; | ||
if (flag === -1) { | ||
result.elem = collection.filter(function (collection) { | ||
var s = str2date(collection.start); | ||
return s < new Date(); | ||
}); | ||
} else { | ||
result.elem = collection.filter(function (collection) { | ||
var s = str2date(collection.start); | ||
return s >= new Date(); | ||
}); | ||
} | ||
return result; | ||
}; | ||
|
||
Events.prototype.FilterToParty = function (flag) { | ||
"use strict"; | ||
var result, collection; | ||
result = new Events(); | ||
collection = this.elem; | ||
if (flag === -1) { | ||
result.elem = collection.filter(function (collection) { | ||
return collection.party === "нет"; | ||
}); | ||
} else { | ||
result.elem = collection.filter(function (collection) { | ||
return collection.party === "да"; | ||
}); | ||
} | ||
return result; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Замени все
document.*
на функции jQuery