@@ -48,6 +48,13 @@ define([
48
48
var page = this . $el . find ( '#importarea' ) . val ( ) ;
49
49
page = JSON . parse ( page ) ;
50
50
console . log ( page ) ;
51
+ var success = {
52
+ success : {
53
+ message : '<strong>Nice.</strong> The notes was imported successfully.'
54
+ }
55
+ } ;
56
+ var notesexist = { message : '<strong>Error:</strong> ' + "Notes for this page already exist" } ;
57
+
51
58
if ( _ . isArray ( page ) ) {
52
59
_ ( page ) . each ( function ( p ) {
53
60
if ( ! p . url && ! p . data ) {
@@ -56,21 +63,22 @@ define([
56
63
db . get ( 'notes' , p . url )
57
64
. done ( function ( model ) {
58
65
if ( model ) {
59
- throw "Notes for this page already exist" ;
66
+ throw notesexist ;
60
67
} else {
61
68
db . put ( { name : 'notes' , keyPath : 'url' } , p )
62
69
. done ( function ( ) {
63
70
console . log ( 'saved' ) ;
64
71
p . id = Util . hashCode ( p . url ) ;
65
72
_self . collection . add ( _self . collection . parse ( p ) ) ;
73
+ $ ( document ) . trigger ( 'notification' , [ success ] ) ;
66
74
} )
67
75
. fail ( function ( e ) {
68
- alert ( e ) ;
76
+ $ ( document ) . trigger ( 'notification' , [ { error : e } ] ) ;
69
77
} ) ;
70
78
}
71
79
} )
72
80
. fail ( function ( e ) {
73
- alert ( e ) ;
81
+ $ ( document ) . trigger ( 'notification' , [ { error : e } ] ) ;
74
82
} ) ;
75
83
}
76
84
} ) ;
@@ -81,29 +89,31 @@ define([
81
89
db . get ( 'notes' , page . url )
82
90
. done ( function ( model ) {
83
91
if ( model ) {
84
- throw "Notes for this page already exist" ;
92
+ throw notesexist ;
85
93
} else {
86
94
db . put ( { name : 'notes' , keyPath : 'url' } , page )
87
95
. done ( function ( ) {
88
96
console . log ( 'saved' ) ;
89
97
page . id = Util . hashCode ( page . url ) ;
90
98
_self . collection . add ( _self . collection . parse ( page ) ) ;
99
+ $ ( document ) . trigger ( 'notification' , [ success ] ) ;
91
100
} )
92
101
. fail ( function ( e ) {
93
- alert ( e ) ;
102
+ $ ( document ) . trigger ( 'notification' , [ { error : e } ] ) ;
94
103
} ) ;
95
104
}
96
105
} )
97
106
. fail ( function ( e ) {
98
- alert ( e ) ;
107
+ $ ( document ) . trigger ( 'notification' , [ { error : e } ] ) ;
99
108
} ) ;
100
109
}
101
110
}
102
111
103
112
this . $el . find ( '#importarea' ) . val ( '' ) ;
104
113
105
114
} catch ( e ) {
106
- alert ( e ) ;
115
+ // alert(e);
116
+ $ ( document ) . trigger ( 'notification' , [ { error : e } ] ) ;
107
117
}
108
118
109
119
}
0 commit comments