[from now] 2012/05/29 21:16:35

diff --git a/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml b/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml
index 1316289..e45afb0 100644
--- a/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml
+++ b/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml
@@ -1,4 +1,4 @@
-<!-- Indices written at Fri, 25 May 2012 17:48:17 JST -->
+<!-- Indices written at Tue, 29 May 2012 18:57:48 JST -->

 <datastore-indexes/>

diff --git a/war/js/nico2ical.js b/war/js/nico2ical.js
index 7640149..422303b 100644
--- a/war/js/nico2ical.js
+++ b/war/js/nico2ical.js
@@ -58,8 +58,8 @@ $(function () {
                         dataType: 'json',
                         data: {
                             'csrftoken': $.cookie('csrftoken'),
-                            'calendarId': this.selectedValue(),
-                            'keywords': this.keywords().split(' ');
+                            'keywords': s.keywords().split(' '),
+                            'calendarId': this.selectedValue()
                             }
                     }
             ).success(function(data) {
[from now] 2012/05/29 21:51:08

diff --git a/src/main/java/org/ryu22e/nico2cal/controller/myCalendar/IndexController.java b/src/main/java/org/ryu22e/nico2cal/controller/myCalendar/IndexController.java
index b06c8df..4ffc8c8 100644
--- a/src/main/java/org/ryu22e/nico2cal/controller/myCalendar/IndexController.java
+++ b/src/main/java/org/ryu22e/nico2cal/controller/myCalendar/IndexController.java
@@ -67,6 +67,9 @@ public final class IndexController extends Controller {
         MyCalendar myCalendar = calendarService.getMyCalendar();
         if (myCalendar != null) {
             requestScope("calendarSummaries", myCalendar.getCalendarId());
+            requestScope(
+                "keywords",
+                myCalendar.getKeywords().toArray(new String[0]));
         }
         requestScope("storedCredential", storedCredential);
         return forward("index.jsp");
diff --git a/war/js/nico2ical.js b/war/js/nico2ical.js
index 422303b..764aba7 100644
--- a/war/js/nico2ical.js
+++ b/war/js/nico2ical.js
@@ -37,9 +37,9 @@ $(function () {
         $(this).tab('show');
     });

-    var CalendarSummaries = function(selectedValue) {
-        this.selectedValue = ko.observable(selectedValue);
-        this.keywords = ko.observable();
+    var CalendarSummaries = function(params) {
+        this.selectedValue = ko.observable(params.selectedValue);
+        this.keywords = ko.observable(params.keywords);
         this.isSaveSuccess = ko.observable(false);
         this.isSavaError = ko.observable(false);
         this.isDisconnectError = ko.observable(false);
@@ -50,7 +50,7 @@ $(function () {
             var s = this;
             $('#save-calendar').button('loading');
             $('#mycalendar-tab a').attr('data-disabled', 'true');
-            $('input[name=calendarSummaries]').attr('disabled', 'disabled');
+            $('input[name=calendarSummaries], #keywords').attr('disabled', 'disabled');
             $.ajax(
                     '/myCalendar/save',
                     {
@@ -69,7 +69,7 @@ $(function () {
                 $('#save-calendar').button('error');
                 s.isSavaError(true);
             }).complete(function() {
-                $('input[name=calendarSummaries]').removeAttr('disabled');
+                $('input[name=calendarSummaries], #keywords').removeAttr('disabled');
                 $('#mycalendar-tab a').removeAttr('data-disabled');
             });
         }.bind(this);
@@ -102,5 +102,6 @@ $(function () {
         }.bind(this);
     };
     var selectedValue = $('input[name=calendarSummaries]:checked').val() || '';
-    ko.applyBindings(new CalendarSummaries(selectedValue));
+    var keywords = $('#keywords').val();
+    ko.applyBindings(new CalendarSummaries({'selectedValue': selectedValue, 'keywords': keywords}));
 });
\ No newline at end of file
diff --git a/war/myCalendar/index.jsp b/war/myCalendar/index.jsp
index 44774b5..cc1e79b 100644
--- a/war/myCalendar/index.jsp
+++ b/war/myCalendar/index.jsp
@@ -30,7 +30,7 @@
       <div class="tab-content">
         <c:if test="${storedCredential}">
           <div class="tab-pane<c:if test="${storedCredential}"> active</c:if>" id="mycalendar-settings">
-            <form class="well">
+            <form class="well" data-bind="submit: updateCalendar">
               <fieldset>
                 <legend>連携先</legend>
                 <div class="control-group">
@@ -52,12 +52,17 @@
                   <div class="control-group">
                   <label class="control-label">タイトルまたは説明文に含まれるキーワード</label>
                   <div class="controls">
+                  <%
+                  String[] str = {"aa","bb","cc"};
+                  pageContext.setAttribute("data",str);
+                  %>
                     <input id="keywords"
                            class="input-xxlarge"
                            type="text"
                            maxlength="50"
                            data-bind="value: keywords"
-                           placeholder="スペースで区切ると複数のキーワードを指定できます。" />
+                           placeholder="スペースで区切ると複数のキーワードを指定できます。"
+                           value="${f:h(fn:join(keywords, ' '))}" />
                   </div><!-- /.controls -->
                 </div><!-- /.control-group -->
               </fieldset>
[from now] 2012/05/29 22:10:15

diff --git a/war/js/nico2ical.js b/war/js/nico2ical.js
index 764aba7..6ed4585 100644
--- a/war/js/nico2ical.js
+++ b/war/js/nico2ical.js
@@ -50,7 +50,8 @@ $(function () {
             var s = this;
             $('#save-calendar').button('loading');
             $('#mycalendar-tab a').attr('data-disabled', 'true');
-            $('input[name=calendarSummaries], #keywords').attr('disabled', 'disabled');
+            var disabledInputs = $('#form-settings input:not(disabled)');
+            disabledInputs.attr('disabled', 'disabled');
             $.ajax(
                     '/myCalendar/save',
                     {
@@ -69,8 +70,8 @@ $(function () {
                 $('#save-calendar').button('error');
                 s.isSavaError(true);
             }).complete(function() {
-                $('input[name=calendarSummaries], #keywords').removeAttr('disabled');
                 $('#mycalendar-tab a').removeAttr('data-disabled');
+                disabledInputs.removeAttr('disabled');
             });
         }.bind(this);
         this.disConnectCalendar = function() {
diff --git a/war/myCalendar/index.jsp b/war/myCalendar/index.jsp
index cc1e79b..96844ee 100644
--- a/war/myCalendar/index.jsp
+++ b/war/myCalendar/index.jsp
@@ -30,7 +30,7 @@
       <div class="tab-content">
         <c:if test="${storedCredential}">
           <div class="tab-pane<c:if test="${storedCredential}"> active</c:if>" id="mycalendar-settings">
-            <form class="well" data-bind="submit: updateCalendar">
+            <form id="form-settings" class="well" data-bind="submit: updateCalendar">
               <fieldset>
                 <legend>連携先</legend>
                 <div class="control-group">
[from now] 2012/05/29 22:25:49

diff --git a/src/main/java/org/ryu22e/nico2cal/service/CalendarService.java b/src/main/java/org/ryu22e/nico2cal/service/CalendarService.java
index 6a45a48..ed27f69 100644
--- a/src/main/java/org/ryu22e/nico2cal/service/CalendarService.java
+++ b/src/main/java/org/ryu22e/nico2cal/service/CalendarService.java
@@ -318,11 +318,6 @@ public class CalendarService {
         if (user != null) {
             // Access tokenが格納されているAppEngineCredentialStoreを削除する。
             new AppEngineCredentialStore().delete(user.getUserId(), null);
-            // 連携対象のCalendar Idが格納されているMyCalendarを削除する。
-            MyCalendarMeta mc = MyCalendarMeta.get();
-            List<Key> keys =
-                    Datastore.query(mc).filter(mc.user.equal(user)).asKeyList();
-            Datastore.delete(keys);
         }
     }

diff --git a/src/test/java/org/ryu22e/nico2cal/controller/myCalendar/DisConnectControllerTest.java b/src/test/java/org/ryu22e/nico2cal/controller/myCalendar/DisConnectControllerTest.java
index afbff76..731c245 100644
--- a/src/test/java/org/ryu22e/nico2cal/controller/myCalendar/DisConnectControllerTest.java
+++ b/src/test/java/org/ryu22e/nico2cal/controller/myCalendar/DisConnectControllerTest.java
@@ -64,7 +64,7 @@ public final class DisConnectControllerTest extends ControllerTestCase {
         assertThat(json.get("status"), is("ok"));

         int count = Datastore.query(MyCalendar.class, testDataKey).count();
-        assertThat(count, is(0));
+        assertThat(count, is(1));
         assertThat(
             new AppEngineCredentialStore().load("42", credential),
             is(false));
diff --git a/src/test/java/org/ryu22e/nico2cal/service/CalendarServiceTest.java b/src/test/java/org/ryu22e/nico2cal/service/CalendarServiceTest.java
index a161332..c70cbec 100644
--- a/src/test/java/org/ryu22e/nico2cal/service/CalendarServiceTest.java
+++ b/src/test/java/org/ryu22e/nico2cal/service/CalendarServiceTest.java
@@ -467,7 +467,7 @@ public final class CalendarServiceTest extends AppEngineTestCase {
         service.disConnectMyCalendar();

         int count = Datastore.query(MyCalendar.class, testDataKey).count();
-        assertThat(count, is(0));
+        assertThat(count, is(1));
         assertThat(
             new AppEngineCredentialStore().load("42", credential),
             is(false));
diff --git a/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml b/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml
index e45afb0..7203a31 100644
--- a/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml
+++ b/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml
@@ -1,4 +1,4 @@
-<!-- Indices written at Tue, 29 May 2012 18:57:48 JST -->
+<!-- Indices written at Tue, 29 May 2012 22:10:34 JST -->

 <datastore-indexes/>

diff --git a/war/js/nico2ical.js b/war/js/nico2ical.js
index 6ed4585..c46ecca 100644
--- a/war/js/nico2ical.js
+++ b/war/js/nico2ical.js
@@ -92,7 +92,7 @@ $(function () {
                 ).success(function(data) {
                     $('#disconnect-calendar').hide();
                     $('#connect-calendar').removeClass('hidden');
-                    $('#nav-calendar-select').hide();
+                    $('#nav-mycalendar-settings').hide();
                 }).error(function(xhr, textStatus, errorThrown) {
                     $('#disconnect-calendar').addClass('btn-danger').button('error');
                     s.isDisconnectError(true);
[from now] 2012/05/30 00:21:41

diff --git a/src/main/java/org/ryu22e/nico2cal/controller/myCalendar/SaveController.java b/src/main/java/org/ryu22e/nico2cal/controller/myCalendar/SaveController.java
index 5cebc76..b1f8807 100644
--- a/src/main/java/org/ryu22e/nico2cal/controller/myCalendar/SaveController.java
+++ b/src/main/java/org/ryu22e/nico2cal/controller/myCalendar/SaveController.java
@@ -29,21 +29,28 @@ public final class SaveController extends Controller {
      */
     private CalendarService calendarService = new CalendarService();

+    /**
+     *
+     */
+    public static final int KEYWORDS_MAX_LENGTH = 25;
+
     /*
      * (non-Javadoc) {@inheritDoc}
      */
     @Override
     public Navigation run() throws Exception {
         Validators v = new Validators(request);
+        String[] keywords = paramValues("keywords[]");
         v.add("calendarId", v.required());
-        if (!v.validate()) {
+        if (!v.validate()
+                || (keywords != null && KEYWORDS_MAX_LENGTH < keywords.length)) {
             response.setStatus(HttpStatusConstants.FORBIDDEN);
             return null;
         }
         MyCalendar myCalendar = new MyCalendar();
         BeanUtil.copy(request, myCalendar);
-        myCalendar.setKeywords(Arrays.asList(request
-            .getParameterValues("keywords[]")));
+        myCalendar.setKeywords(Arrays.asList(paramValues("keywords[]")));
+        myCalendar.setDisabled(false);
         calendarService.putMyCalendar(myCalendar);

         Map<String, String> map = new HashMap<String, String>();
diff --git a/src/main/java/org/ryu22e/nico2cal/model/MyCalendar.java b/src/main/java/org/ryu22e/nico2cal/model/MyCalendar.java
index cc13611..13d57fc 100644
--- a/src/main/java/org/ryu22e/nico2cal/model/MyCalendar.java
+++ b/src/main/java/org/ryu22e/nico2cal/model/MyCalendar.java
@@ -49,6 +49,11 @@ public final class MyCalendar implements Serializable {
     private List<String> keywords;

     /**
+     *
+     */
+    private boolean disabled;
+
+    /**
      * Returns the key.
      *
      * @return the key
@@ -101,6 +106,20 @@ public final class MyCalendar implements Serializable {
     }

     /**
+     * @return the user
+     */
+    public User getUser() {
+        return user;
+    }
+
+    /**
+     * @param user the user to set
+     */
+    public void setUser(User user) {
+        this.user = user;
+    }
+
+    /**
      * @return the keywords
      */
     public List<String> getKeywords() {
@@ -115,17 +134,17 @@ public final class MyCalendar implements Serializable {
     }

     /**
-     * @return the user
+     * @return the disabled
      */
-    public User getUser() {
-        return user;
+    public boolean isDisabled() {
+        return disabled;
     }

     /**
-     * @param user the user to set
+     * @param disabled the disabled to set
      */
-    public void setUser(User user) {
-        this.user = user;
+    public void setDisabled(boolean disabled) {
+        this.disabled = disabled;
     }

     /*
diff --git a/src/main/java/org/ryu22e/nico2cal/service/CalendarService.java b/src/main/java/org/ryu22e/nico2cal/service/CalendarService.java
index ed27f69..d81fb38 100644
--- a/src/main/java/org/ryu22e/nico2cal/service/CalendarService.java
+++ b/src/main/java/org/ryu22e/nico2cal/service/CalendarService.java
@@ -318,6 +318,13 @@ public class CalendarService {
         if (user != null) {
             // Access tokenが格納されているAppEngineCredentialStoreを削除する。
             new AppEngineCredentialStore().delete(user.getUserId(), null);
+            MyCalendarMeta mc = MyCalendarMeta.get();
+            MyCalendar myCalendar =
+                    Datastore.query(mc).filter(mc.user.equal(user)).asSingle();
+            if (myCalendar != null) {
+                myCalendar.setDisabled(true);
+                Datastore.put(myCalendar);
+            }
         }
     }

diff --git a/src/main/java/org/ryu22e/nico2cal/servlet/ConnectGoogleApiCallback.java b/src/main/java/org/ryu22e/nico2cal/servlet/ConnectGoogleApiCallback.java
index 7a8992f..e07544b 100644
--- a/src/main/java/org/ryu22e/nico2cal/servlet/ConnectGoogleApiCallback.java
+++ b/src/main/java/org/ryu22e/nico2cal/servlet/ConnectGoogleApiCallback.java
@@ -7,6 +7,8 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;

+import org.ryu22e.nico2cal.model.MyCalendar;
+import org.ryu22e.nico2cal.service.CalendarService;
 import org.ryu22e.nico2cal.util.GoogleApiKeyUtil;

 import com.google.api.client.auth.oauth2.AuthorizationCodeFlow;
@@ -32,12 +34,22 @@ public final class ConnectGoogleApiCallback extends
      */
     private static final long serialVersionUID = 1L;

+    /**
+     *
+     */
+    private CalendarService calendarService = new CalendarService();
+
     /*
      * (non-Javadoc) {@inheritDoc}
      */
     @Override
     protected void onSuccess(HttpServletRequest req, HttpServletResponse resp,
             Credential credential) throws ServletException, IOException {
+        MyCalendar myCalendar = calendarService.getMyCalendar();
+        if (myCalendar != null) {
+            myCalendar.setDisabled(false);
+            calendarService.putMyCalendar(myCalendar);
+        }
         resp.sendRedirect("/myCalendar");
     }

diff --git a/src/test/java/org/ryu22e/nico2cal/controller/myCalendar/DisConnectControllerTest.java b/src/test/java/org/ryu22e/nico2cal/controller/myCalendar/DisConnectControllerTest.java
index 731c245..945e28f 100644
--- a/src/test/java/org/ryu22e/nico2cal/controller/myCalendar/DisConnectControllerTest.java
+++ b/src/test/java/org/ryu22e/nico2cal/controller/myCalendar/DisConnectControllerTest.java
@@ -63,8 +63,9 @@ public final class DisConnectControllerTest extends ControllerTestCase {
         assertThat(json, is(notNullValue()));
         assertThat(json.get("status"), is("ok"));

-        int count = Datastore.query(MyCalendar.class, testDataKey).count();
-        assertThat(count, is(1));
+        MyCalendar result = Datastore.getOrNull(MyCalendar.class, testDataKey);
+        assertThat(result, is(notNullValue()));
+        assertThat(result.isDisabled(), is(true));
         assertThat(
             new AppEngineCredentialStore().load("42", credential),
             is(false));
diff --git a/src/test/java/org/ryu22e/nico2cal/service/CalendarServiceTest.java b/src/test/java/org/ryu22e/nico2cal/service/CalendarServiceTest.java
index c70cbec..3ac95a4 100644
--- a/src/test/java/org/ryu22e/nico2cal/service/CalendarServiceTest.java
+++ b/src/test/java/org/ryu22e/nico2cal/service/CalendarServiceTest.java
@@ -466,8 +466,9 @@ public final class CalendarServiceTest extends AppEngineTestCase {

         service.disConnectMyCalendar();

-        int count = Datastore.query(MyCalendar.class, testDataKey).count();
-        assertThat(count, is(1));
+        MyCalendar result = Datastore.getOrNull(MyCalendar.class, testDataKey);
+        assertThat(result, is(notNullValue()));
+        assertThat(result.isDisabled(), is(true));
         assertThat(
             new AppEngineCredentialStore().load("42", credential),
             is(false));
diff --git a/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml b/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml
index 7203a31..26b278f 100644
--- a/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml
+++ b/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml
@@ -1,4 +1,4 @@
-<!-- Indices written at Tue, 29 May 2012 22:10:34 JST -->
+<!-- Indices written at Tue, 29 May 2012 23:23:52 JST -->

 <datastore-indexes/>

diff --git a/war/js/nico2ical.js b/war/js/nico2ical.js
index c46ecca..da785c5 100644
--- a/war/js/nico2ical.js
+++ b/war/js/nico2ical.js
@@ -48,6 +48,8 @@ $(function () {
         }.bind(this);
         this.updateCalendar = function() {
             var s = this;
+            s.isSaveSuccess(false);
+            s.isSavaError(false);
             $('#save-calendar').button('loading');
             $('#mycalendar-tab a').attr('data-disabled', 'true');
             var disabledInputs = $('#form-settings input:not(disabled)');