sessvars.$.prefs.crossDomain=true; function setStoreStr( key, data_str ) { log2console("setStoreStr() was called" ); if( isBrowserChrome() ) { return setStoreStrChrome(key, data_str); } else { return setStoreStrNOTChrome(key, data_str); } } function getStoreStr( key ) { log2console("getStoreStr() was called" ); if( isBrowserChrome() ) { return getStoreStrChrome(key); } else { return getStoreStrNOTChrome(key); } } function setStoreStrNOTChrome( key, data_str ) { if( sessvars.e2p_dict == null ) sessvars.e2p_dict = {}; sessvars.e2p_dict[key] = encodeURIComponent(data_str); sessvars.$.flush(); log2console("key ["+key+"] ; data_str ["+data_str+"]" ); // jQuery.jStore.set( key, data_str ); return data_str } function setStoreStrChrome( key, data_str ) { // if( sessionStorage[key] == null ) // sessionStorage[key] = {} sessionStorage[key] = data_str; log2console("key ["+key+"] ; data_str ["+data_str+"]" ); return data_str; } function getStoreStrNOTChrome( key ) { log2console("getStoreStrNOTChrome() was called" ); if( sessvars.e2p_dict == null ) return null; var data_str = decodeURIComponent( sessvars.e2p_dict[key] ); // var data_str = jQuery.jStore.get(key); log2console("key ["+key+"] ; data_str ["+JSON.stringify(data_str)+"]" ); if(data_str) return data_str; // return JSON.stringify(data_str) // return $.toJSON(data_str) else return null; } function getStoreStrChrome( key ) { log2console("getStoreStrChrome() was called" ); var data_str = sessionStorage[key]; if (data_str) { log2console("key ["+key+"] ; data_str ["+JSON.stringify(data_str)+"]" ); return data_str; } else return null; } function setStore( key, data_obj ) { /* var data_obj_str = null if( typeof(data_obj) !== 'string' ) data_obj_str = $.toJSON(data_obj) else data_obj_str = data_obj */ // var data_obj_str = $.toJSON(data_obj) var data_obj_str = JSON.stringify( data_obj ); setStoreStr(key, data_obj_str); // alert(getStoreStr(key)) // alert(getStore(key)) return data_obj; } function getStore( key ) { var data_str = getStoreStr(key); // alert("getStore got "+key+" --- "+data_str) if(data_str) { //var res = $.parseJSON(data_str); eval( "res="+data_str ); //var res = data_str if (typeof res == 'undefined') return null; return res; } else return null; } var STORAGE_E2P_DATA_PREFIX = "storage_e2p_data_"; var SESSION_STORAGE_WIN_ID = 'sb_window_id'; function getWinId() { var isChrome = isBrowserChrome(); log2console("isChrome = " + isChrome); if( isChrome ) { return "C"; } else { return "W"; } } function getStorageName( storage_prefix ) { return storage_prefix + "__" +getWinId(); } function getE2PDataStorageName() { return getStorageName( STORAGE_E2P_DATA_PREFIX ); } var save_recipe_default = function() { // get an initial e2p_data object with the general-info section in it var e2p_data = aggregate_section_2_data_obj( [], "general_book_info", get_stored_general_book_data()); // aggregate the running-total sections to the e2p_data obj e2p_data = aggregate_current_sections_to_e2p_obj(e2p_data); return save_recipe( e2p_data ); }; var save_recipe_in_client = function( the_e2p_data ) { var e2p_data_storage_key = getE2PDataStorageName(); var my_e2p_data = setStore( e2p_data_storage_key, the_e2p_data ); return my_e2p_data; }; var save_recipe = function( the_e2p_data ) { var my_e2p_data = save_recipe_in_client( the_e2p_data ); save_recipe_in_server( my_e2p_data ); // alert("stored my_e2p_data = "+my_e2p_data) return my_e2p_data; }; var get_recipe_in_client = function() { var e2p_data_storage_name = getE2PDataStorageName(); log2console("e2p_data_storage_name", e2p_data_storage_name); var e2p_data_storage = getStore( e2p_data_storage_name ); // normalize to null if(typeof e2p_data_storage === 'undefined') e2p_data_storage = null; return e2p_data_storage; }; var get_book_title = function( the_e2p_data ) { if( !the_e2p_data ) return null; log2console("get_book_title() was called", the_e2p_data ); var book_title = null; for(var i=0; i 0); }, error_codes['section_title_already_extists']); arrangeSectionListsUI(); } var init_homepage = function() { if(location.pathname.endsWith('bridge_after_blogger_auth.html') ) { // returning from Google Auth - should display the blogger-details section load_section('blogger_details.html'); return; } var addr = $.address.value(); // if (typeof console != 'undefined') // console.log("init_homepage - addr",addr); log2console("init_homepage - addr = " + addr ); if ( !get_recipe_in_client() ) { $('#main-container-homepage').show(); $('#main-container').hide(); return; } $('#main-container-homepage').hide(); $('#main-container').show(); }; var init_homepage_acapub = function() { if(location.pathname.endsWith('bridge_after_blogger_auth.html') ) { // returning from Google Auth - should display the blogger-details section load_section('blogger_details.html'); return; } var addr = $.address.value(); log2console("init_homepage - addr = " + addr ); $("#create-flipbook").click(function() { save_session_no_preview(); FLIPBOOK_PREVIEW.open_flipbook_popup(); return false; }); }; function blockCover() { // $.blockUI({ message: $('#seeallcovers') }); $('.asyncUploader').each( function(index){$(this).css("display", 'none');} ) //Distinct the screen resolution and show the corresponding popup div. if(parseInt(screen.height) < 1000) $.blockUI({ message: $('#seeallcovers-small'), css : { 'position': 'absolute', 'top':'100px', 'left':'180px' } }); else $.blockUI({ message: $('#seeallcovers'), css : { 'position': 'absolute', 'top':'100px', 'left':'180px' } }); } function unblockCover() { $('.asyncUploader').each( function(index){$(this).css("display", '');} ) if(parseInt(screen.height) < 1000) $.unblockUI({ message: $('#seeallcovers-small') }); else $.unblockUI({ message: $('#seeallcovers') }); } function blockDedication() { $('.asyncUploader').each( function(index){$(this).css("display", 'none');} ) $.blockUI({ message: $('#dedicationtext') }); } function unblockDedication() { $('.asyncUploader').each( function(index){$(this).css("display", '');} ) $.unblockUI({ message: $('#dedicationtext') }); } function blockTemplate() { $('.asyncUploader').each( function(index){$(this).css("display", 'none');} ) $.blockUI({ message: $('#pagetemp') }); } function unblockTemplate() { $('.asyncUploader').each( function(index){$(this).css("display", '');} ) $.unblockUI({ message: $('#pagetemp') }); } var current_form_validation = null; var bind_form_validation = function(form) { // var validation_options = $.extend(true, {}, validationOptions, $(form).data("validation_options")); log2console("333 form=", form, validation_options); // var validator = $(form).validate(validationOptions); var validator = $(form).validate(validation_options); current_form_validation = validator; log2console("4444 validator", validator); }; var bind_validations = function() { var validated_forms = $('.validated-form, .section-form'); validated_forms.each(function(i) { log2console("bind_validations(); validated_forms[i]: ", validated_forms[i] ); bind_form_validation(validated_forms[i]); }) }; var validationOptions = { rules : { section_title : { sectionTitleUnique : true, required:true } }, debug:true, // the function should not call directly since it breaks !!!!! submitHandler: function(form) { oursubmit(form); } } var validate_msdoc=function(section_data) { // alert("validate msdoc"+$.toJSON(section_data)) if (section_data.section_title=='off') { return {'section_title':'off'}; } if (section_data.section_title=='off') { return {'section_title':'off'}; } if (section_data.section_title=='on') { return true; } } function validate_blog_name(blog_name_or_url) { var regExp = /^\W*((http:\/\/)|\W*)([\w-\.]*)\W*$/i; var groups=blog_name_or_url.match(regExp); if (! groups) { return null; } blogId = groups[3]; if (blogId.length == 0) return null; if (blogId.search('\\.') < 0) blogId = blogId + ".blogspot.com"; return blogId; } function getRandom() { return (new Date()).getTime() + Math.floor(Math.random() * 100000); // return 100000 + Math.floor(Math.random() * 100000) } function isBrowserChrome() { return navigator.userAgent.toLowerCase().indexOf('chrome') > -1; } function unescapeHTML(html) { return $("
").html(html).text(); } function escapeHTML(html) { return $("
").text(html).html(); } var startsWith = function (str, testStr) { return (str.match("^"+testStr)==testStr); }; String.prototype.startsWith = function(str) { return (this.match("^" + str) == str); }; String.prototype.endsWith = function(str) { return (this.match(str + "$") == str); }; function charactersLeft(countId, inputEl, limit) { // Get the element where the current count is displayed var countEl = $('#'+countId); // Get the text from the input element var inputStr = inputEl.val(); // # of characters left = max input - current string length var charsLeft = limit - inputStr.length; // When 0 characters are left... if(charsLeft <= 0) { // always set charsLeft to 0 so no negative #'s display charsLeft = 0; // trim the extra input off of the input string and push // to the input element inputEl.val(inputStr.substring(0, limit)); } // push the current count to the count element countEl.html(charsLeft); } $.fn.serializeObject = function() { var o = {}; var a = this.serializeArray(); $.each(a, function() { if (o[this.name]) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return o; }; // // This extension funcs allow retrieving the param values from the address-bar-URL // $.extend({ getUrlVars: function(){ var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; }, getUrlVar: function(name){ return $.getUrlVars()[name]; } }); // // This functions are for bind & trigger of general events that are not linked to a specific DOM element // $.extend({ bind_general: function( event_name, cb_func ) { $("html").bind( event_name, cb_func ); }, trigger_general: function( event_name ) { $("html").trigger( event_name ); } }); var on_section_deleted = function on_section_deleted( cloned_elem_section_data ) { var _on_section_deleted = function() { // do nothing }; return _on_section_deleted; }; var on_sections_added = function( newDivs ) { var _on_sections_added = function() { // do nothing }; return _on_sections_added; }; var display_elems_according_2_sections_num = function() { if (get_number_of_current_sections() > 0) { $( '#save_proj_wo_creating_book' ).show(); $( '#preview_book_btn_container' ).show(); $( '#create-flipbook' ).show(); } else { $( '#save_proj_wo_creating_book' ).hide(); $( '#preview_book_btn_container' ).hide(); $( '#create-flipbook' ).hide(); } }; var addSectionDivToSectionsList = function(newDiv) { var book_section_type_is_artilces_and_pdf = newDiv.hasClass("article_and_pdf_book_section"); var book_section_type_is_photos = newDiv.hasClass("photos_book_section"); //var book_section_type = newDivdata(section_data_key).book_section_type || "photos"; var li = $("
  • ").addClass("section-state-div-wrapper").append(newDiv); if (book_section_type_is_artilces_and_pdf) { $(".states-articles-list-container").each(function() { $(this).append(li); $(this).sortable( "refresh" ); }); } else if (book_section_type_is_photos) { var photos_list_container = $("#states-photos-list-container"); photos_list_container.append(li); photos_list_container.sortable( "refresh" ); } else alert("unknown book section type"); }; var moveLiveChatBoxToArticleList = function () { //$("#articles-bottom").removeClass("articles-list-bottom").addClass("live-chat-list-bottom"); $("div.articles-list-bottom").each(function(){ $(this).removeClass("articles-list-bottom").addClass("live-chat-list-bottom"); }); $('#articles-bottom-buttons').show(); $('#photos-bottom-buttons').hide(); }; var moveLiveChatBoxToPhotoList = function () { $("#articles-bottom").removeClass("live-chat-list-bottom").addClass("articles-list-bottom"); $('#articles-bottom-buttons').hide(); $('#photos-bottom-buttons').show(); }; var arrangeSectionListsUI = function () { var articles_sections_num = get_articles_sections_num(); var photos_sections_num = get_photos_sections_num(); if((articles_sections_num == 0) && (photos_sections_num == 0)) { moveLiveChatBoxToArticleList(); $('div.intro-text').each(function(){ $(this).show(); }); $('div.article-list').addClass('introduction-container'); //$('#status_container').load("introduction.html"); //$('#introduction-container').show(); //$('#states-container').hide(); //return; } else { $('#states-container').show(); $('div.intro-text').each(function(){ $(this).hide(); }); $('div.article-list').removeClass('introduction-container'); if ((articles_sections_num > 0) && (photos_sections_num == 0)) { moveLiveChatBoxToArticleList(); } else if ((articles_sections_num > 0) && (photos_sections_num > 0)) { moveLiveChatBoxToPhotoList(); } if (articles_sections_num > 0) { $('#articles-list').show(); if (articles_sections_num > 1) { $('#articles-notes').show(); } else { $('#articles-notes').hide(); } } else { $('#articles-list').hide(); } if (photos_sections_num > 0) { $('#photos-list').show(); if (photos_sections_num > 1) { $('#photos-notes').show(); } else { $('#photos-notes').hide(); } } else { $('#photos-list').hide(); } } }; var add_ele_func_with_store = function(newDivs) { var _add_ele_func_with_store = function() { log2console("_add_ele_func_with_store was called."); for(var i=0; ifile_size_limit_2_bytes(thelimit)) { errs[fieldid_guid]='file size limit is'+thelimit; show_errors(errs); return false; } return true; }; return cond; }; var get_section_titles = function() { var section_titles = []; $('#states-list-container #name__section_title').each( function( index ) { var section_title = $(this).text(); section_titles[section_titles.length] = section_title; }); return section_titles; }; /* var get_section_titles_and_ids = function() { var titles = []; var ids = []; $('#states-list-container #name__section_title').each( function( index ) { var section_title = $(this).text() titles[titles.length] = section_title; var section_unique_id = $(this).closest('.section-state-div').attr('id'); section_unique_id[section_unique_id.length] = section_unique_id; }) var title_and_ids_obj = {'titles':titles, 'ids':ids}; return title_and_ids_obj; } */ var block_default = function() { //If we block a section - use the default blocking div $.blockUI({message: $('#gen-blocking-msg')}); }; var unblock_default = function() { //If we block a section - use the default blocking div $.unblockUI({message: $('#gen-blocking-msg')}); }; var block_create_book = function() { // we block the final submit which is longer - use a custom made blocking div $.blockUI({ message: $('#domMessage') }); }; var unblock_create_book = function() { // we unblock the final submit which is longer - use a custom made blocking div $.unblockUI({ message: $('#domMessage') }); }; var get_section_container_load_cb = function(addr) { return function() { bind_validations(); restoreStatesDiv(); } }; var load_section = function(addr) { $("#get-started-container").hide(); $('#main-container-homepage').hide(); $('#main-container').show(); $('#section_container').load(addr, get_section_container_load_cb(addr)); }; if (typeof String.prototype.startsWith != 'function') { String.prototype.startsWith = function (str) { return this.indexOf(str) == 0; }; } function log2console( msg, event ) { if( $.browser.mozilla==true && $.browser.version.startsWith("10") ) return; // handle SB-10416 try { if (typeof window.console !== 'undefined') window.console.log( msg, event ); } catch(e) { // Do nothing } } var oursubmit=function(form) { // log2console("oursubmit was called. form = ", JSON.stringify(form)) log2console("oursubmit was called."); var desturl = $(form).attr("action"); var formId= $(form).attr("id"); aggregateSection(form, formId.substr(0, formId.indexOf('-form')), desturl); }; /* var a_aggregate_section_handler = function(event) { var sectionForm = $(this).closest("form.section-form") // var desturl=$(this).attr('href') // fix_form_and_submit(sectionForm, desturl) sectionForm.submit() event.preventDefault(); } */ //var fix_form_and_submit = function(sectionForm, desturl) //{ // var formId = sectionForm.attr("id") // todo: add a "pre-click" hook that will call specific handlers from different sections // sectionForm.submit() //} var SECTION_ID_KEY = "SECTION_ID_KEY"; var SECTION_UNIQUE_ID_KEY = "section_unique_id_key"; var SECTION_DATA_KEY = "section_data_key"; var state_count = 0; var is_load_states_div = true; var global_blog_data = { blog_domain: '', section_title: '', username: '', password: '', blog_type :'', session_token: '', wp_host_domain: '', blogs: [], reset : function() { for (var prop in this) { if (this.hasOwnProperty(prop) && typeof this[prop] != "function") { this[prop] = null; } } } }; var the_session_key=null; function get_session_dir_key() { var the_session_key = getStoreStr('dirname'); if (the_session_key === null || the_session_key === '') { var randomnumber = Math.floor(Math.random() * 1000); var d = new Date(); the_session_key = '' + d.getTime() + '_' + randomnumber; setStoreStr('dirname', the_session_key); } //alert(the_session_key) return the_session_key; } //var has_session_data=function() //{ // var e2p_data_storage_name = getE2PDataStorageName(); // var e2p_data_storage = getStore(e2p_data_storage_name); // return e2p_data_storage; //} var get_number_of_current_sections = function() { var e2p_sections = get_e2p_sections(get_recipe_in_client()); for(var i=0; i1 ) { for( var i=0; iOnce you have previewed your book, you can return these settings. ", "no_facebook_albums_selected": "No Facebook Albums were selected. Please select at least one album.", "b2p_typepad_authentication": "TypePad is returning an error when we submit your user name and password. Please check your entries, or try to login at www.typepad.com", "section_title_already_extists": "The section name is already in use.", "start_date_in_the_past": "Start of Term cannot be in the past - if the term has already started, enter today's date.", "picasa_album_not_exist": "We cannot access your Picasa album at the address provided. Please check to ensure you have correctly copied the address (URL) of a single album.
    If so, the likely cause is a \"Private\" album that can only be accessed by you. To allow Everything2Print to access this album, you can temporarily change this election. Open your album and under \"Album Properties\" choose \"Edit\" . Then change the \"Share\" setting to \"Unlisted\".
    Once you have previewed your book, you can return these settings.", "b2p_blog_not_found_for_user": "We are unable to get this user's blog(s)", "twitter_hashtag_prefix": "Hashtag - To select tweets by hashtag, please ensure your entry starts with '#' ."} //|safe display_error = function (err) { var code = err['code']; var msg = err['msg']; if( !msg ) { msg = error_codes[code] } // display the error in a blocking div dialog $('#err-msg').text( msg ); $.blockUI({ message: $('#error'), css: { width: '400px' }/*, timeout:20000*/ }); // alert(msg) // popup_alert( msg ); return true; }; var generate_book_error = function (err) { var code = err.code; var msg = err.msg || error_codes[code]; var internal_error_id = err.internal_error_id || ''; // alert('code['+code+'] ; msg['+msg+'] ; internal_error_id['+internal_error_id+']') $("#section_container").load("error.html", function() { $('#err_elem').text(msg+' - '+internal_error_id) }); return true; }; var b2p_error = function (err) { var code = err.code var blog_domain = err.blog_domain var max_photos = err.max_photos ? err.max_photos : 0; var nphotos = err.nphotos ? err.nphotos : 0; var msg = error_codes[code] alert(msg.replace('%(blog_domain)s', blog_domain).replace('%(max_photos)d', max_photos).replace('%(nphotos)d', nphotos)) return true; } var popup_alert=function(txt) { var viewport = { o: function() { if (self.innerHeight) { this.pageYOffset = self.pageYOffset; this.pageXOffset = self.pageXOffset; this.innerHeight = self.innerHeight; this.innerWidth = self.innerWidth; } else if (document.documentElement && document.documentElement.clientHeight) { this.pageYOffset = document.documentElement.scrollTop; this.pageXOffset = document.documentElement.scrollLeft; this.innerHeight = document.documentElement.clientHeight; this.innerWidth = document.documentElement.clientWidth; } else if (document.body) { this.pageYOffset = document.body.scrollTop; this.pageXOffset = document.body.scrollLeft; this.innerHeight = document.body.clientHeight; this.innerWidth = document.body.clientWidth; } return this; }, init: function(el) { $(el).css("left",Math.round(viewport.o().innerWidth/2) + viewport.o().pageXOffset - Math.round($(el).width()/2)); $(el).css("top",Math.round(viewport.o().innerHeight/2) + viewport.o().pageYOffset - Math.round($(el).height()/2)); } }; $(".simple_popup_div").remove(); var strSimple = "
    "; strSimple += "

    [ x ] Close

    "; strSimple += txt; strSimple += "
    "; $("body").append(strSimple); viewport.init(".simple_popup_div"); $(".simple_close").click(function() { $(".simple_popup_div").remove(); return false; }); } // // oc - Object-Converter ; enable to use the js 'in' key word to search an array // e.g. if 'my_key' in oc(['val1', 'val2', 'val3' ]) // function oc(a) { var o = {}; for(var i=0;i //console.log("inputName",$(this).get(0).tagName) var thisTagName = $(this).get(0).tagName; var value = sectionStateData[inputName]; if($.isArray(value)) value = value[0];//in case we got a list of values we take the first one if (thisTagName == "INPUT") $(this).val(value); else $(this).text(value); } }) } var get_redirected_page = function( sectionId, section_unique_id ) { var section_page = null; // TODO: consider replacing with a constant dictionary switch(sectionId) { case 'picasa': section_page = "picasa.html"; break; case 'pdf': section_page = "pdf.html"; break; case 'blogger': section_page = "blogger_details.html"; break; case 'msdoc': section_page = "msdoc.html"; break; case 'twitter': section_page = "twitter.html"; break; case 'facebook': section_page = "facebook.html" ; break; case 'webcon': section_page = "webcon.html" ; break; case 'sblib': section_page = "sb_library.html" ; break; default: throw "Unexpected sectionId: "+sectionId } return section_page + "?"+SECTION_UNIQUE_ID_KEY+"="+section_unique_id; }; function get_redirected_page_data( sectionId, data ) { var ret_data = null; switch( sectionId ) { case "blogger": ret_data = eval("res=" + decodeURIComponent(data['global_blog_data'])); break; default: ; // nothing to do here } return ret_data; } // TODO: consider dividing into several funcs var getNewStatesDiv = function(sectionId, data) { log2console("getNewStatesDiv was called.", sectionId, data); var section_unique_id = data[SECTION_UNIQUE_ID_KEY]; var section_state_div_template_id = "#section-state-div-template-id-"+sectionId; var extractSectionFunc = $(section_state_div_template_id).data("extract_section_func"); var clonedStatesDiv = $(section_state_div_template_id).clone().toggle().attr("id", section_unique_id); clonedStatesDiv.data(SECTION_ID_KEY, sectionId); clonedStatesDiv.data(SECTION_UNIQUE_ID_KEY, section_unique_id); clonedStatesDiv.data(SECTION_DATA_KEY, data); var newHref = get_redirected_page( sectionId, section_unique_id); var editLinkObj = $(clonedStatesDiv).find('#edit-this-section-' + sectionId); $(editLinkObj).attr("href", newHref); $(editLinkObj).click(function() { // window.location = newHref; var data_json = get_redirected_page_data( sectionId, data) ; submit_data_json( newHref, data_json ); }); // for some reason the href doesn't work. Probably due to the Drag&Drop if(extractSectionFunc) extractSectionFunc(data, clonedStatesDiv); else defaultExtractSection(data, clonedStatesDiv); // handle price display: if there's no price - don't show the div at all $(clonedStatesDiv).find('.price-item').each(function(index) { var price_text = $(this).text(); if(price_text!=null && price_text==='') $(this).parent().hide(); }); return clonedStatesDiv }; var validate_section_then_do=function(section_id , section_data, then_do) { log2console("validate_section_then_do was called.", arguments ); // var json = $.toJSON(section_data); var json = JSON.stringify( section_data ); var url= "validate/%s/".replace('%s',section_id); // resolved by the sever and replaced var querystr= "data="+encodeURIComponent(json); //alert("before: "+ json+"\nafter: "+querystr) // var err_geturl=url+"?"+querystr; block_default(); $.ajax( { type: "POST", url: url, data: querystr, contentType: "application/json; charset=UTF-8", dataType: "json", success: function(data) { // alert( "Data Returned: " + $.toJSON(data) ); // We start by blocking the UI since there are still some changes to do before returning the control to the user. // Assumptions: // 1. If an error returned we display it and unblock the UI // 2. If NO error the next page is loaded and unblocks the UI inherently // $.blockUI(); // log2console('blocking UI'); var err = data.err; // alert( "err: " + $.toJSON(err) ); if (err != undefined) { try { var section = data.section; if (section == 'generate_book') { return generate_book_error(err); } show_errors(err); } catch(e) { notify_error(section_id, err); } finally { unblock_default(); } return; } if ("webcon" == data.section) { var webcon_res = data.webcon_res; if (webcon_res && webcon_res.success) { // Set the results we got from the server in the hidden fields so they would enter the json object. $('input:hidden[name=scraped_article_path]').val(webcon_res.article_path); $('input:hidden[name=scraped_article_title]').val(webcon_res.article_title); $('input:hidden[name=scraped_short_article_title]').val(webcon_res.article_short_title); } else { // We should not reach this code. // When webcon_res.success is False we should have got an err response. // Get error ID and tell the user. $.unblockUI(); alert("We're sorry, we are not able to access the content on this site."); return; } } var validation_success_data = data.validation_success_data; then_do(validation_success_data); // unblock_default(); // here we do not want to unblock!!! cause it takes time till the submit loads a new page while a block is required. So the loaded page unblocks in a natural way. }, error: function(XMLHttpRequest,textStatus,errorThrown) { // ignoring the error + opening dbg page // then_do() notify_error(null, "Server Error!"); unblock_default(); var newwin = window.open(); if(newwin === null) { alert("Looks like a pop-up blocker is ON"); return; } newwin.focus(); newwin.document.write(XMLHttpRequest.responseText); } }); }; var activateFuncAndChangeWinLocation = function( func, new_location ) { return function() { log2console("activateFuncAndChangeWinLocation was called.", arguments); func(); window.location = new_location; } }; var isStatesDivExist = function(section_unique_id) { if( section_unique_id === null) return false; var oldDiv = $('#status_container').find('#'+section_unique_id); return (oldDiv != null && oldDiv.length > 0) ; }; function add_section_unique_id_field_2_form(form, section_unique_id) { var new_form_field = ''; form.append( new_form_field ); } /* function get_data_from_form_field(form, field_id) { var field = $(form).find('#'+field_id); if( field == null ) return null; var data_json = decodeURIComponent($(field).val()); return eval(data_json); } */ function aggregate_data_field_2_form(form, data, field_id, field_name) { var data_json = encodeURIComponent(JSON.stringify(data)); var new_form_field = ''; $(form).append( new_form_field ); } function get_section_id_from_form(sectionForm) { var elem = $(sectionForm).find('#' + SECTION_UNIQUE_ID_KEY); if(elem === null || elem.length === 0) return null; return $(elem).val(); } var populate_ret_form_data = function(sectionForm, validation_success_data) { if( validation_success_data != undefined ) { var data_for_form_population = validation_success_data['data_for_form_population']; if( data_for_form_population != undefined ) { for( var field_name in data_for_form_population ) { var field_value = data_for_form_population[field_name]; $(sectionForm).find("input[name='" + field_name + "']").val(field_value); } } } var form_data = sectionForm.serializeObject(); log2console(form_data); return form_data; }; var aggregateSection = function(sectionForm, sectionId, newaddress) { log2console("aggregateSection", sectionForm, sectionId, newaddress); var section_unique_id = get_section_id_from_form(sectionForm); if( section_unique_id === null) { section_unique_id = sectionId + "-" + (state_count++) + "-" + getRandom(); add_section_unique_id_field_2_form( $(sectionForm), section_unique_id ); } sectionForm=$(sectionForm); var form_data = sectionForm.serializeObject(); var then_do = function( validation_success_data ) { log2console("then_do was called.", sectionId, form_data, validation_success_data ); form_data = populate_ret_form_data(sectionForm, validation_success_data); var newDiv = getNewStatesDiv( sectionId, form_data ); var form_action = sectionForm.attr('action'); // set either an UPDATE-div-function or an ADD-div-function var statesDivChangeFunc = ( isStatesDivExist(section_unique_id) ) ? update_ele_func_with_store([newDiv]): add_ele_func_with_store([newDiv]); $("#status_container").trigger('aggregate_section_event', activateFuncAndChangeWinLocation( statesDivChangeFunc, form_action ) ); }; // data ready // validate validate_section_then_do(sectionId , form_data, then_do) }; //function setConfirmUnload(on) //{ // window.onbeforeunload = (on) ? unloadMessage : null; //} // //function unloadMessage() //{ // return 'If you navigate away from this page, changes will be lost.'; //} var is_there_at_least_one_article_section = function() { var is_article_section_present = false; $('#states-list-container .section-state-div').each( function( index ) { if (is_article_section_present) return; var section_data = $(this).data(SECTION_DATA_KEY); is_article_section_present |= section_data.is_article_section }); return is_article_section_present }; var get_sections_num = function() { return get_articles_sections_num() + get_photos_sections_num(); }; var get_articles_sections_num = function() { return $('#states-articles-list-container div.section-state-div').size(); }; var get_photos_sections_num = function() { return $('#states-photos-list-container div.section-state-div').size(); }; // Use to override the default uploader error handler to show file upload limit // Usage: file_queue_error_handler : custom_file_queue_error_handler var custom_file_queue_error_handler = function(file, code, msg) { if (code=SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT) { show_errors({pdf_upload_filename:"Your uploaded file exceeds the maximum size allowed of "+this.settings.file_size_limit}); } else alert("Sorry, your file wasn't uploaded: " + msg); }; var submit_data_json = function(action, data_obj) { $('body').append('
    '); if( data_obj != null ) { var data_json = JSON.stringify(data_obj); log2console('data_json', data_json); $('#submit-data-id').val(data_json); } $('#submit-data-form-id').submit(); }; //var edit_project_name = function() //{ //}; var init_uploaded_filenames = function() { $(".filename-field").each(function (index, filenameEle) { var filename = $(filenameEle).val(); if (filename != null && filename != "") { var ele_id = $( filenameEle ).attr('id'); var ele_type_end_index = ele_id.lastIndexOf('-'); var status_ele_id = ele_id.substring(0, ele_type_end_index)+'-status'; // find the sibling cover-status elem var status_ele = $('#'+status_ele_id); var status_txt = $.trim(($( status_ele ).text())); if( status_txt === '' ) { var status_txt = "Uploaded "+filename+""; $( status_ele ).html(status_txt); $( status_ele ).show(); } } }); };