From 79fef63dfb7bec7c41fffb1f6c3d2cd413f0af19 Mon Sep 17 00:00:00 2001 From: Natalya Bronina Date: Sun, 11 Nov 2012 17:17:41 +0600 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D0=B5?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=BC=D0=B5=D1=80=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit создание списка событий из формы --- createevent.js | 198 +++++++++++++++++++++++++++++++++++++++++++++++++ forma.html | 77 +++++++++++++++++++ style.css | 36 +++++++++ 3 files changed, 311 insertions(+) create mode 100644 createevent.js create mode 100644 forma.html create mode 100644 style.css diff --git a/createevent.js b/createevent.js new file mode 100644 index 0000000..6c9e2d0 --- /dev/null +++ b/createevent.js @@ -0,0 +1,198 @@ +/* +* function Event(collection) - создает объект +* @param {collection} - массив со значениями полей +* function create() - добавляет событие в список событий при отпревке данных из формы +* function content() - выводит полную информацию событии при клике на него +* function filterAll() - функция фильтрует или сортирует события в зависимости от значений формы фильтрации +* function all() - выводит полный список событий по нажатию на кнопку "Вывести все события" +* function str2date(s) - преобразует дату начала и окончания события +* function FilterToDate(collection, flag) - возвращает предстоящие или прощедшие события в зависимости от значения flag +* function FilterToParty(collection, flag) - возвращает события, в которых я принимаю/ не принимаю участие в зависимости от значения flag +* function SortToDate(collection) сортирует встречи по дате +*/ +var hash = []; +var collection = []; +function Event(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, +// "participants": collection.participants.value || {}, +// "organizer": collection.organizer.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, el; + newEvent = new Event(document.forms[0]); + el = document.createElement('div'); + el.className = 'oneEvent'; + el.setAttribute('id', 'oneEvent' + hash.length); + el.textContent = newEvent.start + "-" + newEvent.end + " " + newEvent.name; + spisok.appendChild(el); + document.getElementById('oneEvent' + hash.length).addEventListener('click', content, true); + hash[hash.length] = newEvent; +} +function content() { + while (contekst.childNodes.length > 0) { + contekst.removeChild(contekst.childNodes[0]); + } + var newEvent = new Event(document.forms[0]); + var el = document.getElementById('meeting').cloneNode(true); + el.className = 'elements'; + var list = el.getElementsByTagName('label'); + for (i=0; i 0) { + if (list[i].childNodes[n - 1].nodeType === 1) { + list[i].removeChild(list[i].childNodes[n - 1]); + } + n = n - 1; + } + for (k in newEvent) { + if (this.className === 'oneEventCollection') { + if (k === document.forms[0].elements[i].name && typeof newEvent[k] === 'string') { + list[i].textContent = list[i].textContent + " " + collection[this.id.charAt(this.id.length - 1)][k]; + } + if (k === document.forms[0].elements[i].name && typeof newEvent[k] !== 'string') { + list[i].textContent = list[i].textContent + " " + collection[this.id.charAt(this.id.length - 1)][k].value; + } + } else { + if (k === document.forms[0].elements[i].name && typeof newEvent[k] === 'string') { + list[i].textContent = list[i].textContent + " " + hash[this.id.charAt(this.id.length - 1)][k]; + } + if (k === document.forms[0].elements[i].name && typeof newEvent[k] !== 'string') { + list[i].textContent = list[i].textContent + " " + hash[this.id.charAt(this.id.length - 1)][k].value; + } + } + } + } + console.log(el.getElementsByTagName('input').length); + el.removeChild(el.childNodes[el.childNodes.length - 2]); + contekst.appendChild(el); +} +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); +} +function filterAll() { + "use strict"; + var collection2 = []; + while (spisok.childNodes.length > 0) { + spisok.removeChild(spisok.childNodes[0]); + } + if (document.forms[1].elements[0].value === "предстоящие") { + collection2 = new FilterToDate(hash, 1); + } + if (document.forms[1].elements[0].value === "прошедшие") { + collection2 = new FilterToDate(hash, -1); + } + if (document.forms[1].elements[0].value === "я не участвую") { + collection2 = new FilterToParty(hash, -1); + } + if (document.forms[1].elements[0].value === "я участвую") { + collection2 = new FilterToParty(hash, 1); + } + + if (document.forms[1].elements[1].value === "предстоящие") { + collection = new FilterToDate(collection2, 1); + } + if (document.forms[1].elements[1].value === "прошедшие") { + collection = new FilterToDate(collection2, -1); + } + if (document.forms[1].elements[1].value === "я не участвую") { + collection = new FilterToParty(collection2, -1); + } + if (document.forms[1].elements[1].value === "я участвую") { + collection = new FilterToParty(collection2, 1); + } + if (document.forms[1].elements[1].value === "сортировать по дате") { + collection = [].concat(new SortToDate(collection2)); + } + for (i = 0; i < collection.length; i ++) { + var el = document.createElement('div'); + el.className = 'oneEventCollection'; + el.setAttribute('id', 'oneEvent' + i); + el.textContent = collection[i].start + "-" + collection[i].end + " " + collection[i].name; + spisok.appendChild(el); + document.getElementById('oneEvent' + i).addEventListener('click', content, true); + } +} + +function all() { + "use strict"; + while (spisok.childNodes.length > 0) { + spisok.removeChild(spisok.childNodes[0]); + } + for (i = 0; i < hash.length; i++) { + var el = document.createElement('div'); + el.className = 'oneEvent'; + el.setAttribute('id', 'oneEvent' + i); + el.textContent = hash[i].start + "-" + hash[i].end + " " + hash[i].name; + spisok.appendChild(el); + document.getElementById('oneEvent' + i).addEventListener('click', content, true); + } +} + +// функции фильтрации +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('-'); + return new Date(dateParts[0], dateParts[1], dateParts[2]); + } +} +function FilterToDate(collection, flag) { + "use strict"; + var result; + if (flag === -1) { + result = collection.filter(function (collection) { + var s = str2date(collection.start); + return s < new Date(); + }); + } else { + result = collection.filter(function (collection) { + var s = str2date(collection.start); + return s >= new Date(); + }); + } + return result; +} +function FilterToParty(collection, flag) { + "use strict"; + var result; + if (flag === -1) { + result = collection.filter(function (collection) { + return collection.party === "нет"; + }); + } else { + result = collection.filter(function (collection) { + return collection.party === "да"; + }); + } + return result; +} +function SortToDate(collection) { + "use strict"; + collection.sort(function (a, b) { + return str2date(a.start) > str2date(b.start) ? 1 : -1; + }); + return collection; +} + diff --git a/forma.html b/forma.html new file mode 100644 index 0000000..b67196f --- /dev/null +++ b/forma.html @@ -0,0 +1,77 @@ + + + + Вывод информации о событиях + + + + + +
+
Создать новое событие
+
+ + + + + + + + + + +
+
+
+
+ + + + +
+
+
+
+ + \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..851ad59 --- /dev/null +++ b/style.css @@ -0,0 +1,36 @@ +.l-level{ + width: 500px; + // margin: 0 auto; + padding: 20px; + font: italic 14px Georgia; + float: right; + } + .t-block{ + font-size: 1.3em; + font-style: italic; + } + .meeting{ position: relative; width: 500px; padding: 10px;} + .meeting label {display: block; padding-bottom: 10px; overflow: hidden;} + .meeting .info {display: block; width: 494px; margin: 10px 0 10px 0;} + .meeting input { float: right;} + .party label, .organize label{ + padding-left: 30px; + } + .b-submit { width: 300px; margin: 10px 100px 10px 100px;} + .party {overflow: hidden;} + .meeting select {margin: 0 10px;} + .l-spisok { + padding: 20px; + // width: 200px; + float: left; + } + .l-spisok form{ + padding-bottom: 10px; + } + .oneEvent, .oneEventCollection { + margin-bottom: 10px; + background-color: blue; + padding: 5px 10px; + } + .contekst {overflow:hidden; padding-top: 20px;} + .contekst label {display: block;} \ No newline at end of file