/*
Klasa Storage - sluzy do trzymania roznych rzeczy w pamieci
Obsluga:
J2CS_Storage.set(name, value) - ustawia wartosc
J2CS_Storage.get(name) - zwraca wartosc lub false jesli nie ma takiej wartosci
*/
var J2CS_Storage = new function() {
this.storage = [];
this.set = function(name, value) {
this.storage[name] = value;
}
this.get = function(name) {
if(this.storage[name] != undefined) {
return this.storage[name];
} else {
return false;
}
}
}
/*
Klasa Request - odpowiada ogolnie za polaczenia ajaxowe.
Tutaj sa zdefiniowane akcje do wykonania.
Zadanie nalezy obslugiwac nastepujaco:
var retval = J2CS_Request.get(options);
lub
var retval = J2CS_Request.post(options);
Struktura options:
options = {
name: "nazwa_akcji",
pozostale: "dane",
ktore: "wysylane",
sa: "getem lub postem"
}
Struktura zwracanych danych (czyli to, co musi byc zwrocone przez PHP, sformatowane do Jsona):
data = {
name: "nazwa_akcji",
dane: "z phpa",
ktore: "trzeba odczytac"
}
Lista akcji, co powinno byc w options i co powinno byc w zwrotnym data:
- get:
- { name: "init" } -> { name: "init", app: i, access_id: i, instructions_on: 0/1, first_section: i, first_subject: i, fault: 0/1, old_link_active: 0/1 }
- { name: "instructions", index: 1/2/3 } -> { name: "instructions", header: "naglowek", content: "html do wyswietlenia" }
- { name: "get_gwo_trials" } -> { name: "get_gwo_trials", data: { id1: name1, id2: name2, ... } }
- { name: "get_saved_trials" } -> { name: "get_saved_trials", data: {id1: {name: name1, date: date1}, id2: {name: name2, date: date2} } } /// pobierz liste klasowek apisanych (posortowane po id DESC)
- { name: "load_library", index: i } -> {name: "load_library, data: {id1: name1, id2: name2, ...}}
- { name: "load_gwo_trial", index: i } -> {name: "load_gwo_trial", data: {id1: name1, id2: name2, ...}}
- { name: "load_saved_trial", index: i } -> {name: "load_gwo_trial", data: {id1: name1, id2: name2, ...}} // pobierz liste zadan do klasowki o id i
- { name: "saved_trial_delete", id: i } -> {name: "saved_trial_delete", status: 0/1}
- { name: "clones_for_exercise", index: i } -> { name: "clones_for_exercise", data: {id1: url1, id2, url2, ... }}
- { name: "load_sections" } -> { name: "load_sections", data: {id1: name1, id2: name2, ...}}
- { name: "load_subjects", section: i } -> { name: "load_subjects", data: {id1: name1, id2: name2, ...}}
- post:
*/
var J2CS_Request = new function() {
this.get = function(options) {
if(options.name == undefined) {
alert("J2CS_Request: name not specified");
return;
}
var type = "GET",
get_ = undefined;
if(options.name == "send_trial") {
options.data = {};
for(s in J2CS_Trial.sort_orders_) {
if(!J2CS_Trial.sort_orders_.hasOwnProperty(s)) continue;
var i = J2CS_Trial.sort_orders_[s];
var ex = J2CS_Trial.exercises_[i];
if(!ex) continue;
var entry = { exercise_id: ex.id, subject_id: ex.subject_id, height: ex.height, sort_order: s }
options.data[s] = entry;
}
get_ = '?name=send_trial&data=post';type='POST';
//type = "POST";
}
var s = this.request(type, options, get_);
return s;
}
this.post = function(options) {
if(options.name == undefined) {
alert("J2CS_Request: name not specified");
return;
}
var s = this.request("POST", options);
return s;
}
this.request = function(method_, data_, get_) {
get_ = get_ || '';
$.ajax("/application/command" + get_, { type: method_, data: data_ , success: this.callback, async: false, dataType: "json" }, "json");
}
this.callback = function(data, textStatus, jqXHR) {
if(data.name == "init") {
if(data.fault != 1) {
J2CS_Storage.set("access", data);
J2CS_Storage.set("trial_header_type", 1);
J2CS_Storage.set("trial_format_type", 1);
J2CS_Storage.set("trial_name", "Twój temat klasówki");
J2CS_Storage.set("user_name", data.user_name);
J2CS_Storage.set("old_link_active", data.old_link_active);
} else {
alert("Nic nie działa. Nie da się pracować.");
}
}
if(data.name == "instructions") {
J2CS_Builder.set_instructions(data);
}
if(data.name == "content") {
}
if(data.name == "get_gwo_trials") {
J2CS_Builder.set_gwo_trials(data.data);
}
if(data.name == "get_saved_trials") {
J2CS_Builder.set_saved_trials(data.data);
}
if(data.name == "load_library") {
//if(advLogger) $.post('/catchNotice.php', {data:data});
if(advLogger) advLogs.push({action:'request.load_library',data:data});
J2CS_Builder.load_library(data.data);
}
if(data.name == "load_gwo_trial") {
J2CS_Storage.set("trial_name", data.title);
J2CS_Storage.set("trial_format_type", data.type);
J2CS_Storage.set("trial_header_type", data.header);
J2CS_Storage.set("group_count", data.groups);
//J2CS_Request.get({name: "set_trial_options", data: { header: data.header, format: data.type }});
J2CS_Builder.load_trial(data.data);
if(data.section != 0 && data.section != 0){
J2CS_Request.get({name: "load_subjects", section: data.section});
$("#library_selectors .section_selector").val(data.section);
$("#library_selectors .subject_selector").val(data.subject);
J2CS_Storage.set("current_section",data.section);
J2CS_Storage.set("current_subject",data.subject);
J2CS_Request.get({name: "load_library", index: data.subject});
}
}
if(data.name == "load_saved_trial") {
J2CS_Storage.set("trial_name", data.title);
J2CS_Request.get({name: "set_trial_name", value: data.title});
J2CS_Storage.set("trial_format_type", data.type);
J2CS_Storage.set("trial_header_type", data.header);
J2CS_Storage.set("group_count", data.groups);
J2CS_Storage.set("show_difficulty", data.show_difficulty);
if(data.changed == '1'){
J2CS_Scripter.showChangedTrialNotification(data.id);
}
J2CS_Builder.load_trial(data.data);
}
if(data.name == "clones_for_exercise") {
var s = [];
var exid = 0;
for(var i in data.data) {
if(!data.data.hasOwnProperty(i)) continue;
var d = data.data[i];
var cl = new J2CS_Clone();
cl.construct(i, d.exercise_id, d.url);
s[s.length] = i;
exid = d.exercise_id;
J2CS_Storage.set("Clone_"+i, cl);
}
J2CS_Storage.set("ClonesFor_"+exid, s);
}
if(data.name == "load_sections") {
//if(advLogger) $.post('/catchNotice.php', {data:data});
if(advLogger) advLogs.push({action:'request.load_sections',data:data});
var ob = $("#library_selectors .section_selector");
ob.children().remove();
var d = data.data;
var c = false;
for(i in d) {
if(!d.hasOwnProperty(i)) continue;
if(!c) {
J2CS_Storage.set("current_section",d[i].id);
c = true;
}
var el = $("");
el.attr("value",d[i].id);
el.html(d[i].name);
ob.append(el);
}
}
if(data.name == "load_subjects") {
//if(advLogger) $.post('/catchNotice.php', {data:data});
if(advLogger) advLogs.push({action:'request.load_subjects',data:data});
var ob = $("#library_selectors .subject_selector");
ob.children().remove();
var d = data.data;
var c = false;
for(i in d) {
if(!d.hasOwnProperty(i)) continue;
if(!c) {
J2CS_Storage.set("current_subject", d[i].id);
c = true;
}
var el = $("");
el.attr("value",d[i].id);
el.html(d[i].name);
ob.append(el);
}
}
if(data.name == "get_group_count") {
J2CS_Storage.set("group_count",data.value);
}
if(data.name == "get_show_difficulty") {
J2CS_Storage.set("show_difficulty",data.value);
}
if(data.name == "send_trial") {
J2CS_Storage.set("trial_clones", data.data);
}
if(data.name == "get_trial_name") {
J2CS_Storage.set("trial_name", data.value);
}
if(data.name == "get_trial_header_type") {
J2CS_Storage.set("trial_header_type", data.value);
}
if(data.name == "get_trial_format_type") {
J2CS_Storage.set("trial_format_type", data.value);
}
if(data.name == 'get_trial_subjects'){
J2CS_Storage.set('trial_subjects',data.data);
}
}
}
J2CS_Clone = function() {
this.id = 0;
this.exercise_id = 0;
this.url = "";
this.construct = function(id, exercise_id, url) {
this.id = id;
this.exercise_id = exercise_id;
this.url = url; // exers/_section_id_/_subject_id_/_exercise_id_/_clone.png
}
}
J2CS_Exercise = function() {
this.id = 0;
this.subject_id = 0;
this.subject = "";
this.difficulty = 0;
this.time_needed = 0;
this.additional = 0;
this.height = 0;
this.count = 0;
this.info = "";
this.url = "";
this.construct = function(id, subject_id, subject, difficulty, time_needed, additional, url, height, count, info) {
this.id = id;
this.subject_id = subject_id;
this.subject = subject;
this.difficulty = difficulty;
this.time_needed = time_needed;
this.additional = additional;
this.url = url;
this.height = height;
this.count = count;
this.info = info;
J2CS_Storage.set("Exercise_"+id, this);
}
this.html = function(){
var additional = '';
if(this.additional == 1){
additional = '
';
}
var html = '';
html += '
';
html += '
';
html += '

';
return html;
}
this.Clones = function() {
// tablica klonow. jesli zapisana klasowka - wczytaj w zapisanej kolejnosci
// zastosuj Storage jako Cache
if(this.url == "strip") {
var ret = [];
return ret;
}
if(!J2CS_Storage.get("ClonesFor_"+this.id)) {
J2CS_Request.get({name: "clones_for_exercise", index: this.id});
}
var clones_ids = J2CS_Storage.get("ClonesFor_"+this.id);
var clones = {};
for(var i in clones_ids) {
var id = clones_ids[i];
clones[id] = J2CS_Storage.get("Clone_"+id);
}
return clones;
}
}
var J2CS_Library = new function() {
this.current_subject_id = parseInt(J2CS_Storage.get("current_subject_id"));
this.exercises_ = {};
this.sort_orders_ = [];
this.construct = function(data) {
if(advLogger) advLogs.push({action:"library.construct",data:data});
this.reset();
for(var i in data) {
if(data.hasOwnProperty(i)) {
if(J2CS_Trial.getExercise(data[i].id) == false) {
this.addExercise(data[i].id, data[i]);
}
}
}
if(advLogger) advLogs.push({action:"library.constructAfter",orders:this.sort_orders_});
this.makeBuild();
}
this.makeBuild = function() {
//if(advLogger) $.post('/catchError.php', {action:"build",list:this.exercises_,order:this.sort_orders_});
if(advLogger) advLogs.push({action:'library.build',exercises:this.exercises_,order:this.sort_orders_});
var container = $("#library_ul");
container.children().each(function() {
if(! $(this).hasClass("strip")){
$(this).remove();
}
});
$("#library_container").scrollTop(0);
for(i in this.sort_orders_) {
if(!this.sort_orders_.hasOwnProperty(i)) continue;
var ex = this.exercises_[this.sort_orders_[i]];
var li = $("");
li.attr("relid", this.sort_orders_[i]);
li.html(ex.html());
container.append(li);
}
if(advLogger) advLogs.push({action:'library.buildAfter',exercises:this.exercises_,order:this.sort_orders_});
}
this.addExercise = function(id, data) {
var ex = new J2CS_Exercise();
ex.construct(id, data.subject_id, data.subject, data.difficulty, data.time_needed, data.additional, data.url, data.height, data.count, data.info);
var stamper = 1;
this.exercises_[id] = ex;
var sort_orders = [];
if(advLogger) advLogs.push({action:"library.addExercise",id:id,data:data,orders:this.sort_orders_});
var ordLength = this.sort_orders_.length;
if(ordLength > 0) {
for(var i = 0; i < ordLength; i++) {
var exid = this.sort_orders_[i];
if(!exid) continue;
if(stamper == 1 && this.exercises_[exid].difficulty == ex.difficulty && exid > id) {
sort_orders.push(id);
stamper = 0;
}
else if(stamper == 1 && this.exercises_[exid].difficulty > ex.difficulty) {
sort_orders.push(id);
stamper = 0;
}
//if(advLogger) advLogs.push({action:"library.addExercise",do:"addSort",id:exid});
sort_orders.push(exid);
}
}
if(stamper == 1) { // kiedy jest to jedyne zadanie w library lub o najwi�kszym id
if(advLogger) advLogs.push({action:"library.addExercise",do:"addSortLast",id:id});
sort_orders.push(id);
}
if(advLogger) advLogs.push({action:"library.addExerciseBMid",orders:this.sort_orders_});
this.sort_orders_ = sort_orders;
if(advLogger) advLogs.push({action:"library.addExerciseMid",orders:this.sort_orders_});
J2CS_Trial.removeExercise(id);
if(advLogger) advLogs.push({action:"library.addExerciseAfter",orders:this.sort_orders_});
}
this.removeRebuild = function(id) {
if(advLogger) advLogs.push({action:"library.removeRebuild",id:id});
if(this.removeExercise(id)) {
this.makeBuild();
}
}
this.removeExercise = function(id) {
if(this.exercises_[id] != undefined) {
delete this.exercises_[id];
var sort_orders = [];
var ordLength = this.sort_orders_.length;
if(ordLength > 0) {
for(var i = 0; i < ordLength; i++) {
if(this.sort_orders_[i] != id) {
sort_orders.push(this.sort_orders_[i]);
}
}
}
this.sort_orders_ = sort_orders;
return true;
}
return false;
}
this.getExercise = function(index) {
if(this.exercises_[index] != undefined) {
return this.exercises_[index];
}
return false;
}
this.reset = function() {
if(advLogger) advLogs.push({action:'library.reset'});
this.current_subject_id = parseInt(J2CS_Storage.get("current_subject_id"));
this.exercises_ = {};
this.sort_orders_ = [];
}
}
var J2CS_Trial = new function() {
this.exercises_ = {};
this.sort_orders_ = [];
this.construct = function(data) {
this.reset();
if(advLogger) advLogs.push({action:"trial.construct",exercises:this.exercises_,orders:this.sort_orders_});
var a = 0;
for(var i in data) {
if(data.hasOwnProperty(i)) {
this.addExercise(data[i].id, ++a, data[i]);
}
}
if(advLogger) advLogs.push({action:"trial.constructAfter"});
this.makeBuild();
}
this.addExercise = function(id, sort_order, data) {
var ex = new J2CS_Exercise();
ex.construct(id, data.subject_id, data.subject, data.difficulty, data.time_needed, data.additional, data.url, data.height, data.count, data.info);
this.exercises_[id] = ex;
this.sort_orders_[sort_order] = id;
J2CS_Library.removeExercise(id);
}
this.removeRebuild = function(id) {
if(this.removeExercise(id)) {
this.makeBuild();
}
}
this.removeExercise = function(id) {
if(this.exercises_[id] != undefined) {
delete this.exercises_[id];
for(var i in this.sort_orders_) {
if(!this.sort_orders_.hasOwnProperty(i)) continue;
if(this.sort_orders_[i] == id) {
delete this.sort_orders_[i];
}
}
return true;
}
return false;
}
this.getExercise = function(index) {
if(this.exercises_[index] != undefined && this.exercises_.hasOwnProperty(index)) {
return this.exercises_[index];
}
return false;
}
this.reset = function() {
this.sort_orders_ = [];
this.exercises_ = {};
}
this.makeBuild = function() {
var container = $("#trial_ul");
if(advLogger) advLogs.push({action:"trial.makeBuild",orders:this.sort_orders_});
container.children().each(function() {
if(! $(this).hasClass("trialheader")){
$(this).remove();
}
});
for(s in this.sort_orders_) {
if(!this.sort_orders_.hasOwnProperty(s)) continue;
var i = this.sort_orders_[s];
var ex = this.exercises_[i];
var li = $("");
if(ex.url == "strip") {
li.attr("relid", i);
if(ex.subject_id == -1) {
li.addClass("strip").addClass("blank");
} else {
li.addClass("strip").addClass("check");
}
if(container.hasClass("window_wide")) {
li.css("height", (ex.height*2)+"px");
} else {
li.css("height", (ex.height)+"px");
}
li.html('');
} else {
li.attr("relid", i);
li.html(ex.html());
}
container.append(li);
}
J2CS_Scripter.updateStep2MenuItems();
}
this.updateSortOrders = function() {
var container = $("#trial_ul");
this.sort_orders_ = [];
var a = 1;
container.children().each(function(i) {
if(! $(this).hasClass("trialheader")) {
J2CS_Trial.sort_orders_[i] = $(this).attr("relid");
}
});
}
}
/*
Klasa Builder - odpowiada za zbudowanie widokow kolejnych krokow
Obsluga:
J2CS_Builder.load_step(i) - zbuduj widok kroku i, a nastepnie odpal oskryptowanie widoku
*/
var J2CS_Builder = new function() {
this.load_step = function(index) {
J2CS_Request.get({name: "instructions", value: index});
if(!J2CS_Storage.get("hide_instructions_"+index)) {
J2CS_Storage.set("hide_instructions_"+index, true);
}
var content = J2CS_Request.get({name: "content", value: index});
if(index == 1) {
var construction_site = $("#first_step_construction").clone();
}
if(index == 2) {
var construction_site = $("#second_step_construction").clone();
var libopen = J2CS_Storage.get("step2_library_opened");
if(libopen) {
construction_site.find("#trial_container").removeClass("window_wide").addClass("window_thin");
construction_site.find("#trial_ul").removeClass("window_wide").addClass("window_thin");
construction_site.find("#library_container").removeClass("window_thin").addClass("window_wide");
construction_site.find("#library_ul").removeClass("window_thin").addClass("window_wide");
} else {
construction_site.find("#library_container").removeClass("window_wide").addClass("window_thin");
construction_site.find("#library_ul").removeClass("window_wide").addClass("window_thin");
construction_site.find("#trial_container").removeClass("window_thin").addClass("window_wide");
construction_site.find("#trial_ul").removeClass("window_thin").addClass("window_wide");
}
}
if(index == 3) {
var construction_site = $("#third_step_construction").clone();
}
$("#inner_container").html(construction_site.html());
J2CS_Scripter.init_step(index);
}
this.set_instructions = function(data) {
if(data.header != undefined) {
$("#instructions").find("#instructions_top_header").html(data.header);
$("#instructions").find("#instructions_content").html(data.content);
}
}
this.show_instructions = function(data) {
this.show_overlay();
$("#instructions").show();
}
this.show_welcome = function(){
this.show_overlay();
$("#welcome").show();
}
this.hide_welcome = function(){
if($("#firefox-printing-info").is(":hidden")){
this.hide_overlay();
}
$("#welcome").hide();
}
this.show_firefox_printing_info = function(){
this.show_overlay();
$("#firefox-printing-info").show();
}
this.hide_firefox_printing_info = function(){
this.hide_overlay();
$("#firefox-printing-info").hide();
}
this.hide_instructions = function() {
this.hide_overlay();
$("#instructions").hide();
}
this.show_overlay = function() {
$("#overlay").show();
}
this.hide_overlay = function() {
$("#overlay").hide();
}
this.set_gwo_trials = function(list) {
var container = $("#step1_tab1c ul");
container.children().remove();
for(var i in list) {
var del = '';
if(container.attr('admin') == 'admin'){
del = 'usuń';
}
var li = $("");
li.attr("relid", list[i].id);
li.html(del + ''+list[i].name+'');
container.append(li);
}
}
this.set_saved_trials = function(list) {
var container = $("#step1_tab2c ul");
container.children().remove();
for(var i in list) {
var li = $("");
li.attr("relid", list[i].id);
li.html('usuń'+
'wczytaj'+
''+list[i].date+' '+list[i].name+'');
container.append(li);
}
}
this.start_blank_creator = function() {
J2CS_Scripter.reset_compositor();
this.load_step(2);
J2CS_Request.get({name: "load_sections"});
J2CS_Request.get({name: "load_subjects", section: J2CS_Storage.get("current_section")});
J2CS_Request.get({name: "load_library", index: J2CS_Storage.get("current_subject")});
J2CS_Storage.set("trial_name", "Klasówka");
J2CS_Storage.set("trial_header_type", 1);
J2CS_Storage.set("trial_format_type", 1);
J2CS_Request.get({name: "set_trial_name", value: "Klasówka"});
J2CS_Request.get({name: "set_trial_options", data: {header: 1, format: 1}});
J2CS_Request.get({name: "set_group_count", value: 2});
J2CS_Storage.set("group_count",2);
J2CS_Request.get({name: "set_show_difficulty", value: 1});
J2CS_Storage.set("show_difficulty",1);
J2CS_Scripter.start_engine();
}
this.start_gwo_trial = function(id) {
J2CS_Scripter.reset_compositor();
this.load_step(2);
J2CS_Request.get({name: "load_sections"});
J2CS_Request.get({name: "load_subjects", section: J2CS_Storage.get("current_section")});
J2CS_Request.get({name: "load_gwo_trial", index: id});
J2CS_Request.get({name: "load_library", index: J2CS_Storage.get("current_subject")});
J2CS_Scripter.start_engine();
}
this.start_saved_trial = function(id) {
J2CS_Scripter.reset_compositor();
this.load_step(2);
J2CS_Request.get({name: "load_sections"});
J2CS_Request.get({name: "load_subjects", section: J2CS_Storage.get("current_section")});
J2CS_Request.get({name: "load_saved_trial", index: id});
J2CS_Request.get({name: "load_library", index: J2CS_Storage.get("current_subject")});
J2CS_Scripter.start_engine();
}
this.load_library = function(list) {
if(advLogger) advLogs.push({action:"builder.loadLib"});
J2CS_Library.construct(list);
if(advLogger) advLogs.push({action:"builder.loadLibAfter"});
}
this.load_trial = function(list) {
if(advLogger) advLogs.push({action:"builder.loadTrial",data:list});
J2CS_Trial.construct(list);
if(advLogger) advLogs.push({action:"builder.loadTrialAfter"});
J2CS_Scripter.start_engine();
J2CS_Scripter.setTrialIcon();
}
}
/*
Klasa Scripter - odpowiada za ciaglosc wykonania programu, ustawienie wszystkich przyciskow,
uruchomienie skryptow w krokach i tak dalej
Obsługa:
J2CS_Scripter.init() - ustaw glowne przyciski
J2CS_Scripter.init_step(i) - uruchom krok i
*/
var J2CS_Scripter = new function() {
this.init = function() {
this.reset_compositor();
if(advLogger) {
var _navigator = {};
if(navigator) for (var i in navigator) _navigator[i] = navigator[i];
$.post('/catchNotice.php', {navigator:JSON.stringify(_navigator)});
}
J2CS_Request.get({name: "init"});
J2CS_Request.get({name: "get_trial_name"});
J2CS_Request.get({name: "get_trial_header_type"});
J2CS_Request.get({name: "get_trial_format_type"});
if(J2CS_Storage.get('old_link_active') && ($.cookie('welcome_shown') != 1)){
J2CS_Builder.show_welcome();
}
$("#instructions_top_close, #instructions_closer").click(function() {
$("#instructions").effect("transfer", {to: $("#inner_container .help_toggler"), easing: "easeOutQuint", className: "ui-effects-transfer"}, 1000);
J2CS_Builder.hide_instructions();
});
$('#welcome_top_close').click(function(){
$("#welcome").effect("transfer", {to: $("#inner_container .help_toggler"), easing: "easeOutQuint", className: "ui-effects-transfer"}, 1000);
J2CS_Builder.hide_welcome();
});
$('#firefox-printing-info_top_close').click(function(){
$("#firefox-printing-info").effect("transfer", {to: $("#inner_container .help_toggler"), easing: "easeOutQuint", className: "ui-effects-transfer"}, 1000);
J2CS_Builder.hide_firefox_printing_info();
});
$('#welcome input[name=show_dialog]').click(function(){
if($(this).is(':checked')){
$.cookie('welcome_shown',1, { expires: 365 });
}else{
$.cookie('welcome_shown',null);
}
});
$('#firefox-printing-info input[name=show_dialog]').click(function(){
if($(this).is(':checked')){
$.cookie('firefox-printing-info',1, { expires: 365 });
}else{
$.cookie('firefox-printing-info',null);
}
});
$(".help_toggler").live("click", function() {
J2CS_Builder.show_instructions({});
});
$("#trial_options_dialog_save").live("click",function() {
var container = $("#trial_options_dialog");
var header_type = container.find("input:radio[name=trial_options_header]:checked").val();
var format_type = container.find("input:radio[name=trial_options_format]:checked").val();
J2CS_Storage.set("trial_header_type", header_type);
J2CS_Storage.set("trial_format_type", format_type);
$("#trial_ul li.trialheader").removeClass("header_1").removeClass("header_2").removeClass("header_3").removeClass("header_4");
$("#trial_ul li.trialheader").addClass("header_"+header_type);
$("#trial_ul li.trialheader img").attr("src", "exers/header"+header_type+"f.png");
J2CS_Request.get({name: "set_trial_options", data: {header: header_type, format: format_type}});
/* Sprawdzamy, czy nazwa klasówki nie przekracza limitu dla nagłówka */
var maxlength = (header_type == 4) ? 51 : 40;
var tname = J2CS_Storage.get('trial_name');
if (tname.length > maxlength) {
tname = tname.substr(0, maxlength);
J2CS_Storage.set("trial_name", tname);
J2CS_Request.get({name: "set_trial_name", value: tname});
$('.trial_name').html(tname + ' zmień nazwę');
}
$("#trial_options_dialog").hide();
J2CS_Scripter.updateStep2MenuItems(1);
J2CS_Scripter.setTrialIcon();
J2CS_Builder.hide_overlay();
});
$("#trial_options_dialog_top_close").live("click",function() {
$("#trial_options_dialog").hide();
J2CS_Builder.hide_overlay();
});
$('.actions .info').live('mouseover',function(event){
var li = $(this).parent().parent().parent();
var ul = li.parent();
var id = li.attr('relid');
if(ul.attr('id') == 'trial_ul'){
var exercise = J2CS_Trial.getExercise(id);
}else{
var exercise = J2CS_Library.getExercise(id);
}
var levels = ['łatwe','średnio trudne','trudne','bardzo trudne'];
var difficulty = levels[exercise.difficulty - 1];
var html = "";
if(exercise.info.length > 0) {
html += codi2html(exercise.info)+"
";
}
html += 'Temat: ' + exercise.subject + '
';
html += 'Czas wykonywania: ' + exercise.time_needed + ' min
';
html += 'Poziom trudności: ' + difficulty + '
';
html += 'Liczba wariantów: ' + exercise.count + '
';
html += 'Numer identyfikacyjny: ' + exercise.id + '';
if(exercise.additional == 1){
html += "
Zadanie spoza podstawy programowej"
}
var info = $("").addClass('tooltip').html(html);
var offset = $(this).offset();
info.css({
top : offset.top + 25,
right : $(window).width() - offset.left - 25
});
$('body').append(info);
});
$('.actions .info').live('mouseout',function(){
$('.tooltip').remove();
});
$(".go_to_third_step.clickable").live('click',function() {
var trial_name_ = $("#outer_container #trial_ul .trial_name").clone();
trial_name_.find(".trial_name_changer").remove();
var trial_name = trial_name_.text();
J2CS_Request.get({name: "set_trial_name", value: trial_name});
J2CS_Builder.load_step(3);
});
$("#step2_menu_accept.clickable").live('click',function() {
var trial_name_ = $("#outer_container #trial_ul .trial_name").clone();
trial_name_.find(".trial_name_changer").remove();
var trial_name = trial_name_.text();
J2CS_Request.get({name: "set_trial_name", value: trial_name});
J2CS_Builder.load_step(3);
});
$("#step2_menu_accept.alert").live('click',function(){
var excnt = parseInt($("#inner_container #step2_menu_excnt").text());
if(excnt > 30) {
J2CS_Scripter.showToManyExersAlert();
} else {
J2CS_Scripter.showToManyA5PagesAlert();
}
});
if(advLogger) this.init_advLogger();
setInterval(function(){
J2CS_Request.get({name: "get_trial_name"});
},1000 * 60 * 5)
}
this.init_advLogger = function() {
/*
watch(J2CS_Trial, function(a, b, c) {
console.log('trial changed', a, b, c);
}, 3);
watch(J2CS_Library, function(a, b, c) {
console.log('library changed', a, b, c);
}, 3);
watch(J2CS_Request, function(a, b, c) {
console.log('request changed', a, b, c);
}, 3);
*/
}
this.init_step = function(index) {
var inits = J2CS_Storage.get("access");
$(".main_header_accessname").html(inits.access_name);
if(index == 1) {
J2CS_Request.get({name: "get_gwo_trials"});
J2CS_Request.get({name: "get_saved_trials"});
J2CS_Storage.set("step2_library_opened",false);
$('#inner_container #step1_tab1c ul[admin=admin]').sortable({
axis : 'y',
update: function(event,ui){
var sort_order = {};
ui.item.parent().children().each(function(index,element){
sort_order[index] = {trial : $(element).attr('relid'), order : index};
});
J2CS_Request.get({name: 'set_gwo_trials_order',data: sort_order});
}
});
$("#goto_old_version").click(function() {
var access = J2CS_Storage.get("access");
window.location.href = "/app_data/kompozytor/?hash="+(access.hash);
});
$("#step1_tabbler ul.step1_tabs li").removeClass("active");
$("#step1_tabbler_c div").hide();
$("#step1_tab1c").show();
$("#step1_tab1").addClass("active");
$("#step1_tabs li").click(function(event) {
$(this).parent().removeClass().addClass($(this).attr('id'));
$(this).siblings().removeClass("active");
$("#step1_tabbler_c div").hide();
$("#"+$(this).attr("id")+"c").show();
$(this).addClass("active");
});
$(".step1_button.delete").click(function() {
var trialid = $(this).parent().attr("relid");
var trialname = $(this).parent().find(".trialname").text();
J2CS_Builder.show_overlay();
var position = $("#outer_container").position();
var left = position.left + 320;
$("#trial_delete_dialog").css("left",left+"px");
$("#trial_delete_dialog .trial_delete_dialog_trialname").html(trialname);
$("#trial_delete_confirm").attr("relid", trialid);
$("#trial_delete_dialog").show();
});
$("#trial_delete_confirm").click(function() {
var id_ = $(this).attr("relid");
J2CS_Request.get({name: "saved_trial_delete", id: id_});
var ob = $("li[relid="+id_+"]");
ob.remove();
J2CS_Builder.hide_overlay();
$("#trial_delete_dialog").hide();
});
$("#trial_delete_deny").click(function() {
J2CS_Builder.hide_overlay();
$("#trial_delete_dialog").hide();
});
$(".go_to_second_step.clickable").click(function() {
J2CS_Trial.reset();
J2CS_Builder.start_blank_creator();
});
$("#step1_blankstart").click(function() {
J2CS_Builder.start_blank_creator();
return false;
});
$("#step1_tab1c .forward").click(function() {
var id = parseInt($(this).parents("li").first().attr("relid"));
var trial_name_ = $(this).parent().clone();
trial_name_.find("a").remove();
var trial_name = trial_name_.text();
J2CS_Request.get({name: "set_trial_name", value: trial_name});
J2CS_Storage.set("trial_name", trial_name);
J2CS_Builder.start_gwo_trial(id);
});
$("#step1_tab2c .step1_button.forward").click(function() {
var id = parseInt($(this).parents("li").first().attr("relid"));
J2CS_Builder.start_saved_trial(id);
});
}
if(index == 2) {
// uruchomienie zadan
$("#library_selectors .section_selector").val(J2CS_Storage.get("current_section"));
$("#library_selectors .subject_selector").val(J2CS_Storage.get("current_subject"));
$("#library_selectors .section_selector").change(function() {
J2CS_Storage.set("current_section", $(this).val());
J2CS_Request.get({name: "load_subjects", section: J2CS_Storage.get("current_section")});
J2CS_Request.get({name: "load_library", index: J2CS_Storage.get("current_subject")});
});
$("#library_selectors .subject_selector").change(function() {
J2CS_Storage.set("current_subject", $(this).val());
J2CS_Request.get({name: "load_library", index: J2CS_Storage.get("current_subject")});
});
$("#step2_swap_arrow_img").click(function() {
var check = J2CS_Storage.get("step2_library_opened");
if(check == false) {
$("#trial_ul li").each(function() {
if($(this).hasClass("strip")) {
var height = parseInt($(this).css('height'))/2;
$(this).css("height", height+"px");
}
});
$("#step2_header_trial").removeClass("active");
$("#step2_header_library").addClass("active");
$("#library_container, #library_ul").removeClass("window_thin").addClass("window_wide");
$("#trial_container, #trial_ul").removeClass("window_wide").addClass("window_thin");
J2CS_Storage.set("step2_library_opened", true);
}
else {
$("#trial_ul li").each(function() {
if($(this).hasClass("strip")) {
var height = parseInt($(this).css('height'))*2;
$(this).css("height", height+"px");
}
});
$("#step2_header_library").removeClass("active");
$("#step2_header_trial").addClass("active");
$("#library_container, #library_ul").removeClass("window_wide").addClass("window_thin");
$("#trial_container, #trial_ul").removeClass("window_thin").addClass("window_wide");
J2CS_Storage.set("step2_library_opened", false);
}
});
$("#trial_options_toggler").click(function() {
var header_type = J2CS_Storage.get("trial_header_type");
var format_type = J2CS_Storage.get("trial_format_type");
J2CS_Builder.show_overlay();
$("#trial_options_dialog").find("#trial_options_dialog_header").find("input[value="+header_type+"]").click();
$("#trial_options_dialog").find("#trial_options_dialog_format").find("input[value="+format_type+"]").click();
$("#trial_options_dialog").show();
});
$(".go_to_first_step.clickable").click(function() {
J2CS_Builder.load_step(1);
});
$("#trial_ul .trialheader .trial_name").html(J2CS_Storage.get("trial_name")+' zmień nazwę');
}
if(index == 3) {
/* Pokaż ostrzeżenie o drukowaniu PDF w Firefoksie */
var userAgent = window.navigator.userAgent.toLowerCase();
if(userAgent.indexOf("firefox") > -1){
var firefox_version = parseFloat(userAgent.substr(userAgent.length - 4, userAgent.length - 1));
if(firefox_version >= 19.0){
if($.cookie('firefox-printing-info') != 1){
J2CS_Builder.show_firefox_printing_info();
}
}
}
J2CS_Request.get({name: "send_trial"});
$(".go_to_second_step.clickable").click(function() {
J2CS_Builder.load_step(2);
J2CS_Library.makeBuild();
J2CS_Trial.makeBuild();
J2CS_Scripter.start_engine();
});
$("#go_back_to_editor").click(function() {
J2CS_Builder.load_step(2);
J2CS_Library.makeBuild();
J2CS_Trial.makeBuild();
J2CS_Scripter.start_engine();
});
if(!J2CS_Storage.get("group_count")) {
J2CS_Request.get({name: "get_group_count"});
}
$("#group_count").val(J2CS_Storage.get("group_count"));
$("#group_count").change(function() {
J2CS_Storage.set("group_count", $(this).val());
J2CS_Request.get({name: "set_group_count", value: $(this).val()});
J2CS_Scripter.start_preview();
});
if(!J2CS_Storage.get("show_difficulty")) {
J2CS_Request.get({name: "get_show_difficulty"});
}
$("#show_difficulty").attr('checked', J2CS_Storage.get("show_difficulty") == 1);
$("#show_difficulty").change(function() {
J2CS_Storage.set("show_difficulty", $(this).attr('checked') ? 1 : 0);
if ($(this).attr('checked')) {
$('#preview_ul .asterisk').text('*');
} else {
$('#preview_ul .asterisk').text('');
}
J2CS_Request.get({name: "set_show_difficulty", value: $(this).attr('checked') ? 1 : 0});
});
$("#print_all").click(function() {
var foo = new Date; // Generic JS date object
var unixtime_ms = foo.getTime(); // Returns milliseconds since the epoch
var unixtime = parseInt(unixtime_ms / 1000);
$(this).parent().attr("href","/application/pdfQuestions/?y="+unixtime);
});
$("#print_ans").click(function() {
var foo = new Date; // Generic JS date object
var unixtime_ms = foo.getTime(); // Returns milliseconds since the epoch
var unixtime = parseInt(unixtime_ms / 1000);
$(this).parent().attr("href","/application/pdfAnswers/?y="+unixtime);
});
$("#save_all").click(function() {
var dialog = $('#save').clone();
dialog.find('input[name=name]').keypress(function(e) {
// jesli w tresci sa znaki niepoprawne: ' " < > ~ % # ` / \ { } [ ] ( )
// to je usun i daj highlight
if(
e.which == 34 ||
e.which == 35 ||
e.which == 37 ||
e.which == 39 ||
e.which == 40 ||
e.which == 41 ||
e.which == 47 ||
e.which == 60 ||
e.which == 62 ||
e.which == 91 ||
e.which == 92 ||
e.which == 93 ||
e.which == 94 ||
e.which == 95 ||
e.which == 96 ||
e.which == 123 ||
e.which == 124 ||
e.which == 125 ||
e.which == 126
) {
$(this).effect("highlight",{color: "red"}, 50);
return false;
}
});
dialog.dialog({
title: 'Zapisz twój zestaw zadań',
autoOpen: true,
modal: true,
resizable: false,
draggable: false,
width: 450,
height: 235,
closeOnEscape: false,
create: function(){
var select = $(this).find('select[name=default_subject]');
$(this).find('input[name=default]').click(function(){
var default_subject = select.parent().parent();
if($(this).is(':checked')){
default_subject.css('display','block');
}else{
default_subject.css('display','none');
}
});
if(select){
J2CS_Request.get({name : 'get_trial_subjects'});
var subjects = J2CS_Storage.get('trial_subjects');
select.append('');
for(i in subjects){
var subject = subjects[i];
var option = $('');
option.val(subject.id);
option.text(subject.name);
select.append(option);
}
}
$(this).find(':checkbox').change(function(){
var input_field = dialog.find('input[name=name]');
var error_msg = dialog.find('#save_name .error');
if($(this).is(':checked')){
input_field.attr('maxlength',60);
error_msg.text(error_msg.text().replace('25', '60'));
}else{
input_field.attr('maxlength',25);
error_msg.text(error_msg.text().replace('60', '25'));
}
});
$(this).parent().find('button').removeAttr('class');
},
buttons: {
'Anuluj': function(){
$(this).dialog('destroy');
},
'Zapisz': function(){
var name_field = $(this).find('input[name=name]');
var name_value = $.trim(name_field.val());
if(name_value.length < 3 || name_value.length > name_field.attr('maxlength')){
$(this).find('#save_name .error').css('visibility','visible');
}else{
var system_field = $(this).find('input[name=default]');
var system_value = system_field.is(':checked');
var subject = null;
if(system_value){
subject = $(this).find('select[name=default_subject]').val();
}
J2CS_Request.get({name: "save_trial", value: {name: name_value, system: system_value, subject: subject}});
$(this).dialog('destroy');
}
}
}
});
});
J2CS_Scripter.start_preview();
}
}
this.updatePrintMethod = function(){
var trial_type = J2CS_Storage.get("trial_format_type");
var page_count = J2CS_Storage.get("page_count");
var info = $('#step3_print_method .step3_left_content');
if(trial_type == 2){
$('#step3_print_method').css('display','block');
if(page_count == '1'){
$('#step3_print_method .step3_left_content').text('jednostronny');
}else{
$('#step3_print_method .step3_left_content').text('dwustronny');
}
}else{
$('#step3_print_method').css('display','none');
}
}
this.reset_compositor = function() {
var access = J2CS_Storage.get("access");
J2CS_Trial.reset();
J2CS_Library.reset();
J2CS_Storage.set("current_section", access.first_section);
J2CS_Storage.set("current_subject", access.first_subject);
}
this.setTrialIcon = function(){
var trial_type = J2CS_Storage.get("trial_format_type");
var type_img = $("#step2_menu_pgcnt img");
if(trial_type == 1){
type_img.attr('src','css/img/layout/pgcnt_a4.png');
}else{
type_img.attr('src','css/img/layout/pgcnt_a5.png');
}
}
this.start_engine = function() {
var header_type = J2CS_Storage.get("trial_header_type");
$("#trial_ul li.trialheader").removeClass("header_1").removeClass("header_2").removeClass("header_3").removeClass("header_4").addClass("header_"+header_type);
$("#trial_ul li.trialheader img").attr("src", "exers/header"+header_type+"f.png");
$("#trial_ul li.trialheader .trial_name").html(J2CS_Storage.get("trial_name")+' zmień nazwę');
$("#trial_ul .trial_name_changer").live("click",function() {
var parent = $(this).parent();
var sth = parent.clone();
sth.find(".trial_name_changer").remove();
var name = sth.text();
/* Tytuł egzaminu ma sięgać do końca kartki */
var maxlength = $("#trial_ul li.trialheader").hasClass('header_4') ? '51' : '40';
parent.html('');
parent.find('input').bind('mousedown.ui-disableSelection selectstart.ui-disableSelection', function(event) {
event.stopImmediatePropagation();
});
parent.find('input').val(name);
parent.find('input').focus();
parent.find('input').keypress(function(e) {
// jesli w tresci sa znaki niepoprawne: ' " < > ~ % # ` / \ { } [ ] ( )
// to je usun i daj highlight
if(
e.which == 34 ||
e.which == 35 ||
e.which == 37 ||
e.which == 39 ||
e.which == 40 ||
e.which == 41 ||
e.which == 47 ||
e.which == 60 ||
e.which == 62 ||
e.which == 91 ||
e.which == 92 ||
e.which == 93 ||
e.which == 94 ||
e.which == 95 ||
e.which == 96 ||
e.which == 123 ||
e.which == 124 ||
e.which == 125 ||
e.which == 126
) {
$(this).effect("highlight",{color: "red"}, 50);
return false;
}
});
parent.find("form").submit(function(){
var tname = $(this).find("input").val().replace(/['"<>~%#`/\\\{\}\[\]\(\)]/g, ''); // filtrowanie niepoprawnych znaków
J2CS_Storage.set("trial_name", tname);
J2CS_Request.get({name: "set_trial_name", value: tname});
var prent = $(this).parent();
var newtext = tname+' zmień nazwę';
prent.html(newtext);
return false;
});
});
$("#library_ul, #trial_ul").sortable({
cancel: '.ui-resizable-s',
connectWith: '.sortable',
items: 'li:not(.strip.stripconstructor, .trialheader)',
revert: true,
placeholder: 'highlighted_placeholder',
scroll: "yes",
appendTo: 'body',
helper: 'clone',
tolerance: 'pointer',
containment: '#outer_container #inner_container',
opacity: 0.6,
distance: 3,
zIndex: 200,
start: function(event, ui) {
ui.helper.css("list-style","none");
ui.helper.css("border","1px solid #a9c9c3");
ui.helper.css("height","auto").css("width","auto");
ui.helper.css("line-height","1px");
if(ui.item.hasClass("strip")) {
ui.helper.addClass("strip-clone");
}
$("#outer_container #trial_ul li").removeClass("first_on_page");
$(".stripconstructor").draggable("disable");
},
beforeStop: function(event, ui) {
var id = ui.helper.attr("relid");
// no wiec sa cztery przypadki
// 1. gosc pochodzi z library i laduje w library - wtedy cofnij
// 2. gosc pochodzi z library i laduje w trial - usun z library, dodaj do trial, ustaw sort_orders
// 3. gosc pochodzi z trial i laduje w library - usun z trial, jesli temat sie zgadza, to dodaj do library
// 4. gosc pochodzi z trial i laduje w trial - zaktualizuj tylko sort_orders
// no to zaczynamy
var target_list = ui.item.parent();
var target_id = target_list.attr("id");
var source_list = $(this);
var source_id = source_list.attr("id");
if(source_id == "library_ul" && target_id == "library_ul") {
// TO JEST OBSLUGIWANE Z UPDATE!!!
// $(this).sortable('cancel');
}
else if(source_id == "library_ul" && target_id == "trial_ul") {
var ex = J2CS_Library.getExercise(id);
J2CS_Trial.addExercise(id, 0, {difficulty: ex.difficulty, subject_id: ex.subject_id, subject: ex.subject, time_needed: ex.time_needed, additional: ex.additional, url: ex.url, height: ex.height, count: ex.count, info: ex.info} );
}
else if(source_id == "trial_ul" && target_id == "library_ul") {
ex = J2CS_Trial.getExercise(id);
J2CS_Trial.removeExercise(id);
if(ex.subject_id == J2CS_Storage.get("current_subject")) {
J2CS_Library.addExercise(id, {difficulty: ex.difficulty, subject_id: ex.subject_id, subject: ex.subject, time_needed: ex.time_needed, additional: ex.additional, url: ex.url, height: ex.height, count: ex.count, info: ex.info} );
} else {
ui.item.remove();
}
J2CS_Scripter.updateStep2MenuItems(2);
}
else if(source_id == "trial_ul" && target_id == "trial_ul") {
if(ui.item.hasClass("strip") && !ui.item.attr("relid")) {
$(this).find(".stripconstructortext").remove();
var newid = [];
var ss = 0;
if(ui.item.hasClass("check")) {
newid = J2CS_Scripter.getNewIdForElement("a", "check");
ss = -2;
} else if(ui.item.hasClass("blank")) {
newid = J2CS_Scripter.getNewIdForElement("b", "blank");
ss = -1;
}
J2CS_Trial.addExercise(newid[1], 0, {subject_id: ss, difficulty: 0, time_needed: 0, additional: 0, url: "strip", height: 40} );
ui.item.attr("relid",newid[1]);
if(ui.item.hasClass("check")) {
ui.item.resizable({
handles: "s",
grid: 10,
minHeight: 30,
maxHeight: 150,
minWidth: 520,
maxWidth: 520,
start: function(event, ui) {
},
resize: function(event, ui) {
J2CS_Trial.exercises_[$(this).attr("relid")].height = parseInt($(this).css("height"))/2;
},
stop: function(event, ui) {
J2CS_Scripter.updateStep2MenuItems(3);
}
});
}
else {
ui.item.resizable({
handles: "s",
minHeight: 30,
maxHeight: 150,
minWidth: 520,
maxWidth: 520,
start: function(event, ui) {
},
resize: function(event, ui) {
J2CS_Trial.exercises_[$(this).attr("relid")].height = parseInt($(this).css("height"))/2;
},
stop: function(event, ui) {
J2CS_Scripter.updateStep2MenuItems(4);
}
});
}
ui.item.removeClass("ui-draggable").removeClass("stripconstructor");
}
}
$(".stripconstructor").draggable('enable');
J2CS_Trial.updateSortOrders();
},
stop: function(event, ui) {
J2CS_Trial.updateSortOrders();
J2CS_Scripter.updateStep2MenuItems(5);
J2CS_Library.makeBuild();
$(".stripconstructor").draggable('enable');
$("#trial_ul li.strip").removeClass('ui-draggable-disabled').removeClass('ui-state-disabled').removeAttr("aria-disabled");
},
over: function(event, ui) {
},
update: function(event, ui) {
var target_list = ui.item.parent();
var target_id = target_list.attr("id");
var source_list = $(this);
var source_id = source_list.attr("id");
if(source_id == "library_ul" && target_id == "library_ul") {
$(this).sortable('cancel');
$("li.strip.check:not(li.strip.check:first)",this).remove();
$("li.strip.blank:not(li.strip.blank:first)",this).remove();
J2CS_Trial.updateSortOrders();
}
J2CS_Trial.updateSortOrders();
},
receive: function(event, ui) {
}
}).disableSelection();
$(".stripconstructor").draggable({
connectToSortable: '#trial_ul, #library_ul',
helper: 'clone',
revert: 'invalid',
revertDuration: 1,
distance: 3,
appendTo: 'body',
opacity: 0.6,
zIndex: 200,
containment: '#outer_container #inner_container',
start: function(event, ui) {
J2CS_Storage.set("draggable_start_trial_count", $("#trial_ul").children("li").length);
$(".stripconstructor").draggable('disable');
ui.helper.css("list-style","none").css("z-index", "10000");
if($(this).hasClass("check")) {
ui.helper.addClass("strip").addClass("check");
}
else {
ui.helper.addClass("strip").addClass("blank");
}
ui.helper.addClass("strip-clone");
$("#outer_container #trial_ul li").removeClass("first_on_page");
ui.helper.find(".stripconstructortext").remove();
},
stop: function(event, ui) {
if($("#trial_ul").children("li").length == J2CS_Storage.get("draggable_start_trial_count")) {
$(".stripconstructor").draggable('enable');
}
J2CS_Scripter.updateStep2MenuItems(6);
}
}).disableSelection();
$("#trial_ul li.strip").live("mouseenter", function() {
$(this).find(".ui-resizable-s").css("background-position", "0 -18px");
}).live("mouseleave", function() {
$(this).find(".ui-resizable-s").css("background-position", "0 -35px");
});
$("#outer_container #trial_ul li.strip.check").resizable({
handles: "s",
grid: 10,
minHeight: 30,
maxHeight: 150,
minWidth: 520,
maxWidth: 520,
start: function(event, ui) {
},
resize: function(event, ui) {
},
stop: function(event, ui) {
var height = parseInt($(this).css("height"));
if(height%10 != 0) {
height = Math.round(height/10)*10;
$(this).css("height",height+"px");
}
J2CS_Trial.exercises_[$(this).attr("relid")].height = height/2;
J2CS_Scripter.updateStep2MenuItems(7);
}
});
$("#outer_container #trial_ul li.strip.blank").resizable({
handles: "s",
minHeight: 30,
maxHeight: 150,
minWidth: 520,
maxWidth: 520,
start: function(event, ui) {
},
resize: function(event, ui) {
J2CS_Trial.exercises_[$(this).attr("relid")].height = parseInt($(this).css("height"))/2;
},
stop: function(event, ui) {
J2CS_Scripter.updateStep2MenuItems(8);
}
});
$("#library_ul .stripconstructor .actions .move").click(function(e) {
e.stopImmediatePropagation();
var li = $(this).parent().parent();
var newid = [];
var ss = 0;
if(li.hasClass("check")) {
newid = J2CS_Scripter.getNewIdForElement("a", "check");
ss = -2;
} else if(li.hasClass("blank")) {
newid = J2CS_Scripter.getNewIdForElement("b", "blank");
ss = -1;
}
J2CS_Trial.addExercise(newid[1], 0, {subject_id: ss, difficulty: 0, time_needed: 0, additional: 0, url: "strip", height: 40} );
var lin = li.clone();
lin.removeClass("ui-draggable").removeClass("stripconstructor");
lin.attr("relid",newid[1]);
lin.find(".stripconstructortext").remove();
lin.appendTo($("#trial_ul"));
J2CS_Trial.updateSortOrders();
J2CS_Scripter.updateStep2MenuItems(9);
if(lin.hasClass("check")) {
lin.resizable({
handles: "s",
grid: 10,
minHeight: 30,
maxHeight: 150,
minWidth: 520,
maxWidth: 520,
start: function(event, ui) {
},
resize: function(event, ui) {
J2CS_Trial.exercises_[$(this).attr("relid")].height = parseInt($(this).css("height"))/2;
},
stop: function(event, ui) {
J2CS_Scripter.updateStep2MenuItems(10);
}
});
}
else {
lin.resizable({
handles: "s",
minHeight: 30,
maxHeight: 150,
minWidth: 520,
maxWidth: 520,
start: function(event, ui) {
},
resize: function(event, ui) {
J2CS_Trial.exercises_[$(this).attr("relid")].height = parseInt($(this).css("height"))/2;
},
stop: function(event, ui) {
J2CS_Scripter.updateStep2MenuItems(11);
}
});
}
});
$("#trial_ul .strip .actions .move").live("click", function(e) {
e.stopImmediatePropagation();
var li = $(this).parent().parent();
var id = parseInt(li.attr("relid"));
J2CS_Trial.removeExercise(id);
li.remove();
J2CS_Trial.updateSortOrders();
J2CS_Scripter.updateStep2MenuItems(12);
});
$(".exercise .actions .move").live("click",function(e) {
e.stopImmediatePropagation();
var ex_id = parseInt($(this).parent().parent().parent().attr("relid"));
var container = $(this).parent().parent().parent().parent();
var container_name = container.attr("id");
if(container_name == "library_ul") {
var ex = J2CS_Library.getExercise(ex_id);
J2CS_Trial.addExercise(ex_id, 0, {difficulty: ex.difficulty, subject_id: ex.subject_id, subject: ex.subject, time_needed: ex.time_needed, additional: ex.additional, url: ex.url, height: ex.height, count: ex.count, info: ex.info} );
$(this).parent().parent().parent().appendTo("#trial_ul");
J2CS_Trial.updateSortOrders();
} else {
ex = J2CS_Trial.getExercise(ex_id);
J2CS_Trial.removeExercise(ex_id);
if(ex.subject_id == J2CS_Storage.get("current_subject")) {
J2CS_Library.addExercise(ex_id, {difficulty: ex.difficulty, subject_id: ex.subject_id, subject: ex.subject, time_needed: ex.time_needed, additional: ex.additional, url: ex.url, height: ex.height, count: ex.count, info: ex.info} );
var f = $(this).parent().parent().parent();
var f_id = parseInt(f.attr("relid"));
var f_df = parseInt(f.find(".exercise").find(".difficulty").find("div").attr("class").replace("type_",""));
var ccc = 0;
$("#library_ul").find("li").each(function() {
if($(this).attr("relid") != undefined) {
var l_id = parseInt($(this).attr("relid"));
var l_df = parseInt($(this).find(".exercise").find(".difficulty").find("div").attr("class").replace("type_",""));
if(ccc == 0 && f_df == l_df && f_id < l_id) {
ccc = 1;
$(this).before(f);
} else if(ccc == 0 && f_df < l_df) {
ccc = 1;
$(this).before(f);
}
}
});
if(ccc == 0) {
f.appendTo("#library_ul");
}
} else {
$(this).parent().parent().parent().remove();
}
J2CS_Trial.updateSortOrders();
}
J2CS_Scripter.updateStep2MenuItems(13);
});
J2CS_Scripter.updateStep2MenuItems(14);
}
this.updateStep2MenuItems = function(act) {
var time = 0;
var excnt = 0;
var pgs = 1;
var trial_type = J2CS_Storage.get("trial_format_type");
var compiler = compiler_type;
var printable_area = 0;
var before_exercise_margin = 0;
var before_blankstrip_margin = 0;
var toppage_offset = 0;
if(compiler == "latex") {
printable_area = (trial_type == 1 ? 262 : 115);
before_exercise_margin = 6;
before_blankstrip_margin = 3;
toppage_offset = 0;
}
else if(compiler == "xelatex" && compiler_font == "11pt") {
printable_area = (trial_type == 1 ? 262 : 115);
before_exercise_margin = 3;
before_blankstrip_margin = 1;
toppage_offset = 5;
}
else {
printable_area = (trial_type == 1 ? 262 : 115);
before_exercise_margin = 0;
before_blankstrip_margin = 1;
toppage_offset = 5;
}
// jesli type=1, to zostaw to jak jest, a jesli 2, to wykonaj nowy kawalek kodu z wysokoscia 240, a header podwojnie
var height_t = J2CS_Scripter.getHeaderHeight(J2CS_Storage.get("trial_header_type"));
$("#outer_container #trial_ul li").removeClass("first_on_page");
//$.post('/catchNotice.php', {action:"scripter",exercises:J2CS_Trial.exercises_, orders:J2CS_Trial.sort_orders_});
if(advLogger) advLogs.push({action:"scripter.update",act:act,exercises:J2CS_Library.exercises_, orders:J2CS_Library.sort_orders_,trialExers:J2CS_Trial.exercises_,trialOrders:J2CS_Trial.sort_orders_});
if(advLogger) {
$.post('/catchNotice.php', {data:JSON.stringify(advLogs)});
advLogs = [];
}
for(s in J2CS_Trial.sort_orders_) {
var i = J2CS_Trial.sort_orders_[s];
var ex = J2CS_Trial.exercises_[i];
if(ex == undefined) continue;
time += (ex.time_needed ? ex.time_needed : 0);
if(ex.subject_id > 0) {
excnt += 1;
}
height_t += ex.height;
if(ex.subject_id > 0) {
height_t += before_exercise_margin;
} else {
height_t += before_blankstrip_margin;
}
var condition = printable_area;
if(height_t > condition) {
$("#outer_container #trial_ul li[relid="+ex.id+"]").addClass("first_on_page");
pgs += 1;
height_t = toppage_offset + ex.height + before_exercise_margin;
}
if(pgs > 2 && trial_type == 2) {
$("#inner_container .go_to_third_step").removeClass('clickable');
$("#inner_container #step2_menu_accept").removeClass('clickable');
$("#inner_container #step2_menu_accept").addClass('alert');
this.showToManyA5PagesAlert();
} else if(trial_type == 2){
$("#inner_container .go_to_third_step").addClass('clickable');
$("#inner_container #step2_menu_accept").addClass('clickable');
$("#inner_container #step2_menu_accept").removeClass('alert');
}
}
if(!J2CS_Storage.get("exers_exceeded") && excnt > 30) {
$("#inner_container .go_to_third_step").removeClass('clickable');
$("#inner_container #step2_menu_accept").removeClass('clickable');
$("#inner_container #step2_menu_accept").addClass('alert');
J2CS_Scripter.showToManyExersAlert();
J2CS_Storage.set("exers_exceeded",true);
} else if(excnt <= 30 && !(trial_type==2 && pgs > 2)) {
$("#inner_container .go_to_third_step").addClass('clickable');
$("#inner_container #step2_menu_accept").addClass('clickable');
$("#inner_container #step2_menu_accept").removeClass('alert');
J2CS_Storage.set("exers_exceeded",false);
}
$("#step2_menu_excnt div").html(excnt);
$("#step2_menu_clock div").html(time);
$("#step2_menu_pgcnt div").html(pgs);
}
this.showToManyExersAlert = function(){
$('#exers_alert').dialog({
autoOpen : true,
resizable : false,
draggable : false,
width: 500,
modal : true
});
}
this.showToManyA5PagesAlert = function(){
$('#pages_alert').dialog({
autoOpen : true,
resizable : false,
draggable : false,
width: 500,
modal : true
});
}
this.getHeaderHeight = function(type) {
if(!type) type = 1;
if(type == 1 || type == 4) return 25;
if(type == 2 || type == 3) return 13;
}
this.start_preview = function() {
var trial_type = J2CS_Storage.get("trial_format_type");
// jesli type=1 to tak jak jest, a jesli 2:
var username = J2CS_Storage.get("user_name");
var header_type = J2CS_Storage.get("trial_header_type");
if(!header_type) header_type = 1;
var format_type = J2CS_Storage.get("trial_format_type");
if(format_type == 1) {
$("#step3_format_displayer .step3_left_content").html("klasówka jednostronna");
$("#step3_format_displayer img").attr("src", "css/img/layout/a4preview.png");
} else {
$("#step3_format_displayer .step3_left_content").html("klasówka dwustronna");
$("#step3_format_displayer img").attr("src", "css/img/layout/a5preview.png");
}
var compiler = compiler_type;
var printable_area = 0;
var before_exercise_margin = 0;
var before_blankstrip_margin = 0;
var toppage_offset = 0;
if(compiler == "latex") {
printable_area = (trial_type == 1 ? 262 : 115);
before_exercise_margin = 6;
before_blankstrip_margin = 3;
toppage_offset = 0;
}
else if(compiler == "xelatex" && compiler_font == "11pt") {
printable_area = (trial_type == 1 ? 262 : 115);
before_exercise_margin = 3;
before_blankstrip_margin = 1;
toppage_offset = 5;
}
else {
printable_area = (trial_type == 1 ? 262 : 115);
before_exercise_margin = 0;
before_blankstrip_margin = 1;
toppage_offset = 5;
}
var container = $("#preview_ul");
container.children().remove();
var container_temp = $("");
container_temp.children().remove();
var header_li = $("");
var text = '
'+
''+J2CS_Storage.get("trial_name")+'
'+
'gr. A
'+
'str. 1/2
'
;
header_li.addClass("trialheader").addClass("header_"+header_type).html(text);
var condition = printable_area;
var group_count = J2CS_Storage.get("group_count");
var show_difficulty = J2CS_Storage.get("show_difficulty") == 1;
var trial_clones = J2CS_Storage.get("trial_clones");
var sites_max = 1;
for(var GROUP=0; GROUP"+J2CS_Scripter.getGroupName(GROUP)+"");
}
container.append(header_clone);
container_temp.append(header_clone.clone());
var height_t = J2CS_Scripter.getHeaderHeight(J2CS_Storage.get("trial_header_type"));
var x = 0;
for(s in J2CS_Trial.sort_orders_) {
var i = J2CS_Trial.sort_orders_[s];
var ex = J2CS_Trial.exercises_[i];
height_t += ex.height;
if(ex.subject_id > 0) {
height_t += before_exercise_margin;
} else {
height_t += before_blankstrip_margin;
}
if(trial_type == 1){
if(height_t > condition) {
var li = $("");
li.addClass("preview_page_divider");
var height_loose = parseInt((condition - (height_t - ex.height))*3.3);
height_loose = height_loose < 0 ? 0 : height_loose;
li.css("margin-top", height_loose+"px");
current_site += 1;
if(GROUP==0) sites_max += 1;
li.html('');
li.append('gr. '+J2CS_Scripter.getGroupName(GROUP)+'
str. '+current_site+'/2
');
container.append(li);
height_t = toppage_offset+ex.height;
if(ex.subject_id > 0) {
height_t += before_exercise_margin;
} else {
height_t += before_blankstrip_margin;
}
}
} else {
if(height_t > condition) {
var li = $("");
li.addClass("preview_page1_divider");
li.html('');
var height_loose = parseInt((condition - (height_t - ex.height))*3.3);
height_loose = height_loose < 0 ? 0 : height_loose;
li.css("margin-top", height_loose+"px");
current_site += 1;
if(GROUP==0) sites_max += 1;
container.append(li);
height_t = toppage_offset+ex.height;
if(ex.subject_id > 0) {
height_t += before_exercise_margin;
} else {
height_t += before_blankstrip_margin;
}
$('li',container_temp).each(function(){
container.append(this);
});
container.append(li.clone().attr('class','preview_page_divider').css("margin-top", height_loose+"px").append('gr. '+J2CS_Scripter.getGroupName(GROUP)+'
str. '+current_site+'/2
'));
container_temp.children().remove();
}
}
var li = $("");
if(ex.url == "strip") {
li.attr("relid", i);
if(ex.subject_id == -1) {
li.addClass("strip").addClass("blank");
} else {
li.addClass("strip").addClass("check");
}
li.css("height", (ex.height*2)+"px");
} else {
li.attr("relid", i);
var url = "";
if(trial_clones[ex.id][GROUP] == undefined) {
url = trial_clones[ex.id][0];
} else {
url = trial_clones[ex.id][GROUP];
}
var gwiazdka = "";
if(ex.difficulty == 4) {
gwiazdka = '' + (show_difficulty ? '*' : '') + '';
}
li.html(''+gwiazdka+(++x)+'.
');
}
container.append(li.clone());
container_temp.append(li.clone());
}
if(trial_type == 2){
if(current_site == 2){
var li = $("");
li.addClass("preview_page2_divider");
var height_loose = parseInt((condition - height_t)*3.3);
height_loose = height_loose < 0 ? 0 : height_loose;
li.css("margin-top", height_loose+"px");
li.html('');
li.append('gr. '+J2CS_Scripter.getGroupName(GROUP)+'
str. '+current_site+'/2
');
container.append(li);
$('li',container_temp).each(function(){
container.append(this);
});
}else{
var li = $("");
li.addClass("preview_page1_divider");
li.html('');
var height_loose = parseInt((condition - height_t)*3.3);
height_loose = height_loose < 0 ? 0 : height_loose;
li.css("margin-top", height_loose+"px");
container.append(li);
$('li',container_temp).each(function(){
container.append(this);
});
}
}
var li = $("");
if(trial_type == 1 && current_site > 1 && current_site%2 == 1){
if(GROUP < group_count-1) {
li.addClass("preview_group_divider");
} else {
li.addClass("preview_page_ender");
}
}else{
if(GROUP < group_count-1) {
li.addClass("preview_group_divider");
} else {
li.addClass("preview_page_ender");
}
}
var height_loose = parseInt((condition - height_t)*3.3);
height_loose = height_loose < 0 ? 0 : height_loose;
li.css("margin-top", height_loose+"px");
li.html('');
container.append(li);
J2CS_Storage.set('page_count',current_site);
J2CS_Scripter.updatePrintMethod();
}
container.find(".preview_sites_max").html(sites_max);
if(sites_max == 1) {
container.find(".trial_site").css("display","none");
container.find(".trial_group").css("right", "30px");
}
if(group_count == 1) {
container.find(".trial_group").css("display","none");
} else {
container.find(".trial_group").css("display", "block");
}
}
this.getNewIdForElement = function(id,type) {
var foo = new Date; // Generic JS date object
var unixtime_ms = foo.getTime(); // Returns milliseconds since the epoch
var unixtime = parseInt(unixtime_ms / 10000000);
var random = Math.floor(Math.random()*1000);
key = unixtime+""+random;
return (new Array(id+"_"+key,key));
}
this.getGroupName = function(id) {
if(id == 0) return "A";
if(id == 1) return "B";
if(id == 2) return "C";
if(id == 3) return "D";
if(id == 4) return "E";
if(id == 5) return "F";
if(id == 6) return "G";
if(id == 7) return "H";
if(id == 8) return "I";
if(id == 9) return "J";
}
this.showChangedTrialNotification = function(id){
$('#trial_change_notification').dialog({
autoOpen: true,
resizable: false,
draggable: false,
modal: true,
width: 750,
close: function(){
J2CS_Request.get({name: "set_notification_read",trial: id});
}
});
}
}
function codi2html(text) {
var format_search = [
/\[b\](.*?)\[\/b\]/ig,
/\[i\](.*?)\[\/i\]/ig,
/\[u\](.*?)\[\/u\]/ig,
'[br]',
'[_]'
]; // note: NO comma after the last entry
// The matching array of strings to replace matches with
var format_replace = [
'$1',
'$1',
'$1',
'
',
' '
];
// Perform the actual conversion
for (var i =0;i