To participate you must create an account on apostrophenow.org. If you have already done so, click Login.

Changeset 4467

Show
Ignore:
Timestamp:
01/11/12 15:29:55 (4 months ago)
Author:
tboutell
Message:

Blog and event metadata forms track whether they have unsaved changes, so the new apostrophe.onBeforeUnload method in a.js can ask them

Location:
plugins/apostropheBlogPlugin/branches/1.5
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • plugins/apostropheBlogPlugin/branches/1.5/modules/aBlogAdmin/templates/editSuccess.php

    r3495 r4467  
    1515  <div class="a-ui a-subnav-wrapper a-admin-sidebar"> 
    1616                <div class="a-subnav-inner"> 
    17             <div id="a-ui a-admin-blog-post-form"> 
     17            <div class="a-admin-blog-post-form"> 
    1818              <form method="post" action="<?php echo url_for('a_blog_admin_update', $a_blog_post) ?>" id="a-admin-form" class="a-ui blog"> 
    1919          <?php include_partial('aBlogAdmin/form', array('form' => $form, 'a_blog_post' => $a_blog_post, 'popularTags' => $popularTags, 'existingTags' => $existingTags)) ?> 
  • plugins/apostropheBlogPlugin/branches/1.5/modules/aEventAdmin/templates/editSuccess.php

    r3495 r4467  
    1515  <div class="a-ui a-subnav-wrapper a-admin-sidebar"> 
    1616                <div class="a-subnav-inner"> 
    17             <div id="a-ui a-admin-blog-post-form"> 
     17                  <?php // Yes I meant to set both classes, this way the event form can define small variations ?> 
     18                  <?php // on what goes for the similar blog post form and we can select both when checking ?> 
     19                  <?php // onbeforeunload with just one selector ?> 
     20            <div class="a-admin-blog-post-form a-admin-event-form"> 
    1821              <form method="post" action="<?php echo url_for('a_event_admin_update', $a_event) ?>" id="a-admin-form" class="a-ui blog"> 
    1922          <?php include_partial('aEventAdmin/form', array('form' => $form, 'a_event' => $a_event, 'popularTags' => $popularTags, 'existingTags' => $existingTags)) ?> 
  • plugins/apostropheBlogPlugin/branches/1.5/web/js/aBlog.js

    r4449 r4467  
    7373function aBlogEnableForm(options) 
    7474{ 
    75         var changed = false; 
    7675        var savedState = null; 
    7776        var form = $('#a-admin-form'); 
     77        form.data('changed', false); 
     78   
    7879        apostrophe.formUpdates({ selector: '#a-admin-form', update: 'a-admin-form' }); 
    7980        // Due to the way our markup is structured this is a better place for the little 
     
    105106                        find('.a-save-blog-main .label').text(options['update-labels'][s]); 
    106107                } 
     108                if (!init) 
     109                { 
     110                form.data('changed', true); 
     111                } 
    107112                init = false; 
    108113        }); 
    109114        status.change(); 
    110115 
     116  // On various fields, including the progressively enhanced fields whose PE code has been upgraded 
     117  // to send change events, just monitor change() and set the changed flag so it can be checked 
     118  // by onbeforeunload 
     119   
     120  form.find('#a_blog_item_location,#a_blog_item_all_day,#a_blog_item_start_date_month,#a_blog_item_start_date_day,#a_blog_item_start_date_year,#a_blog_item_start_time_hour,#a_blog_item_start_time_minute,#a_blog_item_end_date_month,#a_blog_item_end_date_day,#a_blog_item_end_date_year,#a_blog_item_end_time_hour,#a_blog_item_end_time_minute,#a_blog_item_published_at_hour,#a_blog_item_published_at_minute,#a_blog_item_author_id,#a-blog-post-tags-input').change(function() { 
     121    form.data('changed', true); 
     122  }); 
     123 
     124  // Listen to keystrokes in the location field. In Chrome at least, text fields don't get a  
     125  // change() event when you type in them and then click a link elsewhere on the page that leaves 
     126  // the page, so we need something else 
     127  form.find('#a_blog_item_location').keyup(function() { 
     128    form.data('changed', true); 
     129  }); 
     130   
    111131        find('.template.section select').change(function() { 
    112132                alert(options['template-change-warning']); 
    113                 // Let the form submit as a full refresh 
     133                // Let the form submit as a full refresh. Don't complain of unsaved changes when we're about to save changes 
     134                $(form).data('changed', false); 
    114135                $(form).unbind('submit.aFormUpdates'); 
    115136        }); 
     
    121142        }); 
    122143         
    123         var p = { 'choose-one': options['editors-choose-label'] }; 
     144        var p = { 'choose-one': options['editors-choose-label'], 'onChange': function() { 
     145          form.data('changed', true); 
     146        } }; 
    124147        aMultipleSelect('#editors-section', p); 
    125         p = { 'choose-one': options['categories-choose-label'] }; 
     148        p = { 'choose-one': options['categories-choose-label'], 'onChange': function() { 
     149          form.data('changed', true); 
     150        } }; 
    126151        if (options['categories-add']) 
    127152        {